From 5a816aaa8270c75874317468b7475dd0c9eb115a Mon Sep 17 00:00:00 2001 From: Klaus Leithoff Date: Tue, 7 Sep 2010 09:04:50 +0000 Subject: [PATCH] rework of bofelamimail::_strtotime, to make propper use of egw_time; performance issue: limit the number of links and email to be parsed (and adapted) to 100 each, as it should be sufficient for most standard emails; try to further improve the display of textmails --- felamimail/inc/class.bocompose.inc.php | 2 +- felamimail/inc/class.bofelamimail.inc.php | 21 ++++++++----- felamimail/inc/class.uidisplay.inc.php | 38 +++++++++++++---------- felamimail/inc/class.uiwidgets.inc.php | 18 +++++------ 4 files changed, 44 insertions(+), 35 deletions(-) diff --git a/felamimail/inc/class.bocompose.inc.php b/felamimail/inc/class.bocompose.inc.php index 1cfbb97caa..d2f7965059 100644 --- a/felamimail/inc/class.bocompose.inc.php +++ b/felamimail/inc/class.bocompose.inc.php @@ -991,7 +991,7 @@ // set a higher timeout for big messages @set_time_limit(120); - #$mail->SMTPDebug = 10; + //$mail->SMTPDebug = 10; #error_log("Folder:".count(array($this->sessionData['folder']))."To:".count((array)$this->sessionData['to'])."CC:". count((array)$this->sessionData['cc']) ."bcc:".count((array)$this->sessionData['bcc'])); if(count((array)$this->sessionData['to']) > 0 || count((array)$this->sessionData['cc']) > 0 || count((array)$this->sessionData['bcc']) > 0) { if(!$mail->Send()) { diff --git a/felamimail/inc/class.bofelamimail.inc.php b/felamimail/inc/class.bofelamimail.inc.php index ec7a4742db..c6154a7620 100644 --- a/felamimail/inc/class.bofelamimail.inc.php +++ b/felamimail/inc/class.bofelamimail.inc.php @@ -3038,21 +3038,26 @@ /** * Helper function to handle wrong or unrecognized timezones * returns the date as it is parseable by strtotime, or current timestamp if everything failes + * @param string date to be parsed/formatted + * @param string format string, if none is passed, use the users common dateformat supplemented by the time hour:minute:second + * @return string returns the date as it is parseable by strtotime, or current timestamp if everything failes */ - static function _strtotime($date='') + static function _strtotime($date='',$format=NULL) { - if (strtotime($date)===false) + if ($format==NULL) $format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'].' '.'H:i:s'; + $date2return = egw_time::to($date,$format); + if ($date2return==null) { $dtarr = explode(' ',$date); - $test = false; - while ($test===false && count($dtarr)>=1) + $test = null; + while ($test===null && count($dtarr)>=1) { array_pop($dtarr); - $test=strtotime(implode(' ',$dtarr)); - if ($test) $date = implode(' ',$dtarr); + $test= egw_time::to(implode(' ',$dtarr),$format); + if ($test) $date2return = $test; } - if ($test===false) $date = strtotime('now'); + if ($test===null) $date2return = egw_time::to('now',$format); } - return $date; + return $date2return; } } diff --git a/felamimail/inc/class.uidisplay.inc.php b/felamimail/inc/class.uidisplay.inc.php index 32ea08557f..4223f71e90 100644 --- a/felamimail/inc/class.uidisplay.inc.php +++ b/felamimail/inc/class.uidisplay.inc.php @@ -127,12 +127,15 @@ global $Email_RegExp_Match; $sbody = $body; $addresses = array(); - + $i = 0; /* Find all the email addresses in the body */ - while(preg_match($Email_RegExp_Match, $sbody, $regs)) { + // stop cold after 100 adresses, as this is very time consuming + while(preg_match($Email_RegExp_Match, $sbody, $regs) && $i<=100) { + //_debug_array($regs); $addresses[$regs[0]] = strtr($regs[0], array('&' => '&')); $start = strpos($sbody, $regs[0]) + strlen($regs[0]); $sbody = substr($sbody, $start); + $i++; } /* Replace each email address with a compose URL */ @@ -140,10 +143,11 @@ if (is_array($addresses)) ksort($addresses); foreach ($addresses as $text => $email) { if ($lmail == $email) next($addresses); - #echo $text."#
"; - #echo $email."#
"; + //echo __METHOD__.' Text:'.$text."#
"; + //echo $email."#
"; $comp_uri = $this->makeComposeLink($email, $text); - $body = preg_replace("/\s".$text."/sim", $comp_uri, $body); + //echo __METHOD__.' Uri:'.$comp_uri.'#
'; + $body = str_replace($text, $comp_uri, $body); $lmail=$email; } @@ -166,12 +170,14 @@ #$pattern = "^".$domain.$dir.$trailingslash.$page.$getstring."$"; $pattern = "~\t->set_var("bcc_data_part",''); } - $headerdate = new egw_time(bofelamimail::_strtotime($headers['DATE'])); $this->t->set_var("date_received", - @htmlspecialchars($headerdate->format($GLOBALS['egw_info']['user']['preferences']['common']['dateformat']).' - '.$headerdate->format('H:i:s'), + @htmlspecialchars(bofelamimail::_strtotime($headers['DATE'],$GLOBALS['egw_info']['user']['preferences']['common']['dateformat']).' - '.bofelamimail::_strtotime($headers['DATE'],'H:i:s'), ENT_QUOTES,$this->displayCharset)); $this->t->set_var("subject_data", @@ -1186,7 +1191,7 @@ $body = ''; - #_debug_array($bodyParts); exit; + //error_log(__METHOD__.array2string($bodyParts)); //exit; foreach((array)$bodyParts as $singleBodyPart) { if (!isset($singleBodyPart['body'])) { @@ -1199,12 +1204,12 @@ } #_debug_array($singleBodyPart['charSet']); #_debug_array($singleBodyPart['mimeType']); - #error_log($singleBodyPart['body']); + //error_log($singleBodyPart['body']); // some characterreplacements, as they fail to translate $sar = array( '@(\x84|\x93|\x94)@', '@(\x96|\x97)@', - '@(\x91|\x92)@', + '@(\x82|\x91|\x92)@', '@(\x85)@', '@(\x86)@', ); @@ -1251,8 +1256,10 @@ // to display a mailpart of mimetype plain/text, may be better taged as preformatted #$newBody = nl2br($newBody); // since we do not display the message as HTML anymore we may want to insert good linebreaking (for visibility). - $newBody = "
".bofelamimail::wordwrap($newBody,85,"\n")."
"; - #$newBody = "
".$newBody."
"; + //error_log($newBody); + // dont break lines that start with > (> as the text was processed with htmlentities before) + $newBody = "
".bofelamimail::wordwrap($newBody,90,"\n",'>')."
"; + //$newBody = "
".$newBody."
"; } else { @@ -1426,9 +1433,8 @@ } else { $this->t->set_var("cc_data_part",''); } - $headerdate = new egw_time(bofelamimail::_strtotime($headers['DATE'])); $this->t->set_var("date_data", - @htmlspecialchars($headerdate->format($GLOBALS['egw_info']['user']['preferences']['common']['dateformat']).' - '.$headerdate->format('H:i:s'), ENT_QUOTES,$this->displayCharset)); + @htmlspecialchars(bofelamimail::_strtotime($headers['DATE'],$GLOBALS['egw_info']['user']['preferences']['common']['dateformat']).' - '.bofelamimail::_strtotime($headers['DATE'],'H:i:s'), ENT_QUOTES,$this->displayCharset)); // link to go back to the message view. the link differs if the print was called from a normal viewing window, or from compose $subject = @htmlspecialchars($this->bofelamimail->decode_subject(preg_replace($nonDisplayAbleCharacters, '', $envelope['SUBJECT'])), ENT_QUOTES, $this->displayCharset); diff --git a/felamimail/inc/class.uiwidgets.inc.php b/felamimail/inc/class.uiwidgets.inc.php index bf29384713..f3764af7b7 100644 --- a/felamimail/inc/class.uiwidgets.inc.php +++ b/felamimail/inc/class.uiwidgets.inc.php @@ -415,15 +415,14 @@ $this->t->set_var('message_counter', $i); $this->t->set_var('message_uid', $header['uid']); - $headerdate = new egw_time($header['date']); - - if ($dateToday == $headerdate->format('Y-m-d')) { - $this->t->set_var('date', $headerdate->format('H:i:s')); //$GLOBALS['egw']->common->show_date($header['date'],'H:i:s')); + + if ($dateToday == bofelamimail::_strtotime($header['date'],'Y-m-d')) { + $this->t->set_var('date', bofelamimail::_strtotime($header['date'],'H:i:s')); //$GLOBALS['egw']->common->show_date($header['date'],'H:i:s')); } else { - $this->t->set_var('date', $headerdate->format($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'])); + $this->t->set_var('date', bofelamimail::_strtotime($header['date'],$GLOBALS['egw_info']['user']['preferences']['common']['dateformat'])); } - $this->t->set_var('datetime', $headerdate->format($GLOBALS['egw_info']['user']['preferences']['common']['dateformat']). - ' - '.$headerdate->format('H:i:s')); + $this->t->set_var('datetime', bofelamimail::_strtotime($header['date'],$GLOBALS['egw_info']['user']['preferences']['common']['dateformat']). + ' - '.bofelamimail::_strtotime($header['date'],'H:i:s')); $this->t->set_var('size', $this->show_readable_size($header['size'])); if ($firstuid === null) @@ -661,14 +660,13 @@ 'uid' => $headerData['uid'], 'mailbox' => base64_encode($_folderName) ); - $headerdate = new egw_time($headerData['date']); //_debug_array($GLOBALS['egw']->link('/index.php',$linkData)); $IFRAMEBody = "
".($_folderType > 0?lang('to'):lang('from')).':'.$full_address.' '.($fromAddress?$fromAddress:'') .'
'. - lang('date').':'.$headerdate->format($GLOBALS['egw_info']['user']['preferences']['common']['dateformat']). - ' - '.$headerdate->format('H:i:s')."
+ lang('date').':'.bofelamimail::_strtotime($headerData['date'],$GLOBALS['egw_info']['user']['preferences']['common']['dateformat']). + ' - '.bofelamimail::_strtotime($headerData['date'],'H:i:s')."
".lang('subject').":".$subject."