source: github/program/steps/mail/addcontact.inc @ 3ddbe66

HEADcourier-fixdev-browser-capabilitiespdorelease-0.6release-0.7release-0.8
Last change on this file since 3ddbe66 was 3ddbe66, checked in by alecpl <alec@…>, 4 years ago
  • added create_contact hook in mail/addcontact action (#1485828)
  • Property mode set to 100644
File size: 2.2 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-2007, RoundCube Dev. - Switzerland                 |
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$done = false;
23$CONTACTS = $RCMAIL->get_address_book(null, true);
24
25if (!empty($_POST['_address']) && is_object($CONTACTS))
26{
27  $contact_arr = $IMAP->decode_address_list(get_input_value('_address', RCUBE_INPUT_POST, true), 1, false);
28 
29  if (!empty($contact_arr[1]['mailto']))
30  {
31    $contact = array(
32      'email' => $contact_arr[1]['mailto'],
33      'name' => $contact_arr[1]['name']
34    );
35   
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'], '@'))));
39
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
45    {
46      $plugin = $RCMAIL->plugins->exec_hook('create_contact', array('record' => $contact, 'source' => get_input_value('_source', RCUBE_INPUT_GPC)));
47      $contact = $plugin['record'];
48
49      if (!$plugin['abort'] && ($done = $CONTACTS->insert($contact)))
50        $OUTPUT->show_message('addedsuccessfully', 'confirmation');
51    }
52  }
53}
54
55if (!$done)
56  $OUTPUT->show_message('errorsavingcontact', 'warning');
57
58$OUTPUT->send();
59?>
Note: See TracBrowser for help on using the repository browser.