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
17 * 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)) {
146 $fixed[$i+
1] = $ident;
152 if ($key == ($id - 1)) {
160 $fixed[$i] = $tmp_hold;
174 // we should never hit this but just in case //
180 // Inc array index //
190 * Function to test if identity is empty
192 * @param array $identity Identitiy Array
194 * @since 1.5.1 and 1.4.5
196 function empty_identity($ident) {
197 if (empty($ident['full_name']) && empty($ident['email_address']) && empty($ident['signature']) && empty($ident['reply_to'])) {