fixed multi email import

This commit is contained in:
Christoph Haas 2016-06-13 20:22:24 +02:00
parent eb0cb9a5ad
commit 21af50aa6c
1 changed files with 46 additions and 26 deletions

View File

@ -753,35 +753,55 @@ class ContactModule extends Module {
} }
if (isset($vCard->email) && count($vCard->email) > 0) { if (isset($vCard->email) && count($vCard->email) > 0) {
$emailcount = 0; $emailcount = 0;
$properties["address_book_long"] = 0;
foreach ($vCard->email as $type => $email) { foreach ($vCard->email as $type => $email) {
$email = $email[0]; // we only can store one mail address foreach ($email as $mail) {
$fileas = $email; $fileas = $mail;
if(isset($properties["fileas"]) && !empty($properties["fileas"])) { if (isset($properties["fileas"]) && !empty($properties["fileas"])) {
$fileas = $properties["fileas"]; // set to real name $fileas = $properties["fileas"]; // set to real name
} }
// we only have storage for 3 mail addresses! // we only have storage for 3 mail addresses!
switch($emailcount) { /**
case 0: * type of email address address_book_mv address_book_long
$properties["email_address_1"] = $email; * email1 0 1 (0x00000001)
$properties["email_address_display_name_1"] = $fileas . " (" . $email . ")"; * email2 1 2 (0x00000002)
$properties["email_address_display_name_email_1"] = $email; * email3 2 4 (0x00000004)
$properties["address_book_mv"] = [0]; // this is needed for adding the contact to the email address book, 0 = email 1 * fax2(business fax) 3 8 (0x00000008)
$properties["address_book_long"] = 1; // this specifies the number of elements in address_book_mv * fax3(home fax) 4 16 (0x00000010)
break; * fax1(primary fax) 5 32 (0x00000020)
case 1: *
$properties["email_address_2"] = $email; * address_book_mv is a multivalued property so all the values are passed in array
$properties["email_address_display_name_2"] = $fileas . " (" . $email . ")"; * address_book_long stores sum of the flags
$properties["email_address_display_name_email_2"] = $email; * these both properties should be in sync always
break; */
case 2: switch ($emailcount) {
$properties["email_address_3"] = $email; case 0:
$properties["email_address_display_name_3"] = $fileas . " (" . $email . ")"; $properties["email_address_1"] = $mail;
$properties["email_address_display_name_email_3"] = $email; $properties["email_address_display_name_1"] = $fileas . " (" . $mail . ")";
break; $properties["email_address_display_name_email_1"] = $mail;
default: break; $properties["address_book_mv"][] = 0; // this is needed for adding the contact to the email address book, 0 = email 1
$properties["address_book_long"] += 1; // this specifies the number of elements in address_book_mv
break;
case 1:
$properties["email_address_2"] = $mail;
$properties["email_address_display_name_2"] = $fileas . " (" . $mail . ")";
$properties["email_address_display_name_email_2"] = $mail;
$properties["address_book_mv"][] = 1; // this is needed for adding the contact to the email address book, 1 = email 2
$properties["address_book_long"] += 2; // this specifies the number of elements in address_book_mv
break;
case 2:
$properties["email_address_3"] = $mail;
$properties["email_address_display_name_3"] = $fileas . " (" . $mail . ")";
$properties["email_address_display_name_email_3"] = $mail;
$properties["address_book_mv"][] = 2; // this is needed for adding the contact to the email address book, 2 = email 3
$properties["address_book_long"] += 4; // this specifies the number of elements in address_book_mv
break;
default:
break;
}
$emailcount++;
} }
$emailcount++;
} }
} }
if (isset($vCard->organization)) { if (isset($vCard->organization)) {