* Mail: handle problem on Mail2Infolog/Mail2Tracker when creating the header info section on mails

handle problems in  email display and processing for further use
avoid php-warnings when cleaning cache by making sure there is something before trying to unset it
make sure the egw_idna object is initialized
This commit is contained in:
Klaus Leithoff 2014-09-05 12:28:07 +00:00
parent 185133abe4
commit 0562c8c0b5

View File

@ -590,12 +590,12 @@ class emailadmin_imapbase
else else
{ {
$folders2return = egw_cache::getCache(egw_cache::INSTANCE,'email','folderObjects'.trim($account_id),$callback=null,$callback_params=array(),$expiration=60*60*1); $folders2return = egw_cache::getCache(egw_cache::INSTANCE,'email','folderObjects'.trim($account_id),$callback=null,$callback_params=array(),$expiration=60*60*1);
if (isset($folders2return[$_ImapServerId])) if (!empty($folders2return) && isset($folders2return[$_ImapServerId]))
{ {
unset($folders2return[$_ImapServerId]); unset($folders2return[$_ImapServerId]);
} }
$folderInfo = egw_cache::getCache(egw_cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($account_id),null,array(),$expiration=60*60*5); $folderInfo = egw_cache::getCache(egw_cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($account_id),null,array(),$expiration=60*60*5);
if (isset($folderInfo[$_ImapServerId])) if (!empty($folderInfo) && isset($folderInfo[$_ImapServerId]))
{ {
unset($folderInfo[$_ImapServerId]); unset($folderInfo[$_ImapServerId]);
} }
@ -607,12 +607,12 @@ class emailadmin_imapbase
} }
*/ */
$folderBasicInfo = egw_cache::getCache(egw_cache::INSTANCE,'email','folderBasicInfo'.trim($account_id),null,array(),$expiration=60*60*1); $folderBasicInfo = egw_cache::getCache(egw_cache::INSTANCE,'email','folderBasicInfo'.trim($account_id),null,array(),$expiration=60*60*1);
if (isset($folderBasicInfo[$_ImapServerId])) if (!empty($folderBasicInfo) && isset($folderBasicInfo[$_ImapServerId]))
{ {
unset($folderBasicInfo[$_ImapServerId]); unset($folderBasicInfo[$_ImapServerId]);
} }
$_specialUseFolders = egw_cache::getCache(egw_cache::INSTANCE,'email','specialUseFolders'.trim($account_id),null,array(),$expiration=60*60*12); $_specialUseFolders = egw_cache::getCache(egw_cache::INSTANCE,'email','specialUseFolders'.trim($account_id),null,array(),$expiration=60*60*12);
if (isset($_specialUseFolders[$_ImapServerId])) if (!empty($_specialUseFolders) && isset($_specialUseFolders[$_ImapServerId]))
{ {
unset($_specialUseFolders[$_ImapServerId]); unset($_specialUseFolders[$_ImapServerId]);
self::$specialUseFolders=null; self::$specialUseFolders=null;
@ -2007,25 +2007,32 @@ class emailadmin_imapbase
if ($_tryIDNConversion===true && stripos($_string,'@')!==false) if ($_tryIDNConversion===true && stripos($_string,'@')!==false)
{ {
$rfcAddr = imap_rfc822_parse_adrlist(str_replace(',','\,',$_string),''); $rfcAddr = imap_rfc822_parse_adrlist($_string,'');
if (!isset(self::$idna2)) self::$idna2 = new egw_idna; if (!isset(self::$idna2)) self::$idna2 = new egw_idna;
$stringA = array(); if (isset(self::$idna2))
//$_string = str_replace($rfcAddr[0]->host,self::$idna2->decode($rfcAddr[0]->host),$_string);
foreach ((array)$rfcAddr as $_rfcAddr)
{ {
if ($_rfcAddr->host=='.SYNTAX-ERROR.') $stringA = array();
//$_string = str_replace($rfcAddr[0]->host,self::$idna2->decode($rfcAddr[0]->host),$_string);
foreach ((array)$rfcAddr as $_rfcAddr)
{ {
$stringA = array(); if ($_rfcAddr->host=='.SYNTAX-ERROR.')
break; // skip idna conversion if we encounter an error here {
$stringA = array();
break; // skip idna conversion if we encounter an error here
}
$stringA[] = imap_rfc822_write_address($_rfcAddr->mailbox,self::$idna2->decode($_rfcAddr->host),$_rfcAddr->personal);
} }
$stringA[] = imap_rfc822_write_address($_rfcAddr->mailbox,self::$idna2->decode($_rfcAddr->host),$_rfcAddr->personal); if (!empty($stringA)) $_string = implode(',',$stringA);
} }
if (!empty($stringA)) $_string = implode(',',$stringA);
} }
if ($_tryIDNConversion==='FORCE') if ($_tryIDNConversion==='FORCE')
{ {
//error_log(__METHOD__.' ('.__LINE__.') '.'->'.$_string.'='.self::$idna2->decode($_string)); if (!isset(self::$idna2)) self::$idna2 = new egw_idna;
$_string = self::$idna2->decode($_string); if (isset(self::$idna2))
{
//error_log(__METHOD__.' ('.__LINE__.') '.'->'.$_string.'='.self::$idna2->decode($_string));
$_string = self::$idna2->decode($_string);
}
} }
return $_string; return $_string;
} }
@ -5331,13 +5338,16 @@ class emailadmin_imapbase
else else
{ {
$attachments[$num] = array_merge($attachments[$num],$mailClass->getAttachment($uid, $attachment['partID'],0,false,false)); $attachments[$num] = array_merge($attachments[$num],$mailClass->getAttachment($uid, $attachment['partID'],0,false,false));
if (empty($attachments[$num]['attachment'])&&$attachments[$num]['cid']) if (empty($attachments[$num]['attachment'])&&$attachments[$num]['cid'])
{ {
$c = $mailClass->getAttachmentByCID($uid, $attachment['cid'], $attachment['partID'],true); $c = $mailClass->getAttachmentByCID($uid, $attachment['cid'], $attachment['partID'],true);
$attachments[$num]['attachment'] = $c->getContents(); $attachments[$num]['attachment'] = $c->getContents();
} }
if (isset($attachments[$num]['charset'])) { // no attempt to convert, if we dont know about the charset
if ($attachments[$num]['charset']===false) $attachments[$num]['charset'] = translation::detect_encoding($attachments[$num]['attachment']); if (isset($attachments[$num]['charset'])&&!empty($attachments[$num]['charset'])) {
// we do not try guessing the charset, if it is not set
//if ($attachments[$num]['charset']===false) $attachments[$num]['charset'] = translation::detect_encoding($attachments[$num]['attachment']);
translation::convert($attachments[$num]['attachment'],$attachments[$num]['charset']); translation::convert($attachments[$num]['attachment'],$attachments[$num]['charset']);
} }
$attachments[$num]['type'] = $attachments[$num]['mimeType']; $attachments[$num]['type'] = $attachments[$num]['mimeType'];
@ -5443,7 +5453,7 @@ class emailadmin_imapbase
$returnAddr .= (strlen($returnAddr)>0?',':''); $returnAddr .= (strlen($returnAddr)>0?',':'');
//error_log(__METHOD__.' ('.__LINE__.') '.$p.' <'.$mb.'@'.$h.'>'); //error_log(__METHOD__.' ('.__LINE__.') '.$p.' <'.$mb.'@'.$h.'>');
$buff = imap_rfc822_write_address($addressObject->mailbox, self::$idna2->decode($addressObject->host), $addressObject->personal); $buff = imap_rfc822_write_address($addressObject->mailbox, self::$idna2->decode($addressObject->host), $addressObject->personal);
$buff = str_replace(array('<','>'),array('[',']'),$buff); $buff = str_replace(array('<','>','"\'','\'"'),array('[',']','"','"'),$buff);
if ($createHTML) $buff = emailadmin_imapbase::htmlspecialchars($buff); if ($createHTML) $buff = emailadmin_imapbase::htmlspecialchars($buff);
//error_log(__METHOD__.' ('.__LINE__.') '.' Address: '.$returnAddr); //error_log(__METHOD__.' ('.__LINE__.') '.' Address: '.$returnAddr);
$returnAddr .= $buff; $returnAddr .= $buff;
@ -5453,7 +5463,7 @@ class emailadmin_imapbase
{ {
// do not mess with strings, return them untouched /* ToDo: validate string as Address */ // do not mess with strings, return them untouched /* ToDo: validate string as Address */
$rfcAddressArray = self::decode_header($rfcAddressArray,true); $rfcAddressArray = self::decode_header($rfcAddressArray,true);
$rfcAddressArray = str_replace(array('<','>'),array('[',']'),$rfcAddressArray); $rfcAddressArray = str_replace(array('<','>','"\'','\'"'),array('[',']','"','"'),$rfcAddressArray);
if (is_string($rfcAddressArray)) return ($createHTML ? emailadmin_imapbase::htmlspecialchars($rfcAddressArray) : $rfcAddressArray); if (is_string($rfcAddressArray)) return ($createHTML ? emailadmin_imapbase::htmlspecialchars($rfcAddressArray) : $rfcAddressArray);
} }
return $returnAddr; return $returnAddr;