* Mail: import and display of mails failed, if personal part of addresses contains valid encoded utf-8 characters

- using now Horde_Mime_Headers::parseHeaders() for headers instead of Mail_mimeDecode, which should be completly replaced with Horde_Mime_Part::parseMessage()
- replaced imap_rfc822_parse_adrlist with Horde_Mail_Rfc822::parseAddressList() using static wrapper emailadmin_imapbase::parseAddressList()
This commit is contained in:
Ralf Becker 2014-10-18 16:30:39 +00:00
parent 93bc0feb16
commit 64aa838e9d
2 changed files with 47 additions and 99 deletions

View File

@ -471,9 +471,8 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
$mailObject->MessageID = $message->headers['message-id'];
/* the client send garbage sometimes (blackberry->domain\username)
// from
$address_array = imap_rfc822_parse_adrlist((get_magic_quotes_gpc()?stripslashes($message->headers['from']):$message->headers['from']),'');
foreach((array)$address_array as $addressObject) {
if ($addressObject->host == '.SYNTAX-ERROR.') continue;
foreach(emailadmin_imapbase::parseAddressList((get_magic_quotes_gpc()?stripslashes($message->headers['from']):$message->headers['from'])) as $addressObject) {
if (!$addressObject->valid) continue;
if ($this->debugLevel>0) debugLog("Header Sentmail From: ".array2string($addressObject).' vs. '.array2string($message->headers['from']));
$mailObject->From = $addressObject->mailbox. (!empty($addressObject->host) ? '@'.$addressObject->host : '');
$mailObject->FromName = $addressObject->personal;
@ -481,39 +480,34 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
*/
// prepare addressee list; moved the adding of addresses to the mailobject down
// to
$address_array = imap_rfc822_parse_adrlist((get_magic_quotes_gpc()?stripslashes($message->headers["to"]):$message->headers["to"]),'');
foreach((array)$address_array as $addressObject) {
if ($addressObject->host == '.SYNTAX-ERROR.') continue;
foreach(emailadmin_imapbase::parseAddressList((get_magic_quotes_gpc()?stripslashes($message->headers["to"]):$message->headers["to"])) as $addressObject) {
if (!$addressObject->valid) continue;
if ($this->debugLevel>0) debugLog("Header Sentmail To: ".array2string($addressObject) );
//$mailObject->AddAddress($addressObject->mailbox. (!empty($addressObject->host) ? '@'.$addressObject->host : ''),$addressObject->personal);
$toMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
}
// CC
$address_array = imap_rfc822_parse_adrlist((get_magic_quotes_gpc()?stripslashes($message->headers["cc"]):$message->headers["cc"]),'');
foreach((array)$address_array as $addressObject) {
if ($addressObject->host == '.SYNTAX-ERROR.') continue;
foreach(emailadmin_imapbase::parseAddressList((get_magic_quotes_gpc()?stripslashes($message->headers["cc"]):$message->headers["cc"])) as $addressObject) {
if (!$addressObject->valid) continue;
if ($this->debugLevel>0) debugLog("Header Sentmail CC: ".array2string($addressObject) );
//$mailObject->AddCC($addressObject->mailbox. (!empty($addressObject->host) ? '@'.$addressObject->host : ''),$addressObject->personal);
$ccMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
}
// BCC
$address_array = imap_rfc822_parse_adrlist((get_magic_quotes_gpc()?stripslashes($message->headers["bcc"]):$message->headers["bcc"]),'');
foreach((array)$address_array as $addressObject) {
if ($addressObject->host == '.SYNTAX-ERROR.') continue;
foreach(emailadmin_imapbase::parseAddressList((get_magic_quotes_gpc()?stripslashes($message->headers["bcc"]):$message->headers["bcc"])) as $addressObject) {
if (!$addressObject->valid) continue;
if ($this->debugLevel>0) debugLog("Header Sentmail BCC: ".array2string($addressObject) );
//$mailObject->AddBCC($addressObject->mailbox. (!empty($addressObject->host) ? '@'.$addressObject->host : ''),$addressObject->personal);
$bccMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
}
/*
// AddReplyTo
$address_array = imap_rfc822_parse_adrlist((get_magic_quotes_gpc()?stripslashes($message->headers['reply-to']):$message->headers['reply-to']),'');
foreach((array)$address_array as $addressObject) {
if ($addressObject->host == '.SYNTAX-ERROR.') continue;
foreach(emailadmin_imapbase::parseAddressList((get_magic_quotes_gpc()?stripslashes($message->headers['reply-to']):$message->headers['reply-to'])) as $addressObject) {
if (!$addressObject->valid) continue;
if ($this->debugLevel>0) debugLog("Header Sentmail REPLY-TO: ".array2string($addressObject) );
$mailObject->AddReplyTo($addressObject->mailbox. (!empty($addressObject->host) ? '@'.$addressObject->host : ''),$addressObject->personal);
}
*/
$addedfullname = false;
// save some headers when forwarding mails (content type & transfer-encoding)
$headers = "";
@ -605,8 +599,7 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
$toCount = 0;
//error_log(__METHOD__.__LINE__.array2string($toMailAddr));
foreach((array)$toMailAddr as $address) {
$address_array = imap_rfc822_parse_adrlist((get_magic_quotes_gpc()?stripslashes($address):$address),'');
foreach((array)$address_array as $addressObject) {
foreach(emailadmin_imapbase::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
$emailAddress = $addressObject->mailbox. (!empty($addressObject->host) ? '@'.$addressObject->host : '');
if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress,(isset($cSMRMethod)?$cSMRMethod:'REQUEST'))) continue;
$mailObject->AddAddress($emailAddress, $addressObject->personal);
@ -615,8 +608,7 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
}
$ccCount = 0;
foreach((array)$ccMailAddr as $address) {
$address_array = imap_rfc822_parse_adrlist((get_magic_quotes_gpc()?stripslashes($address):$address),'');
foreach((array)$address_array as $addressObject) {
foreach(emailadmin_imapbase::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
$emailAddress = $addressObject->mailbox. (!empty($addressObject->host) ? '@'.$addressObject->host : '');
if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress)) continue;
$mailObject->AddCC($emailAddress, $addressObject->personal);
@ -625,8 +617,7 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
}
$bccCount = 0;
foreach((array)$bccMailAddr as $address) {
$address_array = imap_rfc822_parse_adrlist((get_magic_quotes_gpc()?stripslashes($address):$address),'');
foreach((array)$address_array as $addressObject) {
foreach(emailadmin_imapbase::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
$emailAddress = $addressObject->mailbox. (!empty($addressObject->host) ? '@'.$addressObject->host : '');
if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress)) continue;
$mailObject->AddBCC($emailAddress, $addressObject->personal);
@ -928,8 +919,7 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
}
if (count($folderArray) > 0) {
foreach((array)$bccMailAddr as $address) {
$address_array = imap_rfc822_parse_adrlist((get_magic_quotes_gpc()?stripslashes($address):$address),'');
foreach((array)$address_array as $addressObject) {
foreach(emailadmin_imapbase::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
$emailAddress = $addressObject->mailbox. (!empty($addressObject->host) ? '@'.$addressObject->host : '');
$mailAddr[] = array($emailAddress, $addressObject->personal);
}
@ -1122,33 +1112,29 @@ class mail_activesync implements activesync_plugin_write, activesync_plugin_send
$mailObject->Subject = $headers['SUBJECT'];
$mailObject->MessageID = $headers['MESSAGE-ID'];
// from
$address_array = imap_rfc822_parse_adrlist((get_magic_quotes_gpc()?stripslashes($headers['FROM']):$headers['FROM']),'');
foreach((array)$address_array as $addressObject) {
foreach(emailadmin_imapbase::parseAddressList((get_magic_quotes_gpc()?stripslashes($headers['FROM']):$headers['FROM'])) as $addressObject) {
//debugLog(__METHOD__.__LINE__.'Address to add (FROM):'.array2string($addressObject));
if ($addressObject->host == '.SYNTAX-ERROR.') continue;
if (!$addressObject->valid) continue;
$mailObject->From = $addressObject->mailbox. (!empty($addressObject->host) ? '@'.$addressObject->host : '');
$mailObject->FromName = $addressObject->personal;
//error_log(__METHOD__.__LINE__.'Address to add (FROM):'.array2string($addressObject));
}
// to
$address_array = imap_rfc822_parse_adrlist((get_magic_quotes_gpc()?stripslashes($headers['TO']):$headers['TO']),'');
foreach((array)$address_array as $addressObject) {
foreach(emailadmin_imapbase::parseAddressList((get_magic_quotes_gpc()?stripslashes($headers['TO']):$headers['TO'])) as $addressObject) {
//debugLog(__METHOD__.__LINE__.'Address to add (TO):'.array2string($addressObject));
if ($addressObject->host == '.SYNTAX-ERROR.') continue;
if (!$addressObject->valid) continue;
$mailObject->AddAddress($addressObject->mailbox. (!empty($addressObject->host) ? '@'.$addressObject->host : ''),$addressObject->personal);
}
// CC
$address_array = imap_rfc822_parse_adrlist((get_magic_quotes_gpc()?stripslashes($headers['CC']):$headers['CC']),'');
foreach((array)$address_array as $addressObject) {
foreach(emailadmin_imapbase::parseAddressList((get_magic_quotes_gpc()?stripslashes($headers['CC']):$headers['CC'])) as $addressObject) {
//debugLog(__METHOD__.__LINE__.'Address to add (CC):'.array2string($addressObject));
if ($addressObject->host == '.SYNTAX-ERROR.') continue;
if (!$addressObject->valid) continue;
$mailObject->AddCC($addressObject->mailbox. (!empty($addressObject->host) ? '@'.$addressObject->host : ''),$addressObject->personal);
}
// AddReplyTo
$address_array = imap_rfc822_parse_adrlist((get_magic_quotes_gpc()?stripslashes($headers['REPLY-TO']):$headers['REPLY-TO']),'');
foreach((array)$address_array as $addressObject) {
foreach(emailadmin_imapbase::parseAddressList((get_magic_quotes_gpc()?stripslashes($headers['REPLY-TO']):$headers['REPLY-TO'])) as $addressObject) {
//debugLog(__METHOD__.__LINE__.'Address to add (ReplyTO):'.array2string($addressObject));
if ($addressObject->host == '.SYNTAX-ERROR.') continue;
if (!$addressObject->valid) continue;
$mailObject->AddReplyTo($addressObject->mailbox. (!empty($addressObject->host) ? '@'.$addressObject->host : ''),$addressObject->personal);
}
$Header = $Body = ''; // we do not use Header and Body we use the MailObject

View File

@ -1140,9 +1140,7 @@ class mail_compose
//error_log(__METHOD__.__LINE__.array2string(array('key'=>$key,'value'=>$value)));
$value = htmlspecialchars_decode($value,ENT_COMPAT);
$value = str_replace("\"\"",'"',$value);
$address_array = imap_rfc822_parse_adrlist((get_magic_quotes_gpc()?stripslashes($value):$value), '');
//unset($content[strtolower($destination)]);
foreach((array)$address_array as $addressObject) {
foreach(emailadmin_imapbase::parseAddressList($value) as $addressObject) {
if ($addressObject->host == '.SYNTAX-ERROR.') continue;
$address = imap_rfc822_write_address($addressObject->mailbox,$addressObject->host,$addressObject->personal);
//$address = mail_bo::htmlentities($address, $this->displayCharset);
@ -1491,9 +1489,9 @@ class mail_compose
$this->sessionData['messageFolder'] = $_folder;
$this->sessionData['isDraft'] = true;
foreach((array)$headers['CC'] as $val) {
$rfcAddr=imap_rfc822_parse_adrlist($val, '');
$rfcAddr=emailadmin_imapbase::parseAddressList($val);
$_rfcAddr = $rfcAddr[0];
if ($_rfcAddr->host=='.SYNTAX-ERROR.') continue;
if (!$_rfcAddr->valid) continue;
if($_rfcAddr->mailbox == 'undisclosed-recipients' || (empty($_rfcAddr->mailbox) && empty($_rfcAddr->host)) ) {
continue;
}
@ -1512,9 +1510,9 @@ class mail_compose
$this->sessionData['to'][] = $val;
continue;
}
$rfcAddr=imap_rfc822_parse_adrlist($val, '');
$rfcAddr=emailadmin_imapbase::parseAddressList($val);
$_rfcAddr = $rfcAddr[0];
if ($_rfcAddr->host=='.SYNTAX-ERROR.') continue;
if (!$_rfcAddr->valid) continue;
if($_rfcAddr->mailbox == 'undisclosed-recipients' || (empty($_rfcAddr->mailbox) && empty($_rfcAddr->host)) ) {
continue;
}
@ -1528,9 +1526,9 @@ class mail_compose
}
foreach((array)$headers['REPLY-TO'] as $val) {
$rfcAddr=imap_rfc822_parse_adrlist($val, '');
$rfcAddr=emailadmin_imapbase::parseAddressList($val);
$_rfcAddr = $rfcAddr[0];
if ($_rfcAddr->host=='.SYNTAX-ERROR.') continue;
if (!$_rfcAddr->valid) continue;
if($_rfcAddr->mailbox == 'undisclosed-recipients' || (empty($_rfcAddr->mailbox) && empty($_rfcAddr->host)) ) {
continue;
}
@ -1544,9 +1542,9 @@ class mail_compose
}
foreach((array)$headers['BCC'] as $val) {
$rfcAddr=imap_rfc822_parse_adrlist($val, '');
$rfcAddr=emailadmin_imapbase::parseAddressList($val);
$_rfcAddr = $rfcAddr[0];
if ($_rfcAddr->host=='.SYNTAX-ERROR.') continue;
if (!$_rfcAddr->valid) continue;
if($_rfcAddr->mailbox == 'undisclosed-recipients' || (empty($_rfcAddr->mailbox) && empty($_rfcAddr->host)) ) {
continue;
}
@ -2153,56 +2151,22 @@ class mail_compose
}
// Expand any mailing lists
foreach(array('to','cc','bcc') as $field)
foreach(array(
'to' => 'AddAddress',
'cc' => 'AddCC',
'bcc' => 'AddBCC',
'replyto' => 'AddReplyto') as $field => $method)
{
$_formData[$field] = self::resolveEmailAddressList($_formData[$field]);
}
if ($field != 'replyto') $_formData[$field] = self::resolveEmailAddressList($_formData[$field]);
foreach((array)$_formData['to'] as $address) {
$address_array = imap_rfc822_parse_adrlist((get_magic_quotes_gpc()?stripslashes($address):$address), '');
foreach((array)$address_array as $addressObject) {
if ($addressObject->host == '.SYNTAX-ERROR.') continue;
$_emailAddress = $addressObject->mailbox. (!empty($addressObject->host) ? '@'.$addressObject->host : '');
$emailAddress = $addressObject->mailbox. (!empty($addressObject->host) ? '@'.$mail_bo->idna2->encode($addressObject->host) : '');
#$emailName = $mail_bo->encodeHeader($addressObject->personal, 'q');
#$_mailObject->AddAddress($emailAddress, $emailName);
$_mailObject->AddAddress($emailAddress, str_replace(array('@'),' ',($addressObject->personal?$addressObject->personal:$_emailAddress)));
}
}
foreach((array)$_formData['cc'] as $address) {
$address_array = imap_rfc822_parse_adrlist((get_magic_quotes_gpc()?stripslashes($address):$address),'');
foreach((array)$address_array as $addressObject) {
if ($addressObject->host == '.SYNTAX-ERROR.') continue;
$_emailAddress = $addressObject->mailbox. (!empty($addressObject->host) ? '@'.$addressObject->host : '');
$emailAddress = $addressObject->mailbox. (!empty($addressObject->host) ? '@'.$mail_bo->idna2->encode($addressObject->host) : '');
#$emailName = $mail_bo->encodeHeader($addressObject->personal, 'q');
#$_mailObject->AddCC($emailAddress, $emailName);
$_mailObject->AddCC($emailAddress, str_replace(array('@'),' ',($addressObject->personal?$addressObject->personal:$_emailAddress)));
}
}
foreach((array)$_formData['bcc'] as $address) {
$address_array = imap_rfc822_parse_adrlist((get_magic_quotes_gpc()?stripslashes($address):$address),'');
foreach((array)$address_array as $addressObject) {
if ($addressObject->host == '.SYNTAX-ERROR.') continue;
$_emailAddress = $addressObject->mailbox. (!empty($addressObject->host) ? '@'.$addressObject->host : '');
$emailAddress = $addressObject->mailbox. (!empty($addressObject->host) ? '@'.$mail_bo->idna2->encode($addressObject->host) : '');
#$emailName = $mail_bo->encodeHeader($addressObject->personal, 'q');
#$_mailObject->AddBCC($emailAddress, $emailName);
$_mailObject->AddBCC($emailAddress, str_replace(array('@'),' ',($addressObject->personal?$addressObject->personal:$_emailAddress)));
}
}
foreach((array)$_formData['replyto'] as $address) {
$address_array = imap_rfc822_parse_adrlist((get_magic_quotes_gpc()?stripslashes($address):$address),'');
foreach((array)$address_array as $addressObject) {
if ($addressObject->host == '.SYNTAX-ERROR.') continue;
$_emailAddress = $addressObject->mailbox. (!empty($addressObject->host) ? '@'.$addressObject->host : '');
$emailAddress = $addressObject->mailbox. (!empty($addressObject->host) ? '@'.$addressObject->host : '');
#$emailName = $mail_bo->encodeHeader($addressObject->personal, 'q');
#$_mailObject->AddBCC($emailAddress, $emailName);
$_mailObject->AddReplyto($emailAddress, str_replace(array('@'),' ',($addressObject->personal?$addressObject->personal:$_emailAddress)));
foreach((array)$_formData[$field] as $address)
{
foreach(emailadmin_imapbase::parseAddressList($address) as $addressObject) {
if (!$addressObject->valid) continue;
$_emailAddress = $addressObject->mailbox. (!empty($addressObject->host) ? '@'.$addressObject->host : '');
$emailAddress = $addressObject->mailbox. (!empty($addressObject->host) ? '@'.$mail_bo->idna2->encode($addressObject->host) : '');
$_mailObject->$method($emailAddress, str_replace(array('@'),' ',($addressObject->personal?$addressObject->personal:$_emailAddress)));
}
}
}
@ -2491,8 +2455,7 @@ class mail_compose
$this->createMessage($mail, $_formData, $identity);
$this->sessionData['bcc'] = self::resolveEmailAddressList($this->sessionData['bcc']);
foreach((array)$this->sessionData['bcc'] as $address) {
$address_array = imap_rfc822_parse_adrlist((get_magic_quotes_gpc()?stripslashes($address):$address),'');
foreach((array)$address_array as $addressObject) {
foreach(emailadmin_imapbase::parseAddressList($address) as $addressObject) {
$emailAddress = $addressObject->mailbox. (!empty($addressObject->host) ? '@'.$addressObject->host : '');
$mailAddr[] = array($emailAddress, $addressObject->personal);
}
@ -2768,8 +2731,7 @@ class mail_compose
if (count($folder) > 0 || $_formData['to_infolog'] == 'on' || $_formData['to_tracker'] == 'on') {
//error_log(__METHOD__.__LINE__.array2string($this->sessionData['bcc']));
foreach((array)$this->sessionData['bcc'] as $address) {
$address_array = imap_rfc822_parse_adrlist((get_magic_quotes_gpc()?stripslashes($address):$address),'');
foreach((array)$address_array as $addressObject) {
foreach(emailadmin_imapbase::parseAddressList($address) as $addressObject) {
$emailAddress = $addressObject->mailbox. (!empty($addressObject->host) ? '@'.$addressObject->host : '');
$mailAddr[] = array($emailAddress, $addressObject->personal);
}