X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=functions%2Fidentity.php;h=b2b82177321ae72d1ceccb3d2e6de3dbf3a0b459;hp=17215555da88ccf1dfafa2d6fb5bbc5a98a0f0f2;hb=40e071367219a08de46bf1ed3993180030adc9c9;hpb=1d6248ce00d0564f0508e7744490f27c30052af0 diff --git a/functions/identity.php b/functions/identity.php index 17215555..b2b82177 100644 --- a/functions/identity.php +++ b/functions/identity.php @@ -3,25 +3,15 @@ /** * identity.php * - * Copyright (c) 1999-2005 The SquirrelMail Project Team - * Licensed under the GNU GPL. For full terms see the file COPYING. - * * This contains utility functions for dealing with multiple identities * + * @copyright © 1999-2007 The SquirrelMail Project Team + * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version $Id$ * @package squirrelmail * @since 1.4.2 */ -/** Used to simplify includes - * @ignore - */ -if (!defined('SM_PATH')) { - define('SM_PATH','../'); -} - -/** preference and signature functions */ -include_once(SM_PATH . 'include/load_prefs.php'); /** * Returns an array of all the identities. @@ -53,8 +43,9 @@ function get_identities() { /* If there are any others, add them to the array */ if (!empty($num_ids) && $num_ids > 1) { for ($i=1;$i<$num_ids;$i++) { + $thisem = getPref($data_dir,$username,'email_address' . $i); $identities[] = array('full_name' => getPref($data_dir,$username,'full_name' . $i), - 'email_address' => getPref($data_dir,$username,'email_address' . $i), + 'email_address' => empty($thisem)?$em:$thisem, 'reply_to' => getPref($data_dir,$username,'reply_to' . $i), 'signature' => getSig($data_dir,$username,$i), 'index' => $i ); @@ -80,7 +71,7 @@ function save_identities($identities) { $num_cur = getPref($data_dir, $username, 'identities'); - + $cnt = count($identities); // Remove any additional identities in prefs // @@ -144,7 +135,7 @@ function sqfixidentities( $identities, $id, $action ) { $fixed[0] = $ident; // inform plugins about renumbering of ids - do_hook('options_identities_renumber', $id, 'default'); + do_hook('options_identities_renumber', $temp=array(&$id, 'default')); continue 2; } else { @@ -158,7 +149,7 @@ function sqfixidentities( $identities, $id, $action ) { $tmp_hold = $ident; // inform plugins about renumbering of ids - do_hook('options_identities_renumber', $id , $id - 1); + do_hook('options_identities_renumber', $temp=array(&$id , $id - 1)); continue 2; } else { @@ -175,7 +166,7 @@ function sqfixidentities( $identities, $id, $action ) { if ($key == $id) { // inform plugins about deleted id - do_hook('options_identities_process', $action, $id); + do_hook('options_identities_process', $temp=array(&$action, &$id)); continue 2; } else { @@ -186,12 +177,12 @@ function sqfixidentities( $identities, $id, $action ) { // Process actions from plugins and save/update action // default: /** - * send action and id information. number of hook arguments - * differs from 1.4.4 or older and 1.5.0. count($args) can - * be used to detect modified hook. Older hook does not + * send action and id information. number of hook arguments + * differs from 1.4.4 or older and 1.5.0. count($args) can + * be used to detect modified hook. Older hook does not * provide information that can be useful for plugins. */ - do_hook('options_identities_process', $action, $id); + do_hook('options_identities_process', $temp=array(&$action, &$id)); $fixed[$i] = $ident; @@ -221,4 +212,56 @@ function empty_identity($ident) { } } -?> \ No newline at end of file +/** + * Construct our "From:" header based on + * a supplied identity number. + * Will fall back when no sensible email address has been defined. + * + * @param int $identity identity# to use + * @since 1.5.2 + */ +function build_from_header($identity = 0) { + $idents = get_identities(); + + if (! isset($idents[$identity]) ) $identity = 0; + + if ( !empty($idents[$identity]['full_name']) ) { + $from_name = $idents[$identity]['full_name']; + } + + $from_mail = $idents[$identity]['email_address']; + + if ( isset($from_name) ) { + $from_name_encoded = encodeHeader($from_name); + if ($from_name_encoded != $from_name) { + return $from_name_encoded .' <'.$from_mail.'>'; + } + return '"'.$from_name .'" <'.$from_mail.'>'; + } + return $from_mail; +} + +/** + * Find a matching identity based on a set of emailaddresses. + * Will return the first identity to have a matching address. + * When nothing found, returns the default identity. + * + * @param needles array list of mailadresses + * @returns int identity + * @since 1.5.2 + */ +function find_identity($needles) { + $idents = get_identities(); + if ( count($idents) == 1 || empty($needles) ) return 0; + + foreach ( $idents as $nr => $ident ) { + if ( isset($ident['email_address']) ) { + foreach ( $needles as $needle ) { + if ( $needle == $ident['email_address'] ) { + return $nr; + } + } + } + } + return 0; +}