3 # LiCoM - Lightweight contact manager
4 # Copyright (c) 2005-2006 Florian octo Forster <octo at verplant.org>
6 # This program is free software; you can redistribute it and/or modify it under
7 # the terms of the GNU General Public License as published by the Free Software
8 # Foundation; only version 2 of the License is applicable.
10 # This program is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 # You should have received a copy of the GNU General Public License along with
16 # this program; if not, write to the Free Software # Foundation, Inc.,
17 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 use CGI::Carp (qw(fatalsToBrowser));
26 use HTML::Entities (qw(encode_entities));
28 use LiCoM::Config (qw(get_config set_config read_config));
29 use LiCoM::Connection ();
35 our @MultiFields = (qw(address homephone cellphone officephone fax mail uri));
40 homephone => 'Home Phone',
41 cellphone => 'Cell Phone',
42 officephone => 'Office Phone',
45 uri => 'URI (Homepage)',
49 our $MySelf = $ENV{'SCRIPT_NAME'};
51 our $Action = param ('action');
52 $Action ||= 'default';
56 browse => [\&html_start, \&action_browse, \&html_end],
57 default => [\&html_start, \&action_browse, \&html_end],
58 detail => [\&html_start, \&action_detail, \&html_end],
59 edit => [\&html_start, \&action_edit, \&html_end],
60 list => [\&html_start, \&action_list, \&html_end],
61 save => [\&html_start, \&action_save, \&html_end],
62 search => [\&html_start, \&action_search, \&html_end],
63 verify => [\&html_start, \&action_verify, \&html_end],
64 delete => [\&html_start, \&action_ask_del, \&html_end],
65 expunge => [\&html_start, \&action_do_del, \&html_end],
66 vcard => \&action_vcard,
67 edit_group => [\&html_start, \&action_edit_group, \&html_end],
68 save_group => [\&html_start, \&action_save_group, \&html_end]
73 # make sure AuthLDAPRemoteUserIsDN is enabled.
74 die unless ($ENV{'REMOTE_USER'});
75 set_config ('base_dn', $ENV{'REMOTE_USER'});
77 die unless (defined (get_config ('uri'))
78 and defined (get_config ('base_dn'))
79 and defined (get_config ('bind_dn'))
80 and defined (get_config ('password')));
82 LiCoM::Connection->connect
84 uri => get_config ('uri'),
85 bind_dn => get_config ('bind_dn'),
86 password => get_config ('password')
89 our ($UserCN, $UserID) = LiCoM::Person->get_user ($ENV{'REMOTE_USER'});
91 if (!$UserID and $Action ne 'save')
101 if (!defined ($Actions{$Action}))
103 die ("No such action: $Action");
106 if (ref ($Actions{$Action}) eq 'CODE')
108 $Actions{$Action}->();
110 elsif (ref ($Actions{$Action}) eq 'ARRAY')
112 for (@{$Actions{$Action}})
118 LiCoM::Connection->disconnect ();
126 my $group = param ('group');
127 $group = shift if (@_);
132 my @groups = LiCoM::Group->all ();
134 print qq(\t\t<h2>Contact groups</h2>\n\t\t<ul class="groups">\n);
138 my @members = $group->get_members ();
139 my $members = scalar (@members);
140 my $group_name = $group->name ();
141 my $group_uri = uri_escape ($group_name);
142 my $desc = $group->description ();
144 print qq#\t\t\t<li><a href="$MySelf?action=browse&group=$group_uri">#,
145 encode_entities ($group_name),
146 qq#</a> ($members Member#, ($members == 1 ? ')' : 's)');
147 print qq(<br />\n\t\t\t\t<span class="description">),
148 encode_entities ($desc) . '</span>' if ($desc);
153 print qq(\t\t\t<li class="empty">There are no groups yet.</li>\n);
158 [<a href="$MySelf?action=list">List all</a>]
164 my $group_obj = LiCoM::Group->load ($group);
165 my $group_uri = uri_escape ($group_obj->name ());
166 my $group_html = encode_entities ($group_obj->name ());
167 my @member_names = $group_obj->get_members ();
168 my $desc = $group_obj->description ();
169 my $desc_html = encode_entities ($desc || '');
171 print qq(\t\t<h2>Contact group "$group_html"</h2>\n);
172 print qq(\t\t<div>$desc_html</div>\n) if ($desc);
173 print qq(\t\t<ul class="results">\n);
174 for (sort (@member_names))
177 my $cn_uri = uri_escape ($cn);
178 my $cn_html = encode_entities ($cn);
180 print qq(\t\t\t<li><a href="$MySelf?action=detail&cn=$cn_uri">$cn_html</a></li>\n);
186 [<a href="$MySelf?action=list&group=$group_uri">List</a>]
187 [<a href="$MySelf?action=browse">Back</a>]
188 [<a href="$MySelf?action=edit_group&group=$group_uri">Edit</a>]
196 my $group_name = param ('group');
197 $group_name = shift if (@_);
200 my $group_name_html = encode_entities ($group_name || '');
202 my $title = $group_name
203 ? "List of group "$group_name_html""
204 : 'List of all addresses';
205 my @fields = (qw(address homephone cellphone officephone fax mail));
210 my $group_obj = LiCoM::Group->load ($group_name);
215 Unable to load group "$group_name_html".
220 for ($group_obj->get_members ())
223 my $person_obj = LiCoM::Person->load ($cn);
227 print STDERR "Unable to load cn = $cn;\n";
230 push (@all, $person_obj);
235 @all = LiCoM::Person->search ([[group => $group_name]]);
247 print "\t\t\t\t<th>" . (defined ($FieldNames{$_}) ? $FieldNames{$_} : $_) . "</th>\n";
249 print "\t\t\t</tr>\n";
251 for (sort { $a->name () cmp $b->name () } (@all))
254 my $cn = $person->name ();
255 my $sn = $person->lastname ();
256 my $gn = $person->firstname ();
258 my $cn_uri = uri_escape ($cn);
259 my $cn_html = encode_entities ("$sn, $gn");
261 print "\t\t\t<tr>\n",
262 qq(\t\t\t\t<td><a href="$MySelf?action=detail&cn=$cn_uri">$cn_html</a></td>\n);
267 my @values = $person->get ($field);
268 print "\t\t\t\t<td>" . join ('<br />', map { encode_entities ($_) } (@values)) . "</td>\n";
271 print "\t\t\t</tr>\n";
273 print "\t\t</table>\n\n";
277 my $group_esc = uri_escape ($group_name);
278 print qq(\t\t<div class="menu">[<a href="$MySelf?action=browse&group=$group_esc">Back</a>]</div>\n);
282 print qq(\t\t<div class="menu">[<a href="$MySelf?action=browse">Back</a>]</div>\n);
288 my $cn = param ('cn');
292 my $cn_html = encode_entities ($cn);
293 my $cn_uri = uri_escape ($cn);
295 my $person = LiCoM::Person->load ($cn);
298 print qq(\t<div>Entry "$cn_html" could not be loaded from DB.</div>\n);
302 print qq(\t\t<h2>Details for $cn_html</h2>\n);
305 <table class="detail">
314 my $values = $person->get ($field);
315 my $num = scalar (@$values);
316 my $field_name = defined ($FieldNames{$field}) ? $FieldNames{$field} : $field;
320 $field_name = encode_entities ($field_name);
322 print "\t\t\t<tr>\n";
325 print qq(\t\t\t\t<th rowspan="$num">$field_name</th>\n);
329 print qq(\t\t\t\t<th>$field_name</th>\n);
332 for (my $i = 0; $i < $num; $i++)
334 my $val = $values->[$i];
335 my $val_uri = uri_escape ($val);
336 my $val_html = encode_entities ($val);
338 if ($field eq 'group')
340 $val = qq(<a href="$MySelf?action=browse&group=$val_uri">$val_html</a>);
342 elsif ($field eq 'uri')
344 if ($val =~ m#^([a-z]+)://(.+)$#)
346 $val_uri = $1 . '://' . uri_escape ($2);
350 $val_uri = 'http://' . uri_escape ($val);
352 $val = qq(<a href="$val_uri" class="extern">$val_html</a>);
354 elsif ($field eq 'mail')
356 $val = qq(<a href="mailto:$val_uri" class="mail">$val_html</a>);
363 print "\t\t\t<tr>\n" if ($i);
364 print "\t\t\t\t<td>$val</td>\n",
369 my @groups = LiCoM::Group->load_by_member ($cn);
372 my $num = scalar (@groups);
373 print "\t\t\t<tr>\n",
374 "\t\t\t\t<th", ($num == 1 ? '' : qq( rowspan="$num")), ">Group", ($num == 1 ? '' : 's'), "</th>\n";
375 for (my $i = 0; $i < $num; $i++)
377 my $group = $groups[$i];
378 my $group_name = $group->name ();
379 my $group_uri = uri_escape ($group_name);
380 my $group_html = encode_entities ($group_name);
382 print "\t\t\t<tr>\n" if ($i != 0);
383 print qq(\t\t\t\t<td><a href="$MySelf?action=browse&group=$group_uri">$group_html</a></td>\n),
392 [<a href="$MySelf?action=verify&cn=$cn_uri">Verify</a>]
393 [<a href="$MySelf?action=vcard&cn=$cn_uri">vCard</a>]
394 [<a href="$MySelf?action=edit&cn=$cn_uri">Edit</a>]
395 [<a href="$MySelf?action=delete&cn=$cn_uri">Delete</a>]
403 my $search = param ('search');
406 $search =~ s/[^\s\w]//g;
410 print qq(\t<div class="error">Sorry, the empty search is not allowed.</div>\n);
415 my @patterns = split (m/\s+/, $search);
421 push (@filter, [[lastname => $pattern], [firstname => $pattern]]);
424 my @matches = LiCoM::Person->search (@filter);
428 print qq(\t<div>No entries matched your search.</div>\n);
432 if (scalar (@matches) == 1)
434 my $person = shift (@matches);
435 my $cn = $person->name ();
440 print qq(\t<ul class="result">\n);
441 for (sort { $a->name () cmp $b->name () } (@matches))
444 my $cn = $person->name ();
445 my $cn_uri = uri_escape ($cn);
446 my $cn_html = encode_entities ($cn);
448 print qq(\t\t<li><a href="$MySelf?action=detail&cn=$cn_uri">$cn_html</a></li>\n);
457 my $cn = param ('cn');
459 $cn = $opts{'cn'} if (defined ($opts{'cn'}));
462 my $cn_html = encode_entities ($cn);
475 $contacts->{$_} = [] for (@MultiFields);
479 $person = LiCoM::Person->load ($cn);
483 print qq(\t<div class="error">Unable to load CN "$cn". Sorry.</div>\n);
487 $lastname = $person->lastname ();
488 $firstname = $person->firstname ();
492 $contacts->{$_} = $person->get ($_);
496 $lastname = param ('lastname') if (param ('lastname') and $UserID);
497 $firstname = param ('firstname') if (param ('firstname') and $UserID);
499 get_contacts ($contacts);
501 $lastname = $opts{'lastname'} if (defined ($opts{'lastname'}));
502 $firstname = $opts{'firstname'} if (defined ($opts{'firstname'}));
506 @{$contacts->{$field}} = @{$opts{$field}} if (defined ($opts{$field}));
511 print "\t\t<h2>Edit contact $cn_html</h2>\n";
515 print "\t\t<h2>Create new contact</h2>\n";
519 <form action="$MySelf" method="post">
520 <input type="hidden" name="action" value="save" />
521 <input type="hidden" name="cn" value="$cn_html" />
528 print qq(\t\t\t\t<td><input type="text" name="lastname" value="$lastname" /></td>\n);
532 print qq(\t\t\t\t<td>$lastname</td>\n);
541 print qq(\t\t\t\t<td><input type="text" name="firstname" value="$firstname" /></td>\n);
545 print qq(\t\t\t\t<td>$firstname</td>\n);
548 print "\t\t\t</tr>\n";
553 my $print = defined ($FieldNames{$field}) ? $FieldNames{$field} : $field;
554 my @values = @{$contacts->{$field}};
556 next if ($field eq 'group');
560 $field = encode_entities ($field);
561 $print = encode_entities ($print);
565 my $value = encode_entities ($_);
570 <td><input type="text" name="$field" value="$value" /></td>
578 my @all_groups = LiCoM::Group->all ();
582 print "\t\t\t<tr>\n",
583 "\t\t\t\t<th>Group(s)</th>\n",
584 qq(\t\t\t\t<td><select name="group" multiple="multiple" size="5">\n);
589 my $group_name = encode_entities ($group->name ());
592 if (grep { $cn eq $_ } ($group->get_members ()))
594 $selected = ' selected="selected"';
597 print qq(\t\t\t\t\t<option value="$group_name"$selected>$group_name</option>\n);
599 print "\t\t\t\t</select></td>\n",
603 print "\t\t\t<tr>\n",
604 "\t\t\t\t<th>New Group</th>\n",
605 qq(\t\t\t\t<td><input type="text" name="newgroup" value="" /></td>\n),
611 <th colspan="2" class="menu">
616 <input type="submit" name="button" value="Cancel" />
617 <input type="submit" name="button" value="Apply" />
621 <input type="submit" name="button" value="Save" />
631 my $cn = $UserID ? param ('cn') : $UserCN;
633 if (verify_fields ())
635 action_edit (cn => $cn);
645 die unless ($UserID);
647 my $button = lc (param ('button'));
650 if ($button eq 'cancel')
656 if (!param ('lastname') or !param ('firstname'))
658 print qq(\t<div class="error">You have to give both, first and lastname, to identify this record.</div>\n);
659 action_edit (cn => '');
663 my $lastname = param ('lastname');
664 my $firstname = param ('firstname');
666 my $contacts = get_contacts ();
668 my $person = LiCoM::Person->create (lastname => $lastname, firstname => $firstname, %$contacts);
672 print qq(\t<div class="error">Unable to save entry. Sorry.</div>\n);
676 $cn = $person->name ();
678 for (param ('group'))
681 my $group = LiCoM::Group->load ($group_name);
685 $group->add_members ($cn);
689 my $group_html = encode_entities ($group_name);
690 print qq(\t<div class="error">Group "$group_html" does not exist or could not be loaded.</div>\n);
694 if (param ('newgroup'))
696 # FIXME add error handling
697 my $group_name = param ('newgroup');
698 LiCoM::Group->create ($group_name, '', $cn);
701 if ($button eq 'apply')
703 action_edit (cn => $cn);
713 my $cn = $UserID ? param ('cn') : $UserCN;
714 my $person = LiCoM::Person->load ($cn);
716 die unless ($person);
718 my $button = lc (param ('button'));
721 if ($UserID and $button eq 'cancel')
729 my $lastname = param ('lastname');
730 my $firstname = param ('firstname');
732 $person->lastname ($lastname) if ($lastname and $lastname ne $person->lastname ());
733 $person->firstname ($firstname) if ($firstname and $firstname ne $person->firstname ());
735 $cn = $person->name ();
737 # Each group is one entry of type (objectClass=groupOfNames)
738 # with one or more `member' attributes. These attributes are
739 # the `dn' (distinguished name) of the member entries.
742 my $contacts = get_contacts ();
748 next if (!$UserID and $field eq 'group');
750 if (defined ($contacts->{$field}))
752 my $values = $contacts->{$field};
753 $person->set ($field, $values);
757 $person->set ($field, []);
761 # only `authorized' users may see and change groups
764 my %changed_groups = map { $_ => 1 } (param ('group'));
765 my @current_groups = LiCoM::Group->load_by_member ($cn);
767 for (@current_groups)
770 my $group_name = $group_obj->name ();
772 if (!defined ($changed_groups{$group_name}))
774 $group_obj->del_members ($cn);
778 delete ($changed_groups{$group_name});
781 for (keys %changed_groups)
784 my $group_obj = LiCoM::Group->load ($group_name) or die;
786 $group_obj->add_members ($cn);
789 if (param ('newgroup'))
791 # FIXME add error handling
792 my $group_name = param ('newgroup');
793 LiCoM::Group->create ($group_name, '', $cn);
800 <h3>Your changes have been saved.</h3>
801 <p>Thank you very much for taking the time to keep this record up to date.</p>
806 if ($button eq 'apply' or !$UserID)
808 action_edit (cn => $cn);
818 my $cn = param ('cn');
822 my $person = LiCoM::Person->load ($cn);
823 die unless ($person);
827 homephone => 'TEL;TYPE=home,voice',
828 cellphone => 'TEL;TYPE=cell',
829 officephone => 'TEL;TYPE=work,voice',
830 fax => 'TEL;TYPE=fax',
836 my $sn = $person->lastname ();
837 my $gn = $person->firstname ();
838 my $cn_esc = uri_escape ($cn);
841 Content-Type: text/x-vcard
842 Content-Disposition: attachment; filename="$cn.vcf"
853 my $vc_fld = $vcard_types{$field};
854 my $values = $person->get ($field);
856 next unless ($vc_fld);
861 print "$vc_fld:$value\n";
869 my $cn = param ('cn');
873 my $cn_html = encode_entities ($cn);
875 my $person = LiCoM::Person->load ($cn);
876 die unless ($person);
878 my ($mail) = $person->get ('mail');
882 my ($password) = $person->get ('password');
887 $password = pwgen ();
888 $person->set ('password', [$password]);
890 $password_html = encode_entities ($password);
892 $message = qq(The password for the record "$cn_html" is "$password_html".);
896 if (action_verify_send_mail ($person))
898 my $mail_html = encode_entities ($mail);
899 $message .= qq( A request for verification has been sent to $mail_html.);
904 $message .= q( There was no e-mail address, thus no verification request could be sent.);
907 print qq(\t\t<div class="message">$message</div>\n);
912 sub action_verify_send_mail
915 my $owner = LiCoM::Person->load ($UserCN);
918 my ($owner_mail) = $owner->get ('mail');
921 my $cn_uri = uri_escape ($UserCN);
922 print qq(\t\t<div class="error">You have no email set in your own profile. <a href="$MySelf?action=edit&cn=$cn_uri">Edit it now</a>!</div>\n);
927 for (keys %FieldNames)
929 $max_width = length $FieldNames{$_} if ($max_width < length $FieldNames{$_});
933 my $person_name = $person->name ();
934 my ($person_mail) = $person->get ('mail');
935 my $person_gn = $person->firstname ();
936 my ($password) = $person->get ('password');
938 my $host = $ENV{'HTTP_HOST'};
939 my $url = (defined ($ENV{'HTTPS'}) ? 'https://' : 'http://') . $host . $MySelf;
941 open ($smh, '|-', '/usr/sbin/sendmail', '-t', '-f', $owner_mail) or die ("open (sendmail): $!");
943 To: $person_name <$person_mail>
944 From: $UserCN <$owner_mail>
945 Subject: Please verify our entry in my address book
949 the following is your entry in my address book:
954 my $print = defined ($FieldNames{$field}) ? $FieldNames{$field} : $field;
955 my @values = $person->get ($field);
959 printf $smh ('%'.$max_width."s: %-s\n", $print, $_);
964 If this entry is outdated or incomplete, please take a minute and correct it.
966 Username: $person_name
969 Thank you very much :)
974 This message was automatically generated by LiCoM,
975 http://verplant.org/licom/
984 my $cn = param ('cn');
987 my $person = LiCoM::Person->load ($cn);
990 my $cn_uri = uri_escape ($cn);
991 my $cn_html = encode_entities ($cn);
994 <h2>Really delete $cn_html?</h2>
997 You are about to delete <strong>$cn_html</strong>.
998 Are you totally, absolutely sure you want to do this?
1002 [<a href="$MySelf?action=expunge&cn=$cn_uri">Yes, delete</a>]
1003 [<a href="$MySelf?action=detail&cn=$cn_uri">No, keep</a>]
1011 my $cn = param ('cn');
1014 my $cn_html = encode_entities ($cn);
1016 my $person = LiCoM::Person->load ($cn);
1022 <div>$cn_html has been deleted.</div>
1028 sub action_edit_group
1030 my $group_name = param ('group') or die;
1032 my $group_name_html = encode_entities ($group_name);
1034 my $group_obj = LiCoM::Group->load ($group_name);
1038 print qq(\t<div class="error">Group "$group_name_html" does not exist or could not be loaded.</div>\n);
1042 $group_name_html = encode_entities ($group_obj->name ());
1044 my $desc_html = encode_entities ($group_obj->description () || '');
1047 <h2>Edit contact group "$group_name_html"</h2>
1048 <form action="$MySelf" method="post">
1049 <input type="hidden" name="action" value="save_group" />
1050 <input type="hidden" name="group" value="$group_name_html" />
1054 <td>$group_name_html</td>
1057 <th>Description</th>
1058 <td><input type="text" name="description" value="$desc_html" /></td>
1061 <th colspan="2"><input type="submit" name="button" value="Save" /></th>
1068 sub action_save_group
1070 my $group_name = param ('group') or die;
1072 my $group_name_html = encode_entities ($group_name);
1074 my $group_obj = LiCoM::Group->load ($group_name);
1078 print qq(\t<div class="error">Group "$group_name_html" does not exist or could not be loaded.</div>\n);
1082 my $desc = param ('description');
1083 $group_obj->description ($desc);
1092 $title = q(Lightweight Contact Manager) unless ($title);
1094 $title = encode_entities ($title);
1097 Content-Type: text/html; charset=UTF-8
1101 <title>$title</title>
1102 <style type="text/css">
1109 background-color: inherit;
1110 text-decoration: none;
1115 text-decoration: underline;
1121 background-color: inherit;
1127 background-color: white;
1133 background-color: yellow;
1137 border: 2px solid red;
1143 background-color: white;
1153 border-top: 1px solid black;
1160 background-color: inherit;
1161 text-decoration: none;
1166 text-decoration: underline;
1171 border-top: 1px solid black;
1179 background-color: transparent;
1185 padding-bottom: 1ex;
1186 border-bottom: 1px solid black;
1225 background-color: #cccccc;
1226 vertical-align: top;
1232 background-color: #999999;
1235 vertical-align: top;
1244 background-color: inherit;
1245 text-decoration: underline;
1248 div.topmenu, div.menu
1271 border-collapse: collapse;
1286 border-bottom-width: 2px;
1291 border: 1px solid black;
1292 vertical-align: top;
1310 my $search = param ('search') || '';
1311 $search = encode_entities ($search);
1313 <div class="topmenu">
1314 <form action="$MySelf" method="post">
1315 <input type="hidden" name="action" value="browse" />
1316 <input type="submit" name="button" value="Browse" />
1318 <form action="$MySelf" method="post">
1319 <input type="hidden" name="action" value="search" />
1320 <input type="text" name="search" value="$search" />
1321 <input type="submit" name="button" value="Search" />
1323 <form action="$MySelf" method="post">
1324 <input type="hidden" name="action" value="edit" />
1325 <input type="hidden" name="dn" value="" />
1326 <input type="submit" name="button" value="Add New" />
1331 print "\t\t<h1>$title</h1>\n";
1338 "Lightweight Contact Manager",
1339 written 2005-2006 by <a href="http://verplant.org/">Florian octo Forster</a>
1340 <octo at verplant.org>
1349 my $len = @_ ? shift : 6;
1358 while (length ($retval) < $len)
1360 my $chr = int (rand (128));
1362 if ($chr >= 48 and $chr < 58)
1366 elsif ($chr >= 65 and $chr < 91)
1370 elsif ($chr >= 97 and $chr < 123)
1378 $retval .= chr ($chr);
1381 $retval = '' if (!$numbers or !$lchars or !$uchars);
1395 if ($val !~ m#^[a-zA-Z]+://#)
1397 push (@errors, 'URIs have to begin with a protocol, e.g. "http://", "ftp://" etc.');
1402 for (param ('homephone'), param ('cellphone'), param ('officephone'), param ('fax'))
1405 next unless ($number);
1407 if ($number !~ m/^\+[0-9 \-]+$/)
1409 push (@errors, 'Telephone numbers have to begin with the country code and only numbers, spaces and dashes are allowed, e.g. "+49 911-123456"');
1414 print qq(\t\t<div class="error">\n) if (@errors);
1415 for (my $i = 0; $i < scalar (@errors); $i++)
1417 my $e = $errors[$i];
1419 print "<br />\n" if ($i);
1422 print qq(\n\t\t</div>\n\n) if (@errors);
1424 return (scalar (@errors));
1429 my $contacts = @_ ? shift : {};
1434 my @values = grep { $_ } (param ($field));
1436 next unless (@values);
1438 if ($field eq 'homephone' or $field eq 'cellphone' or $field eq 'officephone' or $field eq 'fax')
1442 $_ =~ s/[^0-9 \-]//g;
1443 $_ = '+' . $_ if ($_);
1447 $contacts->{$field} = [@values] if (@values);