/* 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 );
return false;
}
}
+
+/**
+ * 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;
+}
$mailprio = '';
}
- $identity = '';
$from_o = $orig_header->from;
if (is_array($from_o)) {
if (isset($from_o[0])) {
$send_from_parts = new AddressStructure();
$send_from_parts = $orig_header->parseAddress($send_from);
$send_from_add = $send_from_parts->mailbox . '@' . $send_from_parts->host;
- $identities = get_identities();
- if (count($identities) > 0) {
- foreach($identities as $iddata) {
- if ($send_from_add == $iddata['email_address']) {
- $identity = $iddata['index'];
- break;
- }
- }
- }
+ $identity = find_identity(array($send_from_add));
$subject = decodeHeader($orig_header->subject,false,false,true);
// Remember the receipt settings
*/
function deliverMessage($composeMessage, $draft=false) {
global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body,
- $username, $popuser, $usernamedata, $identity, $idents, $data_dir,
+ $username, $identity, $idents, $data_dir,
$request_mdn, $request_dr, $default_charset, $color, $useSendmail,
$domain, $action, $default_move_to_sent, $move_to_sent;
global $imapServerAddress, $imapPort, $sent_folder, $key;
}
$composeMessage->setBody($body);
- if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
- $popuser = $usernamedata[1];
- $domain = $usernamedata[2];
- unset($usernamedata);
- } else {
- $popuser = $username;
- }
$reply_to = '';
- $from_mail = $idents[$identity]['email_address'];
- $full_name = $idents[$identity]['full_name'];
$reply_to = $idents[$identity]['reply_to'];
- if (!$from_mail) {
- $from_mail = "$popuser@$domain";
- }
- $rfc822_header->from = $rfc822_header->parseAddress($from_mail,true);
- if ($full_name) {
- $from = $rfc822_header->from[0];
- if (!$from->host) $from->host = $domain;
- $full_name_encoded = encodeHeader($full_name);
- if ($full_name_encoded != $full_name) {
- $from_addr = $full_name_encoded .' <'.$from->mailbox.'@'.$from->host.'>';
- } else {
- $from_addr = '"'.$full_name .'" <'.$from->mailbox.'@'.$from->host.'>';
- }
- $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true);
- }
+
+ $from_addr = build_from_header($identity);
+ $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true);
if ($reply_to) {
$rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true);
}
/* Receipt: On Read */
if (isset($request_mdn) && $request_mdn) {
- $rfc822_header->dnt = $rfc822_header->parseAddress($from_mail,true);
+ $rfc822_header->dnt = $rfc822_header->parseAddress($from_addr,true);
} elseif (isset($rfc822_header->dnt)) {
unset($rfc822_header->dnt);
}
/* Receipt: On Delivery */
if (isset($request_dr) && $request_dr) {
- $rfc822_header->more_headers['Return-Receipt-To'] = $from_mail;
+ $rfc822_header->more_headers['Return-Receipt-To'] = $from->mailbox.'@'.$from->domain;
} elseif (isset($rfc822_header->more_headers['Return-Receipt-To'])) {
unset($rfc822_header->more_headers['Return-Receipt-To']);
}
in_array('\\*',$aFlags,true) ) ;
}
-function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) {
- global $username, $attachment_dir, $popuser, $username, $color,
+function SendMDN ( $mailbox, $passed_id, $message, $imapConnection) {
+ global $username, $attachment_dir, $color,
$squirrelmail_language, $default_charset,
$languages, $useSendmail, $domain, $sent_folder;
$rfc822_header->to[] = $header->dnt;
$rfc822_header->subject = _("Read:") . ' ' . encodeHeader($header->subject);
- // Patch #793504 Return Receipt Failing with <@> from Tim Craig (burny_md)
- // This merely comes from compose.php and only happens when there is no
- // email_addr specified in user's identity (which is the startup config)
- if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
- $popuser = $usernamedata[1];
- $domain = $usernamedata[2];
- unset($usernamedata);
- } else {
- $popuser = $username;
+ $idents = get_identities();
+ $needles = array();
+ if ($header->to) {
+ foreach ($header->to as $message_to) {
+ $needles[] = $message_to->mailbox.'@'.$message_to->host;
+ }
}
+ $identity = find_identity($needles);
+ $from_addr = build_from_header($identity);
+ $reply_to = isset($idents[$identity]['reply_to']) ? $idents[$identity]['reply_to'] : '';
+ // FIXME: this must actually be the envelope address of the orginal message,
+ // but do we have that information? For now the first identity is our best guess.
+ $final_recipient = $idents[0]['email_address'];
- $reply_to = '';
- $ident = get_identities();
- if(!isset($identity)) $identity = 0;
- $full_name = $ident[$identity]['full_name'];
- $from_mail = $ident[$identity]['email_address'];
- $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
- $reply_to = $ident[$identity]['reply_to'];
-
- if (!$from_mail) {
- $from_mail = "$popuser@$domain";
- $from_addr = $from_mail;
- }
$rfc822_header->from = $rfc822_header->parseAddress($from_addr,true);
if ($reply_to) {
$rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true);
if ($original_recipient != '') {
$report .= "Original-Recipient : $original_recipient\r\n";
}
- $final_recipient = $sender;
$report .= "Final-Recipient: rfc822; $final_recipient\r\n" .
"Original-Message-ID : $original_message_id\r\n" .
"Disposition: manual-action/MDN-sent-manually; displayed\r\n";
if (isset($sendreceipt)) {
if ( !$message->is_mdnsent ) {
- $final_recipient = '';
- if ((isset($identity)) && ($identity != 0)) //Main identity
- $final_recipient = trim(getPref($data_dir, $username, 'email_address' . $identity, '' ));
- if ($final_recipient == '' )
- $final_recipient = trim(getPref($data_dir, $username, 'email_address', '' ));
$supportMDN = ServerMDNSupport($aMailbox["PERMANENTFLAGS"]);
- if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
+ if ( SendMDN( $mailbox, $passed_id, $message, $imapConnection ) > 0 && $supportMDN ) {
ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id);
$message->is_mdnsent = true;
$aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'] = $message;