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
15 /** Used to simplify includes */
16 if (!defined('SM_PATH')) {
17 define('SM_PATH','../');
20 include_once(SM_PATH
. 'include/load_prefs.php');
23 * Returns an array of all the identities.
24 * Array is keyed: full_name, reply_to, email_address, index, signature
25 * @return array full_name,reply_to,email_address,index,signature
27 function get_identities() {
29 global $username, $data_dir, $domain;
31 $em = getPref($data_dir,$username,'email_address');
33 if (strpos($username , '@') == false) {
34 $em = $username.'@'.$domain;
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'),
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),
63 * Function to save the identities array
65 * @param array $identities Array of identities
67 function save_identities($identities) {
69 global $username, $data_dir, $domain;
71 if (empty($identities) ||
!is_array($identities)) {
76 $num_cur = getPref($data_dir, $username, 'identities');
78 $cnt = count($identities);
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, '');
88 foreach($identities as $id=>$ident) {
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']);
97 setSig($data_dir, $username, 'g', $ident['signature']);
99 setSig($data_dir, $username, $key, $ident['signature']);
104 setPref($data_dir, $username, 'identities', $cnt);
109 * Returns an array with a fixed set of identities
111 * @param array $identities Array of identities
112 * @param int $id Identity to modify
113 * @param string $action Action to perform
116 function sqfixidentities( $identities, $id, $action ) {
122 if (empty($identities) ||
!is_array($identities)) {
126 foreach( $identities as $key=>$ident ) {
128 if (empty_identity($ident)) {
140 $fixed[$i+
1] = $ident;
146 if ($key == ($id - 1)) {
154 $fixed[$i] = $tmp_hold;
168 // we should never hit this but just in case //
174 // Inc array index //
184 * Function to test if identity is empty
186 * @param array $identity Identitiy Array
189 function empty_identity($ident) {
190 if (empty($ident['full_name']) && empty($ident['email_address']) && empty($ident['signature']) && empty($ident['reply_to'])) {