fb90144e67cab522dc2552b0aeb11cec02bcb690
6 * This contains utility functions for dealing with multiple identities
8 * @copyright © 1999-2006 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @package squirrelmail
15 /** Used to simplify includes
18 if (!defined('SM_PATH')) {
19 define('SM_PATH','../');
22 /** preference and signature functions */
23 include_once(SM_PATH
. 'include/load_prefs.php');
26 * Returns an array of all the identities.
27 * Array is keyed: full_name, reply_to, email_address, index, signature
28 * @return array full_name,reply_to,email_address,index,signature
31 function get_identities() {
33 global $username, $data_dir, $domain;
35 $em = getPref($data_dir,$username,'email_address');
37 if (strpos($username , '@') == false) {
38 $em = $username.'@'.$domain;
43 $identities = array();
44 /* We always have this one, even if the user doesn't use multiple identities */
45 $identities[] = array('full_name' => getPref($data_dir,$username,'full_name'),
46 'email_address' => $em,
47 'reply_to' => getPref($data_dir,$username,'reply_to'),
48 'signature' => getSig($data_dir,$username,'g'),
51 $num_ids = getPref($data_dir,$username,'identities');
52 /* If there are any others, add them to the array */
53 if (!empty($num_ids) && $num_ids > 1) {
54 for ($i=1;$i<$num_ids;$i++
) {
55 $identities[] = array('full_name' => getPref($data_dir,$username,'full_name' . $i),
56 'email_address' => getPref($data_dir,$username,'email_address' . $i),
57 'reply_to' => getPref($data_dir,$username,'reply_to' . $i),
58 'signature' => getSig($data_dir,$username,$i),
67 * Function to save the identities array
69 * @param array $identities Array of identities
70 * @since 1.5.1 and 1.4.5
72 function save_identities($identities) {
74 global $username, $data_dir, $domain;
76 if (empty($identities) ||
!is_array($identities)) {
81 $num_cur = getPref($data_dir, $username, 'identities');
83 $cnt = count($identities);
85 // Remove any additional identities in prefs //
86 for($i=$cnt; $i <= $num_cur; $i++
) {
87 removePref($data_dir, $username, 'full_name' . $i);
88 removePref($data_dir, $username, 'email_address' . $i);
89 removePref($data_dir, $username, 'reply_to' . $i);
90 setSig($data_dir, $username, $i, '');
93 foreach($identities as $id=>$ident) {
97 setPref($data_dir, $username, 'full_name' . $key, $ident['full_name']);
98 setPref($data_dir, $username, 'email_address' . $key, $ident['email_address']);
99 setPref($data_dir, $username, 'reply_to' . $key, $ident['reply_to']);
102 setSig($data_dir, $username, 'g', $ident['signature']);
104 setSig($data_dir, $username, $key, $ident['signature']);
109 setPref($data_dir, $username, 'identities', $cnt);
114 * Returns an array with a fixed set of identities
116 * @param array $identities Array of identities
117 * @param int $id Identity to modify
118 * @param string $action Action to perform
120 * @since 1.5.1 and 1.4.5
122 function sqfixidentities( $identities, $id, $action ) {
128 if (empty($identities) ||
!is_array($identities)) {
132 foreach( $identities as $key=>$ident ) {
134 if (empty_identity($ident)) {
145 // inform plugins about renumbering of ids
146 do_hook('options_identities_renumber', $id, 'default');
150 $fixed[$i+
1] = $ident;
156 if ($key == ($id - 1)) {
159 // inform plugins about renumbering of ids
160 do_hook('options_identities_renumber', $id , $id - 1);
168 $fixed[$i] = $tmp_hold;
176 // inform plugins about deleted id
177 do_hook('options_identities_process', $action, $id);
185 // Process actions from plugins and save/update action //
188 * send action and id information. number of hook arguments
189 * differs from 1.4.4 or older and 1.5.0. count($args) can
190 * be used to detect modified hook. Older hook does not
191 * provide information that can be useful for plugins.
193 do_hook('options_identities_process', $action, $id);
199 // Inc array index //
209 * Function to test if identity is empty
211 * @param array $identity Identitiy Array
213 * @since 1.5.1 and 1.4.5
215 function empty_identity($ident) {
216 if (empty($ident['full_name']) && empty($ident['email_address']) && empty($ident['signature']) && empty($ident['reply_to'])) {