mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-28 10:53:39 +01:00
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; backport of bofelamimails version of wordwrap from trunk (allow to skip lines that start with )
This commit is contained in:
parent
2228cb11cc
commit
18e7ab9283
@ -975,7 +975,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()) {
|
||||
|
@ -2706,7 +2706,7 @@
|
||||
return $userACL;
|
||||
}
|
||||
|
||||
static function wordwrap($str, $cols, $cut)
|
||||
static function wordwrap($str, $cols, $cut, $dontbreaklinesstartingwith=false)
|
||||
{
|
||||
$lines = explode("\n", $str);
|
||||
$newStr = '';
|
||||
@ -2716,7 +2716,14 @@
|
||||
//$line = str_replace("\t"," ",$line);
|
||||
//$newStr .= wordwrap($line, $cols, $cut);
|
||||
$allowedLength = $cols-strlen($cut);
|
||||
if (strlen($line) > $allowedLength) {
|
||||
if (strlen($line) > $allowedLength &&
|
||||
($dontbreaklinesstartingwith==false ||
|
||||
($dontbreaklinesstartingwith &&
|
||||
strlen($dontbreaklinesstartingwith)>=1 &&
|
||||
substr($line,0,strlen($dontbreaklinesstartingwith)) != $dontbreaklinesstartingwith
|
||||
)
|
||||
)
|
||||
) {
|
||||
$s=explode(" ", $line);
|
||||
$line = "";
|
||||
$linecnt = 0;
|
||||
@ -2932,21 +2939,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;
|
||||
}
|
||||
}
|
||||
|
@ -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."#<br>";
|
||||
#echo $email."#<br>";
|
||||
//echo __METHOD__.' Text:'.$text."#<br>";
|
||||
//echo $email."#<br>";
|
||||
$comp_uri = $this->makeComposeLink($email, $text);
|
||||
$body = preg_replace("/\s".$text."/sim", $comp_uri, $body);
|
||||
//echo __METHOD__.' Uri:'.$comp_uri.'#<br>';
|
||||
$body = str_replace($text, $comp_uri, $body);
|
||||
$lmail=$email;
|
||||
}
|
||||
|
||||
@ -166,12 +170,14 @@
|
||||
#$pattern = "^".$domain.$dir.$trailingslash.$page.$getstring."$";
|
||||
$pattern = "~\<a href=\"".$domain.".*?\"~i";
|
||||
$sbody = $body;
|
||||
while(@preg_match($pattern, $sbody, $regs)) {
|
||||
#_debug_array($regs);
|
||||
$i = 0;
|
||||
while(@preg_match($pattern, $sbody, $regs) && $i <=100) {
|
||||
//_debug_array($regs);
|
||||
$key=$regs[1].$regs[3].$regs[4].$regs[5];
|
||||
$addresses[$key] = $regs[1].$regs[3].$regs[4].$regs[5];
|
||||
$start = strpos($sbody, $regs[0]) + strlen($regs[0]);
|
||||
$sbody = substr($sbody, $start);
|
||||
$i++;
|
||||
}
|
||||
$llink='';
|
||||
//_debug_array($addresses);
|
||||
@ -445,9 +451,8 @@
|
||||
} else {
|
||||
$this->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($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 = "<pre>".bofelamimail::wordwrap($newBody,85,"\n")."</pre>";
|
||||
#$newBody = "<pre>".$newBody."</pre>";
|
||||
//error_log($newBody);
|
||||
// dont break lines that start with > (> as the text was processed with htmlentities before)
|
||||
$newBody = "<pre>".bofelamimail::wordwrap($newBody,90,"\n",'>')."</pre>";
|
||||
//$newBody = "<pre>".$newBody."</pre>";
|
||||
}
|
||||
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);
|
||||
|
@ -399,15 +399,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)
|
||||
@ -636,14 +635,13 @@
|
||||
'uid' => $headerData['uid'],
|
||||
'mailbox' => base64_encode($_folderName)
|
||||
);
|
||||
$headerdate = new egw_time($headerData['date']);
|
||||
//_debug_array($GLOBALS['egw']->link('/index.php',$linkData));
|
||||
$IFRAMEBody = "<TABLE BORDER=\"1\" rules=\"rows\" style=\"table-layout:fixed;width:100%;\">
|
||||
<TR class=\"th\" style=\"width:100%;\">
|
||||
<TD nowrap valign=\"top\" style=\"overflow:hidden;\">
|
||||
".($_folderType > 0?lang('to'):lang('from')).':<b>'.$full_address.' '.($fromAddress?$fromAddress:'') .'</b><br> '.
|
||||
lang('date').':<b>'.$headerdate->format($GLOBALS['egw_info']['user']['preferences']['common']['dateformat']).
|
||||
' - '.$headerdate->format('H:i:s')."</b><br>
|
||||
lang('date').':<b>'.bofelamimail::_strtotime($headerData['date'],$GLOBALS['egw_info']['user']['preferences']['common']['dateformat']).
|
||||
' - '.bofelamimail::_strtotime($headerData['date'],'H:i:s')."</b><br>
|
||||
".lang('subject').":<b>".$subject."</b>
|
||||
</TD>
|
||||
<td style=\"width:20px;\" align=\"right\">
|
||||
|
Loading…
Reference in New Issue
Block a user