comparison program/steps/mail/addcontact.inc @ 0:4681f974d28b

vanilla 1.3.3 distro, I hope
author Charlie Root
date Thu, 04 Jan 2018 15:52:31 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4681f974d28b
1 <?php
2
3 /**
4 +-----------------------------------------------------------------------+
5 | program/steps/mail/addcontact.inc |
6 | |
7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2005-2013, The Roundcube Dev Team |
9 | |
10 | Licensed under the GNU General Public License version 3 or |
11 | any later version with exceptions for skins & plugins. |
12 | See the README file for a full license statement. |
13 | |
14 | PURPOSE: |
15 | Add the submitted contact to the users address book |
16 | |
17 +-----------------------------------------------------------------------+
18 | Author: Thomas Bruederli <roundcube@gmail.com> |
19 +-----------------------------------------------------------------------+
20 */
21
22 // only process ajax requests
23 if (!$OUTPUT->ajax_call) {
24 return;
25 }
26
27 // Get default addressbook
28 $CONTACTS = $RCMAIL->get_address_book(-1, true);
29
30 if (!empty($_POST['_address']) && is_object($CONTACTS)) {
31 $address = rcube_utils::get_input_value('_address', rcube_utils::INPUT_POST, true);
32 $contact_arr = rcube_mime::decode_address_list($address, 1, false);
33
34 if (!empty($contact_arr[1]['mailto'])) {
35 $contact = array(
36 'email' => $contact_arr[1]['mailto'],
37 'name' => $contact_arr[1]['name'],
38 );
39
40 // Validity checks
41 if (empty($contact['email'])) {
42 $OUTPUT->show_message('errorsavingcontact', 'error');
43 $OUTPUT->send();
44 }
45
46 $email = rcube_utils::idn_to_ascii($contact['email']);
47 if (!rcube_utils::check_email($email, false)) {
48 $OUTPUT->show_message('emailformaterror', 'error', array('email' => $contact['email']));
49 $OUTPUT->send();
50 }
51
52 $contact['email'] = rcube_utils::idn_to_utf8($contact['email']);
53
54 $contact = $RCMAIL->plugins->exec_hook('contact_displayname', $contact);
55
56 if (empty($contact['firstname']) || empty($contact['surname'])) {
57 $contact['name'] = rcube_addressbook::compose_display_name($contact);
58 }
59
60 // validate contact record
61 if (!$CONTACTS->validate($contact, true)) {
62 $error = $CONTACTS->get_error();
63 // TODO: show dialog to complete record
64 // if ($error['type'] == rcube_addressbook::ERROR_VALIDATE) { }
65
66 $OUTPUT->show_message($error['message'] ?: 'errorsavingcontact', 'error');
67 $OUTPUT->send();
68 }
69
70 // check for existing contacts
71 $existing = $CONTACTS->search('email', $contact['email'], 1, false);
72
73 if ($done = $existing->count) {
74 $OUTPUT->show_message('contactexists', 'warning');
75 }
76 else {
77 $plugin = $RCMAIL->plugins->exec_hook('contact_create', array('record' => $contact, 'source' => null));
78 $contact = $plugin['record'];
79
80 $done = !$plugin['abort'] ? $CONTACTS->insert($contact) : $plugin['result'];
81
82 if ($done) {
83 $OUTPUT->show_message('addedsuccessfully', 'confirmation');
84 }
85 }
86 }
87 }
88
89 if (!$done) {
90 $OUTPUT->show_message($plugin['message'] ?: 'errorsavingcontact', 'error');
91 }
92
93 $OUTPUT->send();