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
Line 
1<?php
2
3/*
4 +-----------------------------------------------------------------------+
5 | program/steps/mail/addcontact.inc                                     |
6 |                                                                       |
7 | This file is part of the Roundcube Webmail client                     |
8 | Copyright (C) 2005-2009, The Roundcube Dev Team                       |
9 | Licensed under the GNU GPL                                            |
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
22// only process ajax requests
23if (!$OUTPUT->ajax_call)
24  return;
25
26$done = false;
27$CONTACTS = $RCMAIL->get_address_book(null, true);
28
29if (!empty($_POST['_address']) && is_object($CONTACTS))
30{
31  $contact_arr = $IMAP->decode_address_list(get_input_value('_address', RCUBE_INPUT_POST, true), 1, false);
32
33  if (!empty($contact_arr[1]['mailto'])) {
34    $contact = array(
35      'email' => $contact_arr[1]['mailto'],
36      'name' => $contact_arr[1]['name']
37    );
38
39    // Validity checks
40    if (empty($contact['email'])) {
41      $OUTPUT->show_message('errorsavingcontact', 'error');
42      $OUTPUT->send();
43    }
44   
45    $email = rcube_idn_to_ascii($contact['email']);
46    if (!check_email($email, false)) {
47      $OUTPUT->show_message('emailformaterror', 'error', array('email' => $contact['email']));
48      $OUTPUT->send();
49    }
50
51    $contact['email'] = rcube_idn_to_utf8($contact['email']);
52    $contact['name'] = rcube_addressbook::compose_display_name($contact);
53
54    // check for existing contacts
55    $existing = $CONTACTS->search('email', $contact['email'], true, false);
56
57    if ($done = $existing->count)
58      $OUTPUT->show_message('contactexists', 'warning');
59    else {
60      $plugin = $RCMAIL->plugins->exec_hook('contact_create', array('record' => $contact, 'source' => null));
61      $contact = $plugin['record'];
62
63      $done = !$plugin['abort'] ? $CONTACTS->insert($contact) : $plugin['result'];
64
65      if ($done)
66        $OUTPUT->show_message('addedsuccessfully', 'confirmation');
67    }
68  }
69}
70
71if (!$done)
72  $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsavingcontact', 'error');
73
74$OUTPUT->send();
75
Note: See TracBrowser for help on using the repository browser.