source: github/program/steps/mail/addcontact.inc @ e848180

HEADcourier-fixdev-browser-capabilitiespdorelease-0.6release-0.7release-0.8
Last change on this file since e848180 was e848180, checked in by thomascube <thomas@…>, 2 years ago

Improve display name composition when saving contacts (#1487143), with plugin-support; allow empty names in sql address book, fall back to e-mail address in listing and vcard export

  • Property mode set to 100644
File size: 2.6 KB
RevLine 
[4e17e6c]1<?php
2
3/*
4 +-----------------------------------------------------------------------+
5 | program/steps/mail/addcontact.inc                                     |
6 |                                                                       |
[e019f2d]7 | This file is part of the Roundcube Webmail client                     |
[f5e7b353]8 | Copyright (C) 2005-2009, The Roundcube Dev Team                       |
[30233b8]9 | Licensed under the GNU GPL                                            |
[4e17e6c]10 |                                                                       |
11 | PURPOSE:                                                              |
12 |   Add the submitted contact to the users address book                 |
13 |                                                                       |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16 +-----------------------------------------------------------------------+
17
18 $Id$
19
20*/
21
[881217a]22// only process ajax requests
23if (!$OUTPUT->ajax_call)
24  return;
25
[f115416]26$done = false;
[ade8e11]27$CONTACTS = $RCMAIL->get_address_book(null, true);
[4e17e6c]28
[ade8e11]29if (!empty($_POST['_address']) && is_object($CONTACTS))
[f115416]30{
31  $contact_arr = $IMAP->decode_address_list(get_input_value('_address', RCUBE_INPUT_POST, true), 1, false);
[6f09681]32
[ce92ba7]33  if (!empty($contact_arr[1]['mailto'])) {
[f115416]34    $contact = array(
35      'email' => $contact_arr[1]['mailto'],
36      'name' => $contact_arr[1]['name']
37    );
[e999919]38
[6f09681]39    // Validity checks
40    if (empty($contact['email'])) {
41      $OUTPUT->show_message('errorsavingcontact', 'error');
42      $OUTPUT->send();
43    }
[e18d992e]44   
45    $email = rcube_idn_to_ascii($contact['email']);
46    if (!check_email($email, false)) {
[6f09681]47      $OUTPUT->show_message('emailformaterror', 'error', array('email' => $contact['email']));
48      $OUTPUT->send();
49    }
50
[e8d5bdc]51    $contact['email'] = rcube_idn_to_utf8($contact['email']);
[e848180]52    $contact['name'] = rcube_addressbook::compose_display_name($contact);
[f115416]53
54    // check for existing contacts
[3fc00e6]55    $existing = $CONTACTS->search('email', $contact['email'], true, false);
[ce92ba7]56
[f115416]57    if ($done = $existing->count)
58      $OUTPUT->show_message('contactexists', 'warning');
[ce92ba7]59    else {
[e6ce006]60      $plugin = $RCMAIL->plugins->exec_hook('contact_create', array('record' => $contact, 'source' => null));
[3ddbe66]61      $contact = $plugin['record'];
62
[ce92ba7]63      $done = !$plugin['abort'] ? $CONTACTS->insert($contact) : $plugin['result'];
64
65      if ($done)
[3ddbe66]66        $OUTPUT->show_message('addedsuccessfully', 'confirmation');
67    }
[4e17e6c]68  }
[f115416]69}
[4e17e6c]70
[f115416]71if (!$done)
[6f09681]72  $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsavingcontact', 'error');
[4e17e6c]73
[f115416]74$OUTPUT->send();
[b25dfd0]75
Note: See TracBrowser for help on using the repository browser.