diff options
-rw-r--r-- | program/include/rcube_ldap.php | 17 | ||||
-rw-r--r-- | program/steps/addressbook/import.inc | 8 |
2 files changed, 19 insertions, 6 deletions
diff --git a/program/include/rcube_ldap.php b/program/include/rcube_ldap.php index 130eada63..08b7cd99c 100644 --- a/program/include/rcube_ldap.php +++ b/program/include/rcube_ldap.php @@ -993,10 +993,13 @@ class rcube_ldap extends rcube_addressbook if ($missing) { // try to complete record automatically if ($autofix) { - $reverse_map = array_flip($this->fieldmap); - $name_parts = preg_split('/[\s,.]+/', $save_data['name']); $sn_field = $this->fieldmap['surname']; $fn_field = $this->fieldmap['firstname']; + $mail_field = $this->fieldmap['email']; + + // try to extract surname and firstname from displayname + $reverse_map = array_flip($this->fieldmap); + $name_parts = preg_split('/[\s,.]+/', $save_data['name']); if ($sn_field && $missing[$sn_field]) { $save_data['surname'] = array_pop($name_parts); @@ -1007,6 +1010,16 @@ class rcube_ldap extends rcube_addressbook $save_data['firstname'] = array_shift($name_parts); unset($missing[$fn_field]); } + + // try to fix missing e-mail, very often on import + // from vCard we have email:other only defined + if ($mail_field && $missing[$mail_field]) { + $emails = $this->get_col_values('email', $save_data, true); + if (!empty($emails) && ($email = array_shift($emails))) { + $save_data['email'] = $email; + unset($missing[$mail_field]); + } + } } // TODO: generate message saying which fields are missing diff --git a/program/steps/addressbook/import.inc b/program/steps/addressbook/import.inc index 7b52bdcee..018c980eb 100644 --- a/program/steps/addressbook/import.inc +++ b/program/steps/addressbook/import.inc @@ -164,10 +164,11 @@ if ($_FILES['_file']['tmp_name'] && is_uploaded_file($_FILES['_file']['tmp_name' $CONTACTS->delete_all(); foreach ($vcards as $vcard) { - $email = $vcard->email[0]; + $email = $vcard->email[0]; + $a_record = $vcard->get_assoc(); - // skip entries without an e-mail address - if (empty($email)) { + // skip entries without an e-mail address or invalid + if (empty($email) || !$CONTACTS->validate($a_record, true)) { $IMPORT_STATS->nomail++; continue; } @@ -188,7 +189,6 @@ if ($_FILES['_file']['tmp_name'] && is_uploaded_file($_FILES['_file']['tmp_name' } } - $a_record = $vcard->get_assoc(); $a_record['vcard'] = $vcard->export(); $plugin = $RCMAIL->plugins->exec_hook('contact_create', array('record' => $a_record, 'source' => null)); |