source: subversion/trunk/roundcubemail/program/steps/settings/save_identity.inc

Last change on this file was 6109, checked in by thomasb, 14 months ago

Support mutliple name/email pairs for Bcc and Reply-To identity settings (#1488445)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.7 KB
Line 
1<?php
2
3/*
4 +-----------------------------------------------------------------------+
5 | program/steps/settings/save_identity.inc                              |
6 |                                                                       |
7 | This file is part of the Roundcube Webmail client                     |
8 | Copyright (C) 2005-2009, The Roundcube Dev Team                       |
9 |                                                                       |
10 | Licensed under the GNU General Public License version 3 or            |
11 | any later version with exceptions for skins & plugins.                |
12 | See the README file for a full license statement.                     |
13 |                                                                       |
14 | PURPOSE:                                                              |
15 |   Save an identity record or to add a new one                         |
16 |                                                                       |
17 +-----------------------------------------------------------------------+
18 | Author: Thomas Bruederli <roundcube@gmail.com>                        |
19 +-----------------------------------------------------------------------+
20
21 $Id$
22
23*/
24
25define('IDENTITIES_LEVEL', intval($RCMAIL->config->get('identities_level', 0)));
26
27$a_save_cols = array('name', 'email', 'organization', 'reply-to', 'bcc', 'standard', 'signature', 'html_signature');
28$a_boolean_cols = array('standard', 'html_signature');
29$updated = $default_id = false;
30
31// check input
32if (empty($_POST['_name']) || (empty($_POST['_email']) && IDENTITIES_LEVEL != 1 && IDENTITIES_LEVEL != 3))
33{
34  $OUTPUT->show_message('formincomplete', 'warning');
35  rcmail_overwrite_action('edit-identity');
36  return;
37}
38
39
40$save_data = array();
41foreach ($a_save_cols as $col)
42{
43  $fname = '_'.$col;
44  if (isset($_POST[$fname]))
45    $save_data[$col] = get_input_value($fname, RCUBE_INPUT_POST, true);
46}
47
48// set "off" values for checkboxes that were not checked, and therefore
49// not included in the POST body.
50foreach ($a_boolean_cols as $col)
51{
52  $fname = '_' . $col;
53  if (!isset($_POST[$fname]))
54    $save_data[$col] = 0;
55}
56
57// unset email address if user has no rights to change it
58if (IDENTITIES_LEVEL == 1 || IDENTITIES_LEVEL == 3)
59  unset($save_data['email']);
60
61// Validate e-mail addresses
62$email_checks = array(rcube_idn_to_ascii($save_data['email']));
63foreach (array('reply-to', 'bcc') as $item) {
64  foreach (rcube_mime::decode_address_list(rcube_idn_to_ascii($save_data[$item]), null, false) as $rcpt)
65    $email_checks[] = $rcpt['mailto'];
66}
67
68foreach ($email_checks as $email) {
69  if ($email && !check_email($email)) {
70    // show error message
71    $OUTPUT->show_message('emailformaterror', 'error', array('email' => rcube_idn_to_utf8($email)), false);
72    rcmail_overwrite_action('edit-identity');
73    return;
74  }
75}
76
77// update an existing contact
78if ($_POST['_iid'])
79{
80  $iid = get_input_value('_iid', RCUBE_INPUT_POST);
81  $plugin = $RCMAIL->plugins->exec_hook('identity_update', array('id' => $iid, 'record' => $save_data));
82  $save_data = $plugin['record'];
83
84  if ($save_data['email'])
85    $save_data['email'] = rcube_idn_to_ascii($save_data['email']);
86  if ($save_data['bcc'])
87    $save_data['bcc'] = rcube_idn_to_ascii($save_data['bcc']);
88  if ($save_data['reply-to'])
89    $save_data['reply-to'] = rcube_idn_to_ascii($save_data['reply-to']);
90
91  if (!$plugin['abort'])
92    $updated = $RCMAIL->user->update_identity($iid, $save_data);
93  else
94    $updated = $plugin['result'];
95
96  if ($updated) {
97    $OUTPUT->show_message('successfullysaved', 'confirmation');
98
99    if (!empty($_POST['_standard']))
100      $default_id = get_input_value('_iid', RCUBE_INPUT_POST);
101
102    if ($_POST['_framed']) {
103      // update the changed col in list
104      $OUTPUT->command('parent.update_identity_row', $iid, Q(trim($save_data['name'] . ' <' . rcube_idn_to_utf8($save_data['email']) .'>')));
105    }
106  }
107  else {
108    // show error message
109    $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error', null, false);
110    rcmail_overwrite_action('edit-identity');
111    return;
112  }
113}
114
115// insert a new identity record
116else if (IDENTITIES_LEVEL < 2)
117{
118  if (IDENTITIES_LEVEL == 1)
119    $save_data['email'] = $RCMAIL->user->get_username();
120
121  $plugin = $RCMAIL->plugins->exec_hook('identity_create', array('record' => $save_data));
122  $save_data = $plugin['record'];
123
124  if ($save_data['email'])
125    $save_data['email']    = rcube_idn_to_ascii($save_data['email']);
126  if ($save_data['bcc'])
127    $save_data['bcc']      = rcube_idn_to_ascii($save_data['bcc']);
128  if ($save_data['reply-to'])
129    $save_data['reply-to'] = rcube_idn_to_ascii($save_data['reply-to']);
130
131  if (!$plugin['abort'])
132    $insert_id = $save_data['email'] ? $RCMAIL->user->insert_identity($save_data) : null;
133  else
134    $insert_id = $plugin['result'];
135
136  if ($insert_id) {
137    $OUTPUT->show_message('successfullysaved', 'confirmation', null, false);
138
139    $_GET['_iid'] = $insert_id;
140
141    if (!empty($_POST['_standard']))
142      $default_id = $insert_id;
143
144    if ($_POST['_framed']) {
145      // add a new row to the list
146      $OUTPUT->command('parent.update_identity_row', $insert_id, Q(trim($save_data['name'] . ' <' . rcube_idn_to_utf8($save_data['email']) .'>')), true);
147    }
148  }
149  else {
150    // show error message
151    $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error', null, false);
152    rcmail_overwrite_action('edit-identity');
153    return;
154  }
155}
156else
157  $OUTPUT->show_message('opnotpermitted', 'error');
158
159
160// mark all other identities as 'not-default'
161if ($default_id)
162  $RCMAIL->user->set_default($default_id);
163
164// go to next step
165if (!empty($_REQUEST['_framed'])) {
166  rcmail_overwrite_action('edit-identity');
167}
168else
169  rcmail_overwrite_action('identities');
Note: See TracBrowser for help on using the repository browser.