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

HEADcourier-fixdev-browser-capabilitiespdorelease-0.6release-0.7release-0.8
Last change on this file since d7344819 was d7344819, checked in by alecpl <alec@…>, 2 years ago
  • Added option to specify to which address book add new contacts
  • Property mode set to 100644
File size: 2.9 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$abook = $RCMAIL->config->get('default_addressbook');
27
28// Get configured addressbook
29$CONTACTS = $RCMAIL->get_address_book($abook, true);
30
31// Get first writeable addressbook if the configured doesn't exist
32// This can happen when user deleted the addressbook (e.g. Kolab folder)
33if ($abook !== null && !is_object($CONTACTS)) {
34  $CONTACTS = $RCMAIL->get_address_book(null, true);
35}
36
37if (!empty($_POST['_address']) && is_object($CONTACTS))
38{
39  $contact_arr = $IMAP->decode_address_list(get_input_value('_address', RCUBE_INPUT_POST, true), 1, false);
40
41  if (!empty($contact_arr[1]['mailto'])) {
42    $contact = array(
43      'email' => $contact_arr[1]['mailto'],
44      'name' => $contact_arr[1]['name']
45    );
46
47    // Validity checks
48    if (empty($contact['email'])) {
49      $OUTPUT->show_message('errorsavingcontact', 'error');
50      $OUTPUT->send();
51    }
52   
53    $email = rcube_idn_to_ascii($contact['email']);
54    if (!check_email($email, false)) {
55      $OUTPUT->show_message('emailformaterror', 'error', array('email' => $contact['email']));
56      $OUTPUT->send();
57    }
58
59    $contact['email'] = rcube_idn_to_utf8($contact['email']);
60    $contact['name'] = rcube_addressbook::compose_display_name($contact);
61
62    // check for existing contacts
63    $existing = $CONTACTS->search('email', $contact['email'], true, false);
64
65    if ($done = $existing->count)
66      $OUTPUT->show_message('contactexists', 'warning');
67    else {
68      $plugin = $RCMAIL->plugins->exec_hook('contact_create', array('record' => $contact, 'source' => null));
69      $contact = $plugin['record'];
70
71      $done = !$plugin['abort'] ? $CONTACTS->insert($contact) : $plugin['result'];
72
73      if ($done)
74        $OUTPUT->show_message('addedsuccessfully', 'confirmation');
75    }
76  }
77}
78
79if (!$done)
80  $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsavingcontact', 'error');
81
82$OUTPUT->send();
83
Note: See TracBrowser for help on using the repository browser.