* 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()
r49066: sending mail was failing after r49065
This commit is contained in:
Ralf Becker 2014-10-20 18:10:31 +00:00
parent 570558ff31
commit 9a2cfa0782
3 changed files with 239 additions and 275 deletions

View File

@ -2040,15 +2040,15 @@ class emailadmin_imapbase
if ($_tryIDNConversion===true && stripos($_string,'@')!==false)
{
$rfcAddr = imap_rfc822_parse_adrlist($_string,'');
$rfcAddr = self::parseAddressList($_string);
if (!isset(self::$idna2)) self::$idna2 = new egw_idna;
if (isset(self::$idna2))
{
$stringA = array();
//$_string = str_replace($rfcAddr[0]->host,self::$idna2->decode($rfcAddr[0]->host),$_string);
foreach ((array)$rfcAddr as $_rfcAddr)
foreach ($rfcAddr as $_rfcAddr)
{
if ($_rfcAddr->host=='.SYNTAX-ERROR.')
if (!$_rfcAddr->valid)
{
$stringA = array();
break; // skip idna conversion if we encounter an error here
@ -4495,8 +4495,7 @@ class emailadmin_imapbase
foreach($recepientList as $recepientType) {
if(isset($headers[$recepientType])) {
if ($decode) $headers[$recepientType] = self::decode_header($headers[$recepientType],true);
$addresses = imap_rfc822_parse_adrlist($headers[$recepientType], '');
foreach($addresses as $singleAddress) {
foreach(self::parseAddressList($headers[$recepientType]) as $singleAddress) {
$addressData = array(
'PERSONAL_NAME' => $singleAddress->personal ? $singleAddress->personal : 'NIL',
'AT_DOMAIN_LIST' => $singleAddress->adl ? $singleAddress->adl : 'NIL',
@ -5458,16 +5457,16 @@ class emailadmin_imapbase
}
if ($addressData['RFC822_EMAIL'])
{
$addressObjectA = imap_rfc822_parse_adrlist((get_magic_quotes_gpc()?stripslashes($addressData['RFC822_EMAIL']):$addressData['RFC822_EMAIL']),'');
$addressObjectA = self::parseAddressList($addressData['RFC822_EMAIL']);
}
else
{
$emailaddress = ($addressData['PERSONAL_NAME']?$addressData['PERSONAL_NAME'].' <'.$addressData['EMAIL'].'>':$addressData['EMAIL']);
$addressObjectA = imap_rfc822_parse_adrlist((get_magic_quotes_gpc()?stripslashes($emailaddress):$emailaddress),'');
$addressObjectA = self::parseAddressList($emailaddress);
}
$addressObject = $addressObjectA[0];
//error_log(__METHOD__.' ('.__LINE__.') '.array2string($addressObject));
if ($addressObject->host == '.SYNTAX-ERROR.') continue;
if (!$addressObject->valid) continue;
//$mb =(string)$addressObject->mailbox;
//$h = (string)$addressObject->host;
//$p = (string)$addressObject->personal;
@ -6065,190 +6064,207 @@ class emailadmin_imapbase
*/
function parseFileIntoMailObject($mailObject,$tmpFileName,&$Header,&$Body)
{
$message = file_get_contents($tmpFileName);
try
{
return $this->parseRawMessageIntoMailObject($mailObject,$message,$Header,$Body);
}
catch (egw_exception_assertion_failed $e)
{ // not sure that this is needed to pass on exeptions
throw new egw_exception_assertion_failed($e->getMessage());
}
$message = file_get_contents($tmpFileName);
try
{
return $this->parseRawMessageIntoMailObject($mailObject,$message,$Header,$Body);
}
catch (egw_exception_assertion_failed $e)
{ // not sure that this is needed to pass on exeptions
throw new egw_exception_assertion_failed($e->getMessage());
}
}
/**
* parseRawMessageIntoMailObject - parses a message/rfc mail from file to the mailobject and returns the header and body via reference
* throws egw_exception_assertion_failed when the required Pear Class is not found/loadable
* @param object $mailObject instance of the SMTP Mailer Object
* @param mixed string/object $message string containing the RawMessage / object Mail_mimeDecoded message (part))
* Parses a message/rfc mail from file to the mailobject and returns the header and body via reference
*
* @param PHPMailer $mailObject instance of the SMTP Mailer Object
* @param string|Horde_Mime_Part $message string containing the RawMessage / object Mail_mimeDecoded message (part))
* @param string &$Header reference used to return the imported Mailheader
* @param string &$Body reference to return the imported Body
* @throws egw_exception_assertion_failed when the required Horde_Mail_Part not found
* @return void Mailheader and body is returned via Reference in $Header $Body
*/
function parseRawMessageIntoMailObject($mailObject,$message,&$Header,&$Body)
function parseRawMessageIntoMailObject(PHPMailer $mailObject, $message, &$Header, &$Body)
{
/**
* pear/Mail_mimeDecode requires package "pear/Mail_Mime" (version >= 1.4.0, excluded versions: 1.4.0)
* ./pear upgrade Mail_Mime
* ./pear install Mail_mimeDecode
*/
//echo '<pre>'.$message.'</pre>';
//error_log(__METHOD__.' ('.__LINE__.') '.$message);
if (class_exists('Mail_mimeDecode',false)==false && (@include_once 'Mail/mimeDecode.php') === false) throw new egw_exception_assertion_failed(lang('Required PEAR class Mail/mimeDecode.php not found.'));
if (is_string($message))
/**
* pear/Mail_mimeDecode requires package "pear/Mail_Mime" (version >= 1.4.0, excluded versions: 1.4.0)
* ./pear upgrade Mail_Mime
* ./pear install Mail_mimeDecode
*/
//echo '<pre>'.$message.'</pre>';
//error_log(__METHOD__.' ('.__LINE__.') '.$message);
if (class_exists('Mail_mimeDecode',false)==false && (@include_once 'Mail/mimeDecode.php') === false) throw new egw_exception_assertion_failed(lang('Required PEAR class Mail/mimeDecode.php not found.'));
if (is_string($message))
{
$mailDecode = new Mail_mimeDecode($message);
$structure = $mailDecode->decode(array('include_bodies'=>true,'decode_bodies'=>true,'decode_headers'=>true));
}
elseif (is_object($message))
{
$structure = $message;
}
//error_log(__METHOD__.' ('.__LINE__.') '.array2string($structure));
//_debug_array($structure);
//exit;
// now create a message to view, save it in Drafts and open it
$mailObject->PluginDir = EGW_SERVER_ROOT."/phpgwapi/inc/";
$mailObject->IsSMTP();
$mailObject->CharSet = self::$displayCharset; // some default, may be altered by BodyImport
if (isset($structure->ctype_parameters['charset'])) $mailObject->CharSet = trim($structure->ctype_parameters['charset']);
$mailObject->Encoding = 'quoted-printable'; // some default, may be altered by BodyImport
$contenttypecalendar = '';
$myReplyTo = '';
// use Horde code to parse header, Mail_mimeDecode fails with utf-8
$headers = Horde_Mime_Headers::parseHeaders(substr($message, 0, strpos($message, Horde_Mime_Part::RFC_EOL.Horde_Mime_Part::RFC_EOL)));
foreach($headers->toArray(array('charset' => self::$displayCharset)) as $key => $val)
{
$key = strtolower($key);
//error_log(__METHOD__.' ('.__LINE__.') '.$key.'->'.$val);
foreach((array)$val as $i => $v)
{
$mailDecode = new Mail_mimeDecode($message);
$structure = $mailDecode->decode(array('include_bodies'=>true,'decode_bodies'=>true,'decode_headers'=>true));
}
if (is_object($message))
{
$structure = $message;
}
//error_log(__METHOD__.' ('.__LINE__.') '.array2string($structure));
//_debug_array($structure);
//exit;
// now create a message to view, save it in Drafts and open it
$mailObject->PluginDir = EGW_SERVER_ROOT."/phpgwapi/inc/";
$mailObject->IsSMTP();
$mailObject->CharSet = self::$displayCharset; // some default, may be altered by BodyImport
if (isset($structure->ctype_parameters['charset'])) $mailObject->CharSet = trim($structure->ctype_parameters['charset']);
$mailObject->Encoding = 'quoted-printable'; // some default, may be altered by BodyImport
/*
$mailObject->AddAddress($emailAddress, $addressObject->personal);
$mailObject->AddCC($emailAddress, $addressObject->personal);
$mailObject->AddBCC($emailAddress, $addressObject->personal);
$mailObject->AddReplyto($emailAddress, $addressObject->personal);
*/
$result ='';
$contenttypecalendar = '';
$myReplyTo = '';
foreach((array)$structure->headers as $key => $val)
{
//error_log(__METHOD__.' ('.__LINE__.') '.$key.'->'.$val);
foreach((array)$val as $i => $v)
if ($key!='content-type' && $key !='content-transfer-encoding' &&
$key != 'message-id' &&
$key != 'subject' &&
$key != 'from' &&
$key != 'to' &&
$key != 'cc' &&
$key != 'bcc' &&
$key != 'reply-to' &&
$key != 'x-priority') // the omitted values to that will be set at the end
{
if ($key!='content-type' && $key !='content-transfer-encoding' &&
$key != 'message-id' &&
$key != 'subject' &&
$key != 'from' &&
$key != 'to' &&
$key != 'cc' &&
$key != 'bcc' &&
$key != 'reply-to' &&
$key != 'x-priority') // the omitted values to that will be set at the end
{
$Header .= $mailObject->HeaderLine($key, trim($v));
}
$Header .= $mailObject->HeaderLine($key, trim($v));
}
switch ($key)
{
case 'x-priority':
$mailObject->Priority = $val;
break;
case 'message-id':
$mailObject->MessageID = $val; // ToDo: maybe we want to regenerate the message id all the time
break;
case 'sender':
$mailObject->Sender = $val;
break;
case 'to':
case 'cc':
case 'bcc':
case 'from':
case 'reply-to':
$address_array = imap_rfc822_parse_adrlist((get_magic_quotes_gpc()?stripslashes($val):$val),'');
$i = 0;
foreach((array)$address_array as $addressObject)
}
switch ($key)
{
case 'x-priority':
$mailObject->Priority = $val;
break;
case 'message-id':
$mailObject->MessageID = $val; // ToDo: maybe we want to regenerate the message id all the time
break;
case 'sender':
$mailObject->Sender = $val;
break;
case 'to':
case 'cc':
case 'bcc':
case 'from':
case 'reply-to':
$address_array = self::parseAddressList($val);
$i = 0;
foreach($address_array as $addressObject)
{
$mb = $addressObject->mailbox. (!empty($addressObject->host) ? '@'.$addressObject->host : '');
$pName = $addressObject->personal;
if ($key=='from')
{
$mb = $addressObject->mailbox. (!empty($addressObject->host) ? '@'.$addressObject->host : '');
$pName = $addressObject->personal;
if ($key=='from')
{
$mailObject->From = $mb;
$mailObject->FromName = $pName;
}
${$key}[$i] = array($mb,$pName);
$i++;
$mailObject->From = $mb;
$mailObject->FromName = $pName;
}
if ($key=='reply-to')
{
$myReplyTo = ${$key};
//break; // break early as we add that later
}
$Header .= $mailObject->TextLine(trim($mailObject->AddrAppend(ucfirst($key),${$key})));
break;
case 'content-transfer-encoding':
$mailObject->Encoding = $val;
break;
case 'content-type':
//error_log(__METHOD__.' ('.__LINE__.') '.' '.$key.'->'.$val);
if (stripos($val,'calendar')) $contenttypecalendar = $val;
break;
case 'subject':
${$key}[$i] = array($mb,$pName);
$i++;
}
if ($key=='reply-to')
{
$myReplyTo = ${$key};
//break; // break early as we add that later
}
$Header .= $mailObject->TextLine(trim($mailObject->AddrAppend(ucfirst($key),${$key})));
break;
case 'content-transfer-encoding':
$mailObject->Encoding = $val;
break;
case 'content-type':
//error_log(__METHOD__.' ('.__LINE__.') '.' '.$key.'->'.$val);
if (stripos($val,'calendar')) $contenttypecalendar = $val;
break;
case 'subject':
/*
error_log(__METHOD__.__LINE__.$val);
error_log(__METHOD__.__LINE__.$mailObject->SecureHeader($val));
error_log(__METHOD__.__LINE__.translation::convert($mailObject->SecureHeader($val),false,$mailObject->CharSet));
error_log(__METHOD__.__LINE__.$mailObject->EncodeHeader($mailObject->SecureHeader($val)));
*/
$mailObject->Subject = $mailObject->EncodeHeader(translation::convert($mailObject->SecureHeader($val),false,$mailObject->CharSet));
$Header .= $mailObject->HeaderLine('Subject',$mailObject->Subject);
break;
default:
// stuff like X- ...
//$mailObject->AddCustomHeader('X-Mailer: FeLaMiMail');
if (!strtolower(substr($key,0,2))=='x-') break;
//case 'priority': // priority is a cusom header field
// $mailObject->Priority = $val;
// break;
case 'disposition-notification-to':
case 'organization':
foreach((array)$val as $i => $v) $mailObject->AddCustomHeader($key.': '. $v);
break;
}
}
// handle reply-to, wich may be set, set the first one found
if (!empty($myReplyTo))
{
$mailObject->ClearReplyTos();
$mailObject->AddReplyTo($myReplyTo[0][0],$myReplyTo[0][1]);
$mailObject->Subject = $mailObject->EncodeHeader(translation::convert($mailObject->SecureHeader($val),false,$mailObject->CharSet));
$Header .= $mailObject->HeaderLine('Subject',$mailObject->Subject);
break;
default:
// stuff like X- ...
//$mailObject->AddCustomHeader('X-Mailer: FeLaMiMail');
if (!strtolower(substr($key,0,2))=='x-') break;
//case 'priority': // priority is a cusom header field
// $mailObject->Priority = $val;
// break;
case 'disposition-notification-to':
case 'organization':
foreach((array)$val as $i => $v) $mailObject->AddCustomHeader($key.': '. $v);
break;
}
}
// handle reply-to, wich may be set, set the first one found
if (!empty($myReplyTo))
{
$mailObject->ClearReplyTos();
$mailObject->AddReplyTo($myReplyTo[0][0],$myReplyTo[0][1]);
}
$seemsToBePlainMessage = false;
if (strtolower($structure->ctype_primary)=='text' && $structure->body)
$seemsToBePlainMessage = false;
if (strtolower($structure->ctype_primary)=='text' && $structure->body)
{
$mailObject->IsHTML(strtolower($structure->ctype_secondary)=='html'?true:false);
if (strtolower($structure->ctype_primary) == 'text' && strtolower($structure->ctype_secondary) == 'plain' &&
is_array($structure->ctype_parameters) && isset($structure->ctype_parameters['format']) &&
trim(strtolower($structure->ctype_parameters['format']))=='flowed'
)
{
$mailObject->IsHTML(strtolower($structure->ctype_secondary)=='html'?true:false);
if (strtolower($structure->ctype_primary) == 'text' && strtolower($structure->ctype_secondary) == 'plain' &&
is_array($structure->ctype_parameters) && isset($structure->ctype_parameters['format']) &&
trim(strtolower($structure->ctype_parameters['format']))=='flowed'
)
{
if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." detected TEXT/PLAIN Format:flowed -> removing leading blank ('\r\n ') per line");
$structure->body = str_replace("\r\n ","\r\n", $structure->body);
}
$mailObject->Body = $structure->body;
$seemsToBePlainMessage = true;
if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." detected TEXT/PLAIN Format:flowed -> removing leading blank ('\r\n ') per line");
$structure->body = str_replace("\r\n ","\r\n", $structure->body);
}
$this->createBodyFromStructure($mailObject, $structure, $parenttype=null);
$mailObject->SetMessageType();
$mailObject->CreateHeader(); // this sets the boundary stufff
//echo "Boundary:".$mailObject->FetchBoundary(1).'<br>';
//$boundary ='';
//if (isset($structure->ctype_parameters['boundary'])) $boundary = ' boundary="'.$mailObject->FetchBoundary(1).'";';
if ($seemsToBePlainMessage && !empty($contenttypecalendar) && strtolower($mailObject->ContentType)=='text/plain')
{
$Header .= $mailObject->HeaderLine('Content-Transfer-Encoding', $mailObject->Encoding);
$Header .= $mailObject->HeaderLine('Content-type', $contenttypecalendar);
}
else
{
$Header .= $mailObject->GetMailMIME();
}
$Body = $mailObject->getMessageBody(); // this is a method of the egw_mailer/phpmailer class
//_debug_array($Header);
//_debug_array($Body);
//_debug_array($mailObject);
//exit;
$mailObject->Body = $structure->body;
$seemsToBePlainMessage = true;
}
$this->createBodyFromStructure($mailObject, $structure, $parenttype=null);
$mailObject->SetMessageType();
$mailObject->CreateHeader(); // this sets the boundary stufff
//echo "Boundary:".$mailObject->FetchBoundary(1).'<br>';
//$boundary ='';
//if (isset($structure->ctype_parameters['boundary'])) $boundary = ' boundary="'.$mailObject->FetchBoundary(1).'";';
if ($seemsToBePlainMessage && !empty($contenttypecalendar) && strtolower($mailObject->ContentType)=='text/plain')
{
$Header .= $mailObject->HeaderLine('Content-Transfer-Encoding', $mailObject->Encoding);
$Header .= $mailObject->HeaderLine('Content-type', $contenttypecalendar);
}
else
{
$Header .= $mailObject->GetMailMIME();
}
$Body = $mailObject->getMessageBody(); // this is a method of the egw_mailer/phpmailer class
//_debug_array($Header);
//_debug_array($Body);
//_debug_array($mailObject);
//exit;
}
/**
* Parse an address-list
*
* Replaces imap_rfc822_parse_adrlist, which fails for utf-8, if not our replacement in common_functions is used!
*
* @param string $addresses
* @param string $default_domain
* @return Horde_Mail_Rfc822_List iteratable Horde_Mail_Rfc822_Address objects with attributes mailbox, host, personal and valid
*/
public static function parseAddressList($addresses, $default_domain=null)
{
$rfc822 = new Horde_Mail_Rfc822();
$ret = $rfc822->parseAddressList($addresses, $default_domain ? array('default_domain' => $default_domain) : array());
//foreach($ret as $i => $adr) error_log(__METHOD__."('$addresses', $default_domain) parsed $i: mailbox=$adr->mailbox, host=$adr->host, personal=$adr->personal --> ".$adr);
return $ret;
}
/**
@ -6486,7 +6502,7 @@ error_log(__METHOD__.__LINE__.$mailObject->EncodeHeader($mailObject->SecureHeade
} else if ( isset($headers['X-CONFIRM-READING-TO']) ) {
$toAddr = $headers['X-CONFIRM-READING-TO'];
} else return false;
$singleAddress = imap_rfc822_parse_adrlist($toAddr,'');
$singleAddress = self::parseAddressList($toAddr);
if (self::$debug) error_log(__METHOD__.__LINE__.' To Address:'.$singleAddress[0]->mailbox."@".$singleAddress[0]->host.", ".$singleAddress[0]->personal);
$send->AddAddress($singleAddress[0]->mailbox."@".$singleAddress[0]->host, $singleAddress[0]->personal);
$send->AddCustomHeader('References: '.$headers['MESSAGE-ID']);

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);
@ -1416,9 +1414,9 @@ class mail_compose
function generateRFC822Address($_addressObject)
{
if(!empty($_addressObject->personal) && !empty($_addressObject->mailbox) && !empty($_addressObject->host)) {
if($_addressObject->personal && $_addressObject->mailbox && $_addressObject->host) {
return sprintf('"%s" <%s@%s>', $this->mail_bo->decode_header($_addressObject->personal), $_addressObject->mailbox, $this->mail_bo->decode_header($_addressObject->host,'FORCE'));
} elseif(!empty($_addressObject->mailbox) && !empty($_addressObject->host)) {
} elseif($_addressObject->mailbox && $_addressObject->host) {
return sprintf("%s@%s", $_addressObject->mailbox, $this->mail_bo->decode_header($_addressObject->host,'FORCE'));
} else {
return $this->mail_bo->decode_header($_addressObject->mailbox,true);
@ -1491,10 +1489,10 @@ 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->mailbox == 'undisclosed-recipients' || (empty($_rfcAddr->mailbox) && empty($_rfcAddr->host)) ) {
if (!$_rfcAddr->valid) continue;
if($_rfcAddr->mailbox == 'undisclosed-recipients' || (!$_rfcAddr->mailbox && !$_rfcAddr->host) ) {
continue;
}
$keyemail=$_rfcAddr->mailbox.'@'.$_rfcAddr->host;
@ -1512,10 +1510,10 @@ 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->mailbox == 'undisclosed-recipients' || (empty($_rfcAddr->mailbox) && empty($_rfcAddr->host)) ) {
if (!$_rfcAddr->valid) continue;
if($_rfcAddr->mailbox == 'undisclosed-recipients' || (!$_rfcAddr->mailbox && !$_rfcAddr->host) ) {
continue;
}
$keyemail=$_rfcAddr->mailbox.'@'.$_rfcAddr->host;
@ -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. ($addressObject->host ? '@'.$addressObject->host : '');
$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$mail_bo->idna2->encode($addressObject->host) : '');
$_mailObject->$method($emailAddress, str_replace(array('@'),' ',($addressObject->personal?$addressObject->personal:$_emailAddress)));
}
}
}
@ -2491,9 +2455,8 @@ 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) {
$emailAddress = $addressObject->mailbox. (!empty($addressObject->host) ? '@'.$addressObject->host : '');
foreach(emailadmin_imapbase::parseAddressList($address) as $addressObject) {
$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
$mailAddr[] = array($emailAddress, $addressObject->personal);
}
}
@ -2768,9 +2731,8 @@ 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) {
$emailAddress = $addressObject->mailbox. (!empty($addressObject->host) ? '@'.$addressObject->host : '');
foreach(emailadmin_imapbase::parseAddressList($address) as $addressObject) {
$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
$mailAddr[] = array($emailAddress, $addressObject->personal);
}
}