4 +-----------------------------------------------------------------------+
5 | program/steps/mail/addcontact.inc |
7 | This file is part of the RoundCube Webmail client |
8 | Copyright (C) 2005-2007, 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 1712 2008-09-02 07:42:46Z thomasb $
23 $CONTACTS = $RCMAIL->get_address_book(null, true);
25 if (!empty($_POST['_address']) && is_object($CONTACTS))
27 $contact_arr = $IMAP->decode_address_list(get_input_value('_address', RCUBE_INPUT_POST, true), 1, false);
29 if (!empty($contact_arr[1]['mailto']))
32 'email' => $contact_arr[1]['mailto'],
33 'name' => $contact_arr[1]['name']
36 // use email address part for name
37 if (empty($contact['name']) || $contact['name'] == $contact['email'])
38 $contact['name'] = ucfirst(preg_replace('/[\.\-]/', ' ', substr($contact['email'], 0, strpos($contact['email'], '@'))));
40 // check for existing contacts
41 $existing = $CONTACTS->search('email', $contact['email'], true, false);
42 if ($done = $existing->count)
43 $OUTPUT->show_message('contactexists', 'warning');
44 else if ($done = $CONTACTS->insert($contact))
45 $OUTPUT->show_message('addedsuccessfully', 'confirmation');
50 $OUTPUT->show_message('errorsavingcontact', 'warning');