Ticket #1487858: squirrelmail_multiple_contacts.diff

File squirrelmail_multiple_contacts.diff, 1.8 KB (added by jcrawfordor, 2 years ago)
Line 
1Index: squirrelmail_usercopy.php
2===================================================================
3--- squirrelmail_usercopy.php   (revision 4614)
4+++ squirrelmail_usercopy.php   (working copy)
5@@ -67,17 +67,35 @@
6                                }
7                        }
8 
9-                       // copy address book
10+                       // Copy in contacts
11                        $contacts = $rcmail->get_address_book(null, true);
12                        if ($contacts && count($this->abook)) {
13                                foreach ($this->abook as $rec) {
14-                                   // #1487096 handle multi-address and/or too long items
15-                                   $rec['email'] = array_shift(explode(';', $rec['email']));
16-                    if (check_email(rcube_idn_to_ascii($rec['email']))) {
17-                        $rec['email'] = rcube_idn_to_utf8($rec['email']);
18-                                       $contacts->insert($rec, true);
19-                               }
20-                           }
21+                                       // Check if this contact has multiple email addresses or only one
22+                                       if((strpos($rec['email'], ";") === false) && (strpos($rec['email'], ",") === false)) {
23+                                               // single contact
24+
25+                                               if(check_email(idn_to_ascii($rec['email']))) {
26+                                                       // email is valid and under 128 chars
27+                                                       $rec['email'] = idn_to_utf8($rec['email']);
28+                                                       $contacts->insert($rec, true);
29+                                               }
30+                                       } else {
31+                                               // multiple contact
32+                                               
33+                                               // create group for addresses
34+                                               $newGroup = $contacts->create_group($rec['name']);
35+                                               $groupId = $newGroup['id'];
36+                                               
37+                                               // create contacts for each email and add them to group
38+                                               $groupInsertEmails = preg_split("/[;,]/", $rec['email']);
39+                                               foreach($groupInsertEmails as $thisEmail) {
40+                                                       $thisContact['email'] = idn_to_utf8($thisEmail);
41+                                                       $groupInsertUser = $contacts->insert($thisContact, true);
42+                                                       $contacts->add_to_group($groupId, array($groupInsertUser));
43+                                               }
44+                                       }
45+                               }
46                        }
47 
48                        // mark identity as complete for following hooks