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 2758 2009-07-16 15:01:05Z 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']))
36 'email' => $contact_arr[1]['mailto'],
37 'name' => $contact_arr[1]['name']
40 // use email address part for name
41 if (empty($contact['name']) || $contact['name'] == $contact['email'])
42 $contact['name'] = ucfirst(preg_replace('/[\.\-]/', ' ', substr($contact['email'], 0, strpos($contact['email'], '@'))));
44 // check for existing contacts
45 $existing = $CONTACTS->search('email', $contact['email'], true, false);
46 if ($done = $existing->count)
47 $OUTPUT->show_message('contactexists', 'warning');
50 $plugin = $RCMAIL->plugins->exec_hook('create_contact', array('record' => $contact, 'source' => null));
51 $contact = $plugin['record'];
53 if (!$plugin['abort'] && ($done = $CONTACTS->insert($contact)))
54 $OUTPUT->show_message('addedsuccessfully', 'confirmation');
60 $OUTPUT->show_message('errorsavingcontact', 'warning');