4 +-----------------------------------------------------------------------+
5 | program/steps/mail/addcontact.inc |
7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2005-2009, Roundcube Dev. - Switzerland |
9 | Licensed under the GNU GPL |
12 | Add the submitted contact to the users address book |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
16 +-----------------------------------------------------------------------+
18 $Id: addcontact.inc 4509 2011-02-09 10:51:50Z thomasb $
22 // only process ajax requests
23 if (!$OUTPUT->ajax_call)
27 $CONTACTS = $RCMAIL->get_address_book(null, true);
29 if (!empty($_POST['_address']) && is_object($CONTACTS))
31 $contact_arr = $IMAP->decode_address_list(get_input_value('_address', RCUBE_INPUT_POST, true), 1, false);
33 if (!empty($contact_arr[1]['mailto'])) {
35 'email' => $contact_arr[1]['mailto'],
36 'name' => $contact_arr[1]['name']
40 if (empty($contact['email'])) {
41 $OUTPUT->show_message('errorsavingcontact', 'error');
44 else if (!check_email($contact['email'], false)) {
45 $OUTPUT->show_message('emailformaterror', 'error', array('email' => $contact['email']));
49 $contact['email'] = rcube_idn_to_utf8($contact['email']);
51 // use email address part for name
52 if (empty($contact['name']) || $contact['name'] == $contact['email'])
53 $contact['name'] = ucfirst(preg_replace('/[\.\-]/', ' ', substr($contact['email'], 0, strpos($contact['email'], '@'))));
55 // check for existing contacts
56 $existing = $CONTACTS->search('email', $contact['email'], true, false);
58 if ($done = $existing->count)
59 $OUTPUT->show_message('contactexists', 'warning');
61 $plugin = $RCMAIL->plugins->exec_hook('contact_create', array('record' => $contact, 'source' => null));
62 $contact = $plugin['record'];
64 $done = !$plugin['abort'] ? $CONTACTS->insert($contact) : $plugin['result'];
67 $OUTPUT->show_message('addedsuccessfully', 'confirmation');
73 $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsavingcontact', 'error');