Source for file identity.php

Documentation is available at identity.php

  1. <?php
  2.  
  3. /**
  4.  * identity.php
  5.  *
  6.  * This contains utility functions for dealing with multiple identities
  7.  *
  8.  * @copyright &copy; 1999-2006 The SquirrelMail Project Team
  9.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10.  * @version $Id: identity.php,v 1.4.4.12 2006/04/14 22:27:07 jervfors Exp $
  11.  * @package squirrelmail
  12.  * @since 1.4.2
  13.  */
  14.  
  15. /** Used to simplify includes */
  16. if (!defined('SM_PATH')) {
  17.     define('SM_PATH','../');
  18. }
  19.  
  20. include_once(SM_PATH 'include/load_prefs.php');
  21.  
  22. /**
  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
  26. */
  27. function get_identities({
  28.  
  29.     global $username$data_dir$domain;
  30.  
  31.     $em getPref($data_dir,$username,'email_address');
  32.     if $em {
  33.         if (strpos($username '@'== false{
  34.             $em $username.'@'.$domain;
  35.         else {
  36.             $em $username;
  37.         }
  38.     }
  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'),
  45.         'index' => );
  46.  
  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),
  55.             'index' => $i );
  56.         }
  57.     }
  58.  
  59.     return $identities;
  60. }
  61.  
  62. /**
  63.  * Function to save the identities array
  64.  *
  65.  * @param  array     $identities     Array of identities
  66.  */
  67. function save_identities($identities{
  68.  
  69.     global $username$data_dir$domain;
  70.  
  71.     if (empty($identities|| !is_array($identities)) {
  72.         return;
  73.     }
  74.  
  75.  
  76.     $num_cur getPref($data_dir$username'identities');
  77.     
  78.     $cnt count($identities);
  79.  
  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'');
  86.     }
  87.  
  88.     foreach($identities as $id=>$ident{
  89.  
  90.         $key ($id?$id:'');
  91.  
  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']);
  95.  
  96.         if ($id === 0{
  97.             setSig($data_dir$username'g'$ident['signature']);
  98.         else {
  99.             setSig($data_dir$username$key$ident['signature']);
  100.         }
  101.  
  102.     }
  103.  
  104.     setPref($data_dir$username'identities'$cnt);
  105.  
  106. }
  107.  
  108. /**
  109.  * Returns an array with a fixed set of identities
  110.  *
  111.  * @param   array       $identities      Array of identities
  112.  * @param   int         $id             Identity to modify
  113.  * @param   string      $action         Action to perform
  114.  * @return  array 
  115.  */
  116. function sqfixidentities$identities$id$action {
  117.  
  118.     $fixed array();
  119.     $tmp_hold array();
  120.     $i 0;
  121.  
  122.     if (empty($identities|| !is_array($identities)) {
  123.         return $fixed;
  124.     }
  125.  
  126.     foreach$identities as $key=>$ident {
  127.  
  128.         if (empty_identity($ident)) {
  129.             continue;
  130.         }
  131.  
  132.         switch($action{
  133.  
  134.             case 'makedefault':
  135.  
  136.                 if ($key == $id{
  137.                     $fixed[0$ident;
  138.  
  139.                     // inform plugins about renumbering of ids
  140.                     do_hook('options_identities_renumber'$id'default');
  141.  
  142.                     continue 2;
  143.                 else {
  144.                     $fixed[$i+1$ident;
  145.                 }
  146.                 break;
  147.  
  148.             case 'move':
  149.  
  150.                 if ($key == ($id 1)) {
  151.                     $tmp_hold $ident;
  152.  
  153.                     // inform plugins about renumbering of ids
  154.                     do_hook('options_identities_renumber'$id $id 1);
  155.  
  156.                     continue 2;
  157.                 else {
  158.                     $fixed[$i$ident;
  159.  
  160.                     if ($key == $id{
  161.                         $i++;
  162.                         $fixed[$i$tmp_hold;
  163.                     }
  164.                 }
  165.                 break;
  166.  
  167.             case 'delete':
  168.  
  169.                 if ($key == $id{
  170.                     // inform plugins about deleted id
  171.                     do_hook('options_identities_process'$action$id);
  172.  
  173.                     continue 2;
  174.                 else {
  175.                     $fixed[$i$ident;
  176.                 }
  177.                 break;
  178.  
  179.             // Process actions from plugins and save/update action //
  180.             default:
  181.                 /**
  182.                  * send action and id information. number of hook arguments 
  183.                  * differs from 1.4.4 or older and 1.5.0. count($args) can 
  184.                  * be used to detect modified hook. Older hook does not 
  185.                  * provide information that can be useful for plugins.
  186.                  */
  187.                 do_hook('options_identities_process'$action$id);
  188.  
  189.                 $fixed[$i$ident;
  190.  
  191.         }
  192.  
  193.         // Inc array index //
  194.         $i++;
  195.     }
  196.  
  197.     ksort($fixed);
  198.     return $fixed;
  199.  
  200. }
  201.  
  202. /**
  203.  * Function to test if identity is empty
  204.  *
  205.  * @param   array   $identity   Identitiy Array
  206.  * @return  boolean 
  207.  */
  208. function empty_identity($ident{
  209.     if (empty($ident['full_name']&& empty($ident['email_address']&& empty($ident['signature']&& empty($ident['reply_to'])) {
  210.         return true;
  211.     else {
  212.         return false;
  213.     }
  214. }
  215.  
  216. ?>

Documentation generated on Sat, 07 Oct 2006 16:31:35 +0300 by phpDocumentor 1.3.0RC6