squirrelmail-webmail  1.4.22
About: SquirrelMail is a standards-based webmail package with strong MIME support, address books, and folder manipulation (written in PHP4).
  Fossies Dox: squirrelmail-webmail-1.4.22.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

identity.php
Go to the documentation of this file.
1 <?php
2 
16 if (!defined('SM_PATH')) {
17  define('SM_PATH','../');
18 }
19 
20 include_once(SM_PATH . 'include/load_prefs.php');
21 
27 function get_identities() {
28 
29  global $username, $data_dir, $domain;
30 
31  $em = getPref($data_dir,$username,'email_address');
32  if ( ! $em ) {
33  if (strpos($username , '@') == false) {
34  $em = $username.'@'.$domain;
35  } else {
36  $em = $username;
37  }
38  }
39  $identities = array();
40  /* We always have this one, even if the user doesn't use multiple identities */
41  $identities[] = array('full_name' => getPref($data_dir,$username,'full_name'),
42  'email_address' => $em,
43  'reply_to' => getPref($data_dir,$username,'reply_to'),
44  'signature' => getSig($data_dir,$username,'g'),
45  'index' => 0 );
46 
47  $num_ids = getPref($data_dir,$username,'identities');
48  /* If there are any others, add them to the array */
49  if (!empty($num_ids) && $num_ids > 1) {
50  for ($i=1;$i<$num_ids;$i++) {
51  $identities[] = array('full_name' => getPref($data_dir,$username,'full_name' . $i),
52  'email_address' => getPref($data_dir,$username,'email_address' . $i),
53  'reply_to' => getPref($data_dir,$username,'reply_to' . $i),
54  'signature' => getSig($data_dir,$username,$i),
55  'index' => $i );
56  }
57  }
58 
59  return $identities;
60 }
61 
67 function save_identities($identities) {
68 
69  global $username, $data_dir, $domain;
70 
71  if (empty($identities) || !is_array($identities)) {
72  return;
73  }
74 
75 
76  $num_cur = getPref($data_dir, $username, 'identities');
77 
78  $cnt = count($identities);
79 
80  // Remove any additional identities in prefs //
81  for($i=$cnt; $i <= $num_cur; $i++) {
82  removePref($data_dir, $username, 'full_name' . $i);
83  removePref($data_dir, $username, 'email_address' . $i);
84  removePref($data_dir, $username, 'reply_to' . $i);
85  setSig($data_dir, $username, $i, '');
86  }
87 
88  foreach($identities as $id=>$ident) {
89 
90  $key = ($id?$id:'');
91 
92  setPref($data_dir, $username, 'full_name' . $key, $ident['full_name']);
93  setPref($data_dir, $username, 'email_address' . $key, $ident['email_address']);
94  setPref($data_dir, $username, 'reply_to' . $key, $ident['reply_to']);
95 
96  if ($id === 0) {
97  setSig($data_dir, $username, 'g', $ident['signature']);
98  } else {
99  setSig($data_dir, $username, $key, $ident['signature']);
100  }
101 
102  }
103 
104  setPref($data_dir, $username, 'identities', $cnt);
105 
106 }
107 
116 function sqfixidentities( $identities, $id, $action ) {
117 
118  $fixed = array();
119  $tmp_hold = array();
120  $i = 0;
121 
122  if (empty($identities) || !is_array($identities)) {
123  return $fixed;
124  }
125 
126  foreach( $identities as $key=>$ident ) {
127 
128  if (empty_identity($ident)) {
129  continue;
130  }
131 
132  switch($action) {
133 
134  case 'makedefault':
135 
136  if ($key == $id) {
137  $fixed[0] = $ident;
138 
139  // inform plugins about renumbering of ids
140  do_hook('options_identities_renumber', $id, 'default');
141 
142  continue 2;
143  } else {
144  $fixed[$i+1] = $ident;
145  }
146  break;
147 
148  case 'move':
149 
150  if ($key == ($id - 1)) {
151  $tmp_hold = $ident;
152 
153  // inform plugins about renumbering of ids
154  do_hook('options_identities_renumber', $id , $id - 1);
155 
156  continue 2;
157  } else {
158  $fixed[$i] = $ident;
159 
160  if ($key == $id) {
161  $i++;
162  $fixed[$i] = $tmp_hold;
163  }
164  }
165  break;
166 
167  case 'delete':
168 
169  if ($key == $id) {
170  // inform plugins about deleted id
171  do_hook('options_identities_process', $action, $id);
172 
173  continue 2;
174  } else {
175  $fixed[$i] = $ident;
176  }
177  break;
178 
179  // Process actions from plugins and save/update action //
180  default:
187  do_hook('options_identities_process', $action, $id);
188 
189  $fixed[$i] = $ident;
190 
191  }
192 
193  // Inc array index //
194  $i++;
195  }
196 
197  ksort($fixed);
198  return $fixed;
199 
200 }
201 
208 function empty_identity($ident) {
209  if (empty($ident['full_name']) && empty($ident['email_address']) && empty($ident['signature']) && empty($ident['reply_to'])) {
210  return true;
211  } else {
212  return false;
213  }
214 }
215 
getPref
getPref($data_dir, $username, $string, $default='')
Definition: db_prefs.php:316
$cnt
$cnt
Definition: options_identities.php:86
getSig
getSig($data_dir, $username, $number)
Definition: db_prefs.php:407
$data_dir
$data_dir
Definition: config_default.php:499
$id
$id
Definition: move_messages.php:190
setPref
setPref($data_dir, $username, $string, $set_to)
Definition: db_prefs.php:352
empty_identity
empty_identity($ident)
Definition: identity.php:208
$username
global $username
Definition: validate.php:55
do_hook
do_hook($name)
Definition: plugin.php:42
get_identities
get_identities()
Definition: identity.php:27
removePref
removePref($data_dir, $username, $string)
Definition: db_prefs.php:331
sqfixidentities
sqfixidentities( $identities, $id, $action)
Definition: identity.php:116
SM_PATH
const SM_PATH
Definition: decrypt_headers.php:16
$action
$action
Definition: options.php:34
save_identities
save_identities($identities)
Definition: identity.php:67
$domain
$domain
Definition: config_default.php:118
setSig
setSig($data_dir, $username, $number, $string)
Definition: db_prefs.php:393