322485e0589c9e599e81975a6bfc85d96c3ff552
6 * This contains utility functions for dealing with multiple identities
8 * @copyright © 1999-2007 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @package squirrelmail
17 * Returns an array of all the identities.
18 * Array is keyed: full_name, reply_to, email_address, index, signature
19 * @return array full_name,reply_to,email_address,index,signature
22 function get_identities() {
24 global $username, $data_dir, $domain;
26 $em = getPref($data_dir,$username,'email_address');
28 if (strpos($username , '@') == false) {
29 $em = $username.'@'.$domain;
34 $identities = array();
35 /* We always have this one, even if the user doesn't use multiple identities */
36 $identities[] = array('full_name' => getPref($data_dir,$username,'full_name'),
37 'email_address' => $em,
38 'reply_to' => getPref($data_dir,$username,'reply_to'),
39 'signature' => getSig($data_dir,$username,'g'),
42 $num_ids = getPref($data_dir,$username,'identities');
43 /* If there are any others, add them to the array */
44 if (!empty($num_ids) && $num_ids > 1) {
45 for ($i=1;$i<$num_ids;$i++
) {
46 $identities[] = array('full_name' => getPref($data_dir,$username,'full_name' . $i),
47 'email_address' => getPref($data_dir,$username,'email_address' . $i),
48 'reply_to' => getPref($data_dir,$username,'reply_to' . $i),
49 'signature' => getSig($data_dir,$username,$i),
58 * Function to save the identities array
60 * @param array $identities Array of identities
61 * @since 1.5.1 and 1.4.5
63 function save_identities($identities) {
65 global $username, $data_dir, $domain;
67 if (empty($identities) ||
!is_array($identities)) {
72 $num_cur = getPref($data_dir, $username, 'identities');
74 $cnt = count($identities);
76 // Remove any additional identities in prefs //
77 for($i=$cnt; $i <= $num_cur; $i++
) {
78 removePref($data_dir, $username, 'full_name' . $i);
79 removePref($data_dir, $username, 'email_address' . $i);
80 removePref($data_dir, $username, 'reply_to' . $i);
81 setSig($data_dir, $username, $i, '');
84 foreach($identities as $id=>$ident) {
88 setPref($data_dir, $username, 'full_name' . $key, $ident['full_name']);
89 setPref($data_dir, $username, 'email_address' . $key, $ident['email_address']);
90 setPref($data_dir, $username, 'reply_to' . $key, $ident['reply_to']);
93 setSig($data_dir, $username, 'g', $ident['signature']);
95 setSig($data_dir, $username, $key, $ident['signature']);
100 setPref($data_dir, $username, 'identities', $cnt);
105 * Returns an array with a fixed set of identities
107 * @param array $identities Array of identities
108 * @param int $id Identity to modify
109 * @param string $action Action to perform
111 * @since 1.5.1 and 1.4.5
113 function sqfixidentities( $identities, $id, $action ) {
119 if (empty($identities) ||
!is_array($identities)) {
123 foreach( $identities as $key=>$ident ) {
125 if (empty_identity($ident)) {
136 // inform plugins about renumbering of ids
137 do_hook('options_identities_renumber', $temp=array(&$id, 'default'));
141 $fixed[$i+
1] = $ident;
147 if ($key == ($id - 1)) {
150 // inform plugins about renumbering of ids
151 do_hook('options_identities_renumber', $temp=array(&$id , $id - 1));
159 $fixed[$i] = $tmp_hold;
167 // inform plugins about deleted id
168 do_hook('options_identities_process', $temp=array(&$action, &$id));
176 // Process actions from plugins and save/update action //
179 * send action and id information. number of hook arguments
180 * differs from 1.4.4 or older and 1.5.0. count($args) can
181 * be used to detect modified hook. Older hook does not
182 * provide information that can be useful for plugins.
184 do_hook('options_identities_process', $temp=array(&$action, &$id));
190 // Inc array index //
200 * Function to test if identity is empty
202 * @param array $identity Identitiy Array
204 * @since 1.5.1 and 1.4.5
206 function empty_identity($ident) {
207 if (empty($ident['full_name']) && empty($ident['email_address']) && empty($ident['signature']) && empty($ident['reply_to'])) {