[Svn] r6067 - in trunk/roundcubemail/program: include steps/addressbook

trac at roundcube.net trac at roundcube.net
Thu Apr 12 13:52:09 CEST 2012


Author: alec
Date: 2012-04-12 06:52:09 -0500 (Thu, 12 Apr 2012)
New Revision: 6067

Modified:
   trunk/roundcubemail/program/include/rcube_ldap.php
   trunk/roundcubemail/program/steps/addressbook/import.inc
Log:
- Fix importing to LDAP addressbook when mail attribute is required by
  validating input data with autofix


Modified: trunk/roundcubemail/program/include/rcube_ldap.php
===================================================================
--- trunk/roundcubemail/program/include/rcube_ldap.php	2012-04-12 10:07:10 UTC (rev 6066)
+++ trunk/roundcubemail/program/include/rcube_ldap.php	2012-04-12 11:52:09 UTC (rev 6067)
@@ -993,11 +993,14 @@
         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);
                     unset($missing[$sn_field]);
@@ -1007,6 +1010,16 @@
                     $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

Modified: trunk/roundcubemail/program/steps/addressbook/import.inc
===================================================================
--- trunk/roundcubemail/program/steps/addressbook/import.inc	2012-04-12 10:07:10 UTC (rev 6066)
+++ trunk/roundcubemail/program/steps/addressbook/import.inc	2012-04-12 11:52:09 UTC (rev 6067)
@@ -164,10 +164,11 @@
       $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 @@
         }
       }
 
-      $a_record = $vcard->get_assoc();
       $a_record['vcard'] = $vcard->export();
 
       $plugin = $RCMAIL->plugins->exec_hook('contact_create', array('record' => $a_record, 'source' => null));



More information about the svn mailing list