Skip to content

Commit

Permalink
Merge pull request #9605 from johndoh/vcard_import
Browse files Browse the repository at this point in the history
  • Loading branch information
pabzm authored Dec 2, 2024
2 parents 3577d52 + 8468d29 commit 0c57564
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- Convert images in HTML content pasted into HTML editor to `data:` URIs (and later to attachments) (#6938)
- Add possibility to change ATTR_EMULATE_PREPARES via config file (#9213)
- Use draft settings (like DSN) on "Edit as new" (#9349)
- Add more detailed feedback on vCard import errors (#9591)
- Use new HTML5 parser available on PHP >= 8.4
- Installer: Show NOT OK if none of the database extensions is installed (#9594, #9604)
- Mailvelope: Add a button to enable the extension for webmail domain (#9498)
Expand Down
28 changes: 22 additions & 6 deletions program/actions/contacts/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ public function run($args = [])
self::$stats = new stdClass();
self::$stats->names = [];
self::$stats->skipped_names = [];
self::$stats->invalid_names = [];
self::$stats->error_names = [];
self::$stats->count = count($vcards);
self::$stats->inserted = 0;
self::$stats->skipped = 0;
Expand Down Expand Up @@ -187,6 +189,7 @@ public function run($args = [])
// skip invalid (incomplete) entries
if (!$CONTACTS->validate($a_record, true)) {
self::$stats->invalid++;
self::$stats->invalid_names[] = rcube_addressbook::compose_display_name($a_record, true);
continue;
}

Expand Down Expand Up @@ -251,6 +254,7 @@ public function run($args = [])
self::$stats->names[] = $a_record['name'] ?: $email;
} else {
self::$stats->errors++;
self::$stats->error_names[] = $a_record['name'] ?: $email;
}
}

Expand Down Expand Up @@ -430,13 +434,10 @@ public static function import_map($attrib)
public static function import_confirm($attrib)
{
$rcmail = rcmail::get_instance();
$vars = get_object_vars(self::$stats);
$vars['names'] = $vars['skipped_names'] = '';

$content = html::p(null, $rcmail->gettext([
'name' => 'importconfirm',
'nr' => self::$stats->inserted,
'vars' => $vars,
'vars' => ['inserted' => self::$stats->inserted],
]) . (self::$stats->names ? ':' : '.')
);

Expand All @@ -447,12 +448,27 @@ public static function import_confirm($attrib)
if (self::$stats->skipped) {
$content .= html::p(null, $rcmail->gettext([
'name' => 'importconfirmskipped',
'nr' => self::$stats->skipped,
'vars' => $vars,
'vars' => ['skipped' => self::$stats->skipped],
]) . ':')
. html::p('em', implode(', ', array_map(['rcube', 'Q'], self::$stats->skipped_names)));
}

if (self::$stats->invalid) {
$content .= html::p(null, $rcmail->gettext([
'name' => 'importconfirminvalid',
'vars' => ['invalid' => self::$stats->invalid],
]) . ':')
. html::p('em', implode(', ', array_map(['rcube', 'Q'], self::$stats->invalid_names)));
}

if (self::$stats->errors) {
$content .= html::p(null, $rcmail->gettext([
'name' => 'importconfirmerrors',
'vars' => ['errors' => self::$stats->errors],
]) . ':')
. html::p('em', implode(', ', array_map(['rcube', 'Q'], self::$stats->error_names)));
}

return html::div($attrib, $content);
}

Expand Down
4 changes: 3 additions & 1 deletion program/localization/en_US/messages.inc
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ $messages['nogroupassignmentschanged'] = 'No group assignments changed.';
$messages['importwait'] = 'Importing, please wait...';
$messages['importformaterror'] = 'Import failed! The uploaded file is not a valid import data file.';
$messages['importconfirm'] = '<b>Successfully imported $inserted contacts</b>';
$messages['importconfirmskipped'] = '<b>Skipped $skipped existing entries</b>';
$messages['importconfirmskipped'] = '<b>Skipped $skipped existing contacts</b>';
$messages['importconfirminvalid'] = '<b>Skipped $invalid invalid contacts</b>';
$messages['importconfirmerrors'] = '<b>Failed to import $errors valid contacts</b>';
$messages['importmessagesuccess'] = 'Successfully imported $nr messages';
$messages['importmessageerror'] = 'Import failed! The uploaded file is not a valid message or mailbox file';
$messages['opnotpermitted'] = 'Operation not permitted!';
Expand Down

0 comments on commit 0c57564

Please sign in to comment.