17215555da88ccf1dfafa2d6fb5bbc5a98a0f0f2
6 * Copyright (c) 1999-2005 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This contains utility functions for dealing with multiple identities
12 * @package squirrelmail
16 /** Used to simplify includes
19 if (!defined('SM_PATH')) {
20 define('SM_PATH','../');
23 /** preference and signature functions */
24 include_once(SM_PATH
. 'include/load_prefs.php');
27 * Returns an array of all the identities.
28 * Array is keyed: full_name, reply_to, email_address, index, signature
29 * @return array full_name,reply_to,email_address,index,signature
32 function get_identities() {
34 global $username, $data_dir, $domain;
36 $em = getPref($data_dir,$username,'email_address');
38 if (strpos($username , '@') == false) {
39 $em = $username.'@'.$domain;
44 $identities = array();
45 /* We always have this one, even if the user doesn't use multiple identities */
46 $identities[] = array('full_name' => getPref($data_dir,$username,'full_name'),
47 'email_address' => $em,
48 'reply_to' => getPref($data_dir,$username,'reply_to'),
49 'signature' => getSig($data_dir,$username,'g'),
52 $num_ids = getPref($data_dir,$username,'identities');
53 /* If there are any others, add them to the array */
54 if (!empty($num_ids) && $num_ids > 1) {
55 for ($i=1;$i<$num_ids;$i++
) {
56 $identities[] = array('full_name' => getPref($data_dir,$username,'full_name' . $i),
57 'email_address' => getPref($data_dir,$username,'email_address' . $i),
58 'reply_to' => getPref($data_dir,$username,'reply_to' . $i),
59 'signature' => getSig($data_dir,$username,$i),
68 * Function to save the identities array
70 * @param array $identities Array of identities
71 * @since 1.5.1 and 1.4.5
73 function save_identities($identities) {
75 global $username, $data_dir, $domain;
77 if (empty($identities) ||
!is_array($identities)) {
82 $num_cur = getPref($data_dir, $username, 'identities');
84 $cnt = count($identities);
86 // Remove any additional identities in prefs //
87 for($i=$cnt; $i <= $num_cur; $i++
) {
88 removePref($data_dir, $username, 'full_name' . $i);
89 removePref($data_dir, $username, 'email_address' . $i);
90 removePref($data_dir, $username, 'reply_to' . $i);
91 setSig($data_dir, $username, $i, '');
94 foreach($identities as $id=>$ident) {
98 setPref($data_dir, $username, 'full_name' . $key, $ident['full_name']);
99 setPref($data_dir, $username, 'email_address' . $key, $ident['email_address']);
100 setPref($data_dir, $username, 'reply_to' . $key, $ident['reply_to']);
103 setSig($data_dir, $username, 'g', $ident['signature']);
105 setSig($data_dir, $username, $key, $ident['signature']);
110 setPref($data_dir, $username, 'identities', $cnt);
115 * Returns an array with a fixed set of identities
117 * @param array $identities Array of identities
118 * @param int $id Identity to modify
119 * @param string $action Action to perform
121 * @since 1.5.1 and 1.4.5
123 function sqfixidentities( $identities, $id, $action ) {
129 if (empty($identities) ||
!is_array($identities)) {
133 foreach( $identities as $key=>$ident ) {
135 if (empty_identity($ident)) {
146 // inform plugins about renumbering of ids
147 do_hook('options_identities_renumber', $id, 'default');
151 $fixed[$i+
1] = $ident;
157 if ($key == ($id - 1)) {
160 // inform plugins about renumbering of ids
161 do_hook('options_identities_renumber', $id , $id - 1);
169 $fixed[$i] = $tmp_hold;
177 // inform plugins about deleted id
178 do_hook('options_identities_process', $action, $id);
186 // Process actions from plugins and save/update action //
189 * send action and id information. number of hook arguments
190 * differs from 1.4.4 or older and 1.5.0. count($args) can
191 * be used to detect modified hook. Older hook does not
192 * provide information that can be useful for plugins.
194 do_hook('options_identities_process', $action, $id);
200 // Inc array index //
210 * Function to test if identity is empty
212 * @param array $identity Identitiy Array
214 * @since 1.5.1 and 1.4.5
216 function empty_identity($ident) {
217 if (empty($ident['full_name']) && empty($ident['email_address']) && empty($ident['signature']) && empty($ident['reply_to'])) {