Aleksander Machniak
2013-12-25 c97625e02a95ebd995af8a06c27229581a071ddd
program/steps/mail/addcontact.inc
@@ -5,7 +5,7 @@
 | program/steps/mail/addcontact.inc                                     |
 |                                                                       |
 | This file is part of the Roundcube Webmail client                     |
 | Copyright (C) 2005-2009, The Roundcube Dev Team                       |
 | Copyright (C) 2005-2013, The Roundcube Dev Team                       |
 |                                                                       |
 | Licensed under the GNU General Public License version 3 or            |
 | any later version with exceptions for skins & plugins.                |
@@ -20,20 +20,21 @@
*/
// only process ajax requests
if (!$OUTPUT->ajax_call)
if (!$OUTPUT->ajax_call) {
  return;
}
// Get default addressbook
$CONTACTS = $RCMAIL->get_address_book(-1, true);
if (!empty($_POST['_address']) && is_object($CONTACTS))
{
  $contact_arr = rcube_mime::decode_address_list(rcube_utils::get_input_value('_address', rcube_utils::INPUT_POST, true), 1, false);
if (!empty($_POST['_address']) && is_object($CONTACTS)) {
    $address = rcube_utils::get_input_value('_address', rcube_utils::INPUT_POST, true);
    $contact_arr = rcube_mime::decode_address_list($address, 1, false);
  if (!empty($contact_arr[1]['mailto'])) {
    $contact = array(
      'email' => $contact_arr[1]['mailto'],
      'name' => $contact_arr[1]['name']
            'name'  => $contact_arr[1]['name'],
    );
    // Validity checks
@@ -49,10 +50,12 @@
    }
    $contact['email'] = rcube_utils::idn_to_utf8($contact['email']);
    $contact = $RCMAIL->plugins->exec_hook('contact_displayname', $contact);
    if (empty($contact['firstname']) || empty($contact['surname']))
        if (empty($contact['firstname']) || empty($contact['surname'])) {
      $contact['name'] = rcube_addressbook::compose_display_name($contact);
        }
    // validate contact record
    if (!$CONTACTS->validate($contact, true)) {
@@ -67,22 +70,24 @@
    // check for existing contacts
    $existing = $CONTACTS->search('email', $contact['email'], 1, false);
    if ($done = $existing->count)
        if ($done = $existing->count) {
      $OUTPUT->show_message('contactexists', 'warning');
        }
    else {
      $plugin = $RCMAIL->plugins->exec_hook('contact_create', array('record' => $contact, 'source' => null));
      $contact = $plugin['record'];
      $done = !$plugin['abort'] ? $CONTACTS->insert($contact) : $plugin['result'];
      if ($done)
            if ($done) {
        $OUTPUT->show_message('addedsuccessfully', 'confirmation');
    }
  }
}
}
if (!$done)
if (!$done) {
  $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsavingcontact', 'error');
}
$OUTPUT->send();