Source for file identity.php

Documentation is available at identity.php

  1. <?php
  2. /**
  3. * identity.php
  4. *
  5. * This contains utility functions for dealing with multiple identities
  6. *
  7. * @copyright 1999-2020 The SquirrelMail Project Team
  8. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  9. * @version $Id: identity.php 14840 2020年01月07日 07:42:38Z pdontthink $
  10. * @package squirrelmail
  11. * @since 1.4.2
  12. */
  13. /** Used to simplify includes */
  14. if (!defined ('SM_PATH')) {
  15. define ('SM_PATH','../');
  16. }
  17. include_once(SM_PATH . 'include/load_prefs.php');
  18. /**
  19. * Returns an array of all the identities.
  20. * Array is keyed: full_name, reply_to, email_address, index, signature
  21. * @return array full_name,reply_to,email_address,index,signature
  22. */
  23. function get_identities () {
  24. global $username, $data_dir , $domain ;
  25. $em = getPref ($data_dir,$username,'email_address');
  26. if ( ! $em ) {
  27. if (strpos ($username , '@') == false) {
  28. $em = $username.'@'.$domain;
  29. } else {
  30. $em = $username;
  31. }
  32. }
  33. $identities = array();
  34. /* We always have this one, even if the user doesn't use multiple identities */
  35. $identities[] = array('full_name' => getPref ($data_dir,$username,'full_name'),
  36. 'email_address' => $em,
  37. 'reply_to' => getPref ($data_dir,$username,'reply_to'),
  38. 'signature' => getSig ($data_dir,$username,'g'),
  39. 'index' => 0 );
  40. $num_ids = getPref ($data_dir,$username,'identities');
  41. /* If there are any others, add them to the array */
  42. if (!empty($num_ids) && $num_ids > 1) {
  43. for ($i=1;$i<$num_ids;$i++) {
  44. $identities[] = array('full_name' => getPref ($data_dir,$username,'full_name' . $i),
  45. 'email_address' => getPref ($data_dir,$username,'email_address' . $i),
  46. 'reply_to' => getPref ($data_dir,$username,'reply_to' . $i),
  47. 'signature' => getSig ($data_dir,$username,$i),
  48. 'index' => $i );
  49. }
  50. }
  51. return $identities;
  52. }
  53. /**
  54. * Function to save the identities array
  55. *
  56. * @param array $identities Array of identities
  57. */
  58. function save_identities ($identities) {
  59. global $username, $data_dir ;
  60. if (empty($identities) || !is_array ($identities)) {
  61. return;
  62. }
  63. $num_cur = getPref ($data_dir, $username, 'identities', 0);
  64. $cnt = count ($identities);
  65. // Remove any additional identities in prefs //
  66. for($i=$cnt; $i <= $num_cur; $i++) {
  67. removePref ($data_dir, $username, 'full_name' . $i);
  68. removePref ($data_dir, $username, 'email_address' . $i);
  69. removePref ($data_dir, $username, 'reply_to' . $i);
  70. setSig ($data_dir, $username, $i, '');
  71. }
  72. foreach($identities as $id=>$ident) {
  73. $key = ($id?$id:'');
  74. setPref ($data_dir, $username, 'full_name' . $key, $ident['full_name']);
  75. setPref ($data_dir, $username, 'email_address' . $key, $ident['email_address']);
  76. setPref ($data_dir, $username, 'reply_to' . $key, $ident['reply_to']);
  77. if ($id === 0) {
  78. setSig ($data_dir, $username, 'g', $ident['signature']);
  79. } else {
  80. setSig ($data_dir, $username, $key, $ident['signature']);
  81. }
  82. }
  83. setPref ($data_dir, $username, 'identities', $cnt);
  84. }
  85. /**
  86. * Returns an array with a fixed set of identities
  87. *
  88. * @param array $identities Array of identities
  89. * @param int $id Identity to modify
  90. * @param string $action Action to perform
  91. * @param boolean $override_edit_identity For use by plugins
  92. * where the incoming
  93. * identities array is
  94. * trusted (OPTIONAL;
  95. * default FALSE)
  96. * @return array
  97. */
  98. function sqfixidentities ( $identities, $id, $action, $override_edit_identity=FALSE ) {
  99. global $edit_identity, $data_dir , $username,
  100. $edit_name, $edit_reply_to ;
  101. $num_cur = (int)getPref ($data_dir, $username, 'identities', 0);
  102. $fixed = array();
  103. $tmp_hold = array();
  104. $i = 0;
  105. if (empty($identities) || !is_array ($identities)) {
  106. return $fixed;
  107. }
  108. if ($override_edit_identity)
  109. $edit_identity_local = TRUE;
  110. else
  111. $edit_identity_local = $edit_identity;
  112. // NOTE that $identities is untrusted user input at this point
  113. // make sure no one is being sneaky trying to add identities when they shouldn't
  114. if (!$edit_identity_local && $num_cur !== count ($identities)) {
  115. exit;
  116. }
  117. // only allow growing the identities list if action is "save" and the last ident is populated
  118. // (the input form always has a blank set of inputs for adding a new identity)
  119. // (but we assume when $override_edit_identities is used, a plugin is not passing in the
  120. // identities array with a blank element on the end)
  121. if (!$override_edit_identity && $edit_identity_local
  122. && ($action !== 'save' || empty_identity (end ($identities)))) {
  123. array_pop ($identities);
  124. }
  125. // make sure someone not trying to mess with index numbers
  126. for ($x = 0; $x < $num_cur ; $x++) { // there could be one more when adding but that's ok
  127. if (!isset($identities[$x]))
  128. exit;
  129. }
  130. foreach( $identities as $key=>$ident ) {
  131. if ($edit_identity_local && empty_identity ($ident)) {
  132. continue;
  133. }
  134. // when user isn't allowed to edit some fields, make sure they are unchanged
  135. $pref_index = ($key ? $key : '');
  136. if (!$edit_identity_local && !$edit_name)
  137. $ident['full_name'] = getPref ($data_dir, $username, 'full_name' . $pref_index);
  138. if (!$edit_identity_local)
  139. $ident['email_address'] = getPref ($data_dir, $username, 'email_address' . $pref_index);
  140. if (!$edit_identity_local && !$edit_reply_to)
  141. $ident['reply_to'] = getPref ($data_dir, $username, 'reply_to' . $pref_index);
  142. switch($action) {
  143. case 'makedefault':
  144. // can only get here if someone is trying to be sneaky
  145. if ($num_cur < 2) exit;
  146. if ($key == $id) {
  147. $fixed[0] = $ident;
  148. // inform plugins about renumbering of ids
  149. do_hook ('options_identities_renumber', $id, 'default');
  150. continue 2;
  151. } else {
  152. $fixed[$i+1] = $ident;
  153. }
  154. break;
  155. case 'move':
  156. // can only get here if someone is trying to be sneaky
  157. if ($num_cur < 2) exit;
  158. if ($key == ($id - 1)) {
  159. $tmp_hold = $ident;
  160. // inform plugins about renumbering of ids
  161. do_hook ('options_identities_renumber', $id , $id - 1);
  162. continue 2;
  163. } else {
  164. $fixed[$i] = $ident;
  165. if ($key == $id) {
  166. $i++;
  167. $fixed[$i] = $tmp_hold;
  168. }
  169. }
  170. break;
  171. case 'delete':
  172. // can only get here if someone is trying to be sneaky
  173. if (!$edit_identity_local) exit;
  174. if ($key == $id) {
  175. // inform plugins about deleted id
  176. do_hook ('options_identities_process', $action, $id);
  177. continue 2;
  178. } else {
  179. $fixed[$i] = $ident;
  180. }
  181. break;
  182. // Process actions from plugins and save/update action //
  183. default:
  184. /**
  185. * send action and id information. number of hook arguments
  186. * differs from 1.4.4 or older and 1.5.0. count($args) can
  187. * be used to detect modified hook. Older hook does not
  188. * provide information that can be useful for plugins.
  189. */
  190. do_hook ('options_identities_process', $action, $id);
  191. $fixed[$i] = $ident;
  192. }
  193. // Inc array index //
  194. $i++;
  195. }
  196. ksort ($fixed);
  197. return $fixed;
  198. }
  199. /**
  200. * Function to test if identity is empty
  201. *
  202. * @param array $identity Identity Array
  203. * @return boolean
  204. */
  205. function empty_identity ($ident) {
  206. if (empty($ident['full_name']) && empty($ident['email_address']) && empty($ident['signature']) && empty($ident['reply_to'])) {
  207. return true;
  208. } else {
  209. return false;
  210. }
  211. }

Documentation generated on 2020年1月13日 04:24:43 +0100 by phpDocumentor 1.4.3

AltStyle によって変換されたページ (->オリジナル) /