mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-02-22 13:11:06 +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
This commit is contained in:
parent
f983b8569a
commit
5a816aaa82
@ -991,7 +991,7 @@
|
|||||||
|
|
||||||
// set a higher timeout for big messages
|
// set a higher timeout for big messages
|
||||||
@set_time_limit(120);
|
@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']));
|
#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(count((array)$this->sessionData['to']) > 0 || count((array)$this->sessionData['cc']) > 0 || count((array)$this->sessionData['bcc']) > 0) {
|
||||||
if(!$mail->Send()) {
|
if(!$mail->Send()) {
|
||||||
|
@ -3038,21 +3038,26 @@
|
|||||||
/**
|
/**
|
||||||
* Helper function to handle wrong or unrecognized timezones
|
* Helper function to handle wrong or unrecognized timezones
|
||||||
* returns the date as it is parseable by strtotime, or current timestamp if everything failes
|
* 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);
|
$dtarr = explode(' ',$date);
|
||||||
$test = false;
|
$test = null;
|
||||||
while ($test===false && count($dtarr)>=1)
|
while ($test===null && count($dtarr)>=1)
|
||||||
{
|
{
|
||||||
array_pop($dtarr);
|
array_pop($dtarr);
|
||||||
$test=strtotime(implode(' ',$dtarr));
|
$test= egw_time::to(implode(' ',$dtarr),$format);
|
||||||
if ($test) $date = implode(' ',$dtarr);
|
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;
|
global $Email_RegExp_Match;
|
||||||
$sbody = $body;
|
$sbody = $body;
|
||||||
$addresses = array();
|
$addresses = array();
|
||||||
|
$i = 0;
|
||||||
/* Find all the email addresses in the body */
|
/* 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('&' => '&'));
|
$addresses[$regs[0]] = strtr($regs[0], array('&' => '&'));
|
||||||
$start = strpos($sbody, $regs[0]) + strlen($regs[0]);
|
$start = strpos($sbody, $regs[0]) + strlen($regs[0]);
|
||||||
$sbody = substr($sbody, $start);
|
$sbody = substr($sbody, $start);
|
||||||
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Replace each email address with a compose URL */
|
/* Replace each email address with a compose URL */
|
||||||
@ -140,10 +143,11 @@
|
|||||||
if (is_array($addresses)) ksort($addresses);
|
if (is_array($addresses)) ksort($addresses);
|
||||||
foreach ($addresses as $text => $email) {
|
foreach ($addresses as $text => $email) {
|
||||||
if ($lmail == $email) next($addresses);
|
if ($lmail == $email) next($addresses);
|
||||||
#echo $text."#<br>";
|
//echo __METHOD__.' Text:'.$text."#<br>";
|
||||||
#echo $email."#<br>";
|
//echo $email."#<br>";
|
||||||
$comp_uri = $this->makeComposeLink($email, $text);
|
$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;
|
$lmail=$email;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,12 +170,14 @@
|
|||||||
#$pattern = "^".$domain.$dir.$trailingslash.$page.$getstring."$";
|
#$pattern = "^".$domain.$dir.$trailingslash.$page.$getstring."$";
|
||||||
$pattern = "~\<a href=\"".$domain.".*?\"~i";
|
$pattern = "~\<a href=\"".$domain.".*?\"~i";
|
||||||
$sbody = $body;
|
$sbody = $body;
|
||||||
while(@preg_match($pattern, $sbody, $regs)) {
|
$i = 0;
|
||||||
#_debug_array($regs);
|
while(@preg_match($pattern, $sbody, $regs) && $i <=100) {
|
||||||
|
//_debug_array($regs);
|
||||||
$key=$regs[1].$regs[3].$regs[4].$regs[5];
|
$key=$regs[1].$regs[3].$regs[4].$regs[5];
|
||||||
$addresses[$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]);
|
$start = strpos($sbody, $regs[0]) + strlen($regs[0]);
|
||||||
$sbody = substr($sbody, $start);
|
$sbody = substr($sbody, $start);
|
||||||
|
$i++;
|
||||||
}
|
}
|
||||||
$llink='';
|
$llink='';
|
||||||
//_debug_array($addresses);
|
//_debug_array($addresses);
|
||||||
@ -445,9 +451,8 @@
|
|||||||
} else {
|
} else {
|
||||||
$this->t->set_var("bcc_data_part",'');
|
$this->t->set_var("bcc_data_part",'');
|
||||||
}
|
}
|
||||||
$headerdate = new egw_time(bofelamimail::_strtotime($headers['DATE']));
|
|
||||||
$this->t->set_var("date_received",
|
$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));
|
ENT_QUOTES,$this->displayCharset));
|
||||||
|
|
||||||
$this->t->set_var("subject_data",
|
$this->t->set_var("subject_data",
|
||||||
@ -1186,7 +1191,7 @@
|
|||||||
|
|
||||||
$body = '';
|
$body = '';
|
||||||
|
|
||||||
#_debug_array($bodyParts); exit;
|
//error_log(__METHOD__.array2string($bodyParts)); //exit;
|
||||||
|
|
||||||
foreach((array)$bodyParts as $singleBodyPart) {
|
foreach((array)$bodyParts as $singleBodyPart) {
|
||||||
if (!isset($singleBodyPart['body'])) {
|
if (!isset($singleBodyPart['body'])) {
|
||||||
@ -1199,12 +1204,12 @@
|
|||||||
}
|
}
|
||||||
#_debug_array($singleBodyPart['charSet']);
|
#_debug_array($singleBodyPart['charSet']);
|
||||||
#_debug_array($singleBodyPart['mimeType']);
|
#_debug_array($singleBodyPart['mimeType']);
|
||||||
#error_log($singleBodyPart['body']);
|
//error_log($singleBodyPart['body']);
|
||||||
// some characterreplacements, as they fail to translate
|
// some characterreplacements, as they fail to translate
|
||||||
$sar = array(
|
$sar = array(
|
||||||
'@(\x84|\x93|\x94)@',
|
'@(\x84|\x93|\x94)@',
|
||||||
'@(\x96|\x97)@',
|
'@(\x96|\x97)@',
|
||||||
'@(\x91|\x92)@',
|
'@(\x82|\x91|\x92)@',
|
||||||
'@(\x85)@',
|
'@(\x85)@',
|
||||||
'@(\x86)@',
|
'@(\x86)@',
|
||||||
);
|
);
|
||||||
@ -1251,8 +1256,10 @@
|
|||||||
// to display a mailpart of mimetype plain/text, may be better taged as preformatted
|
// to display a mailpart of mimetype plain/text, may be better taged as preformatted
|
||||||
#$newBody = nl2br($newBody);
|
#$newBody = nl2br($newBody);
|
||||||
// since we do not display the message as HTML anymore we may want to insert good linebreaking (for visibility).
|
// 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>";
|
//error_log($newBody);
|
||||||
#$newBody = "<pre>".$newBody."</pre>";
|
// 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
|
else
|
||||||
{
|
{
|
||||||
@ -1426,9 +1433,8 @@
|
|||||||
} else {
|
} else {
|
||||||
$this->t->set_var("cc_data_part",'');
|
$this->t->set_var("cc_data_part",'');
|
||||||
}
|
}
|
||||||
$headerdate = new egw_time(bofelamimail::_strtotime($headers['DATE']));
|
|
||||||
$this->t->set_var("date_data",
|
$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
|
// 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);
|
$subject = @htmlspecialchars($this->bofelamimail->decode_subject(preg_replace($nonDisplayAbleCharacters, '', $envelope['SUBJECT'])), ENT_QUOTES, $this->displayCharset);
|
||||||
|
@ -415,15 +415,14 @@
|
|||||||
|
|
||||||
$this->t->set_var('message_counter', $i);
|
$this->t->set_var('message_counter', $i);
|
||||||
$this->t->set_var('message_uid', $header['uid']);
|
$this->t->set_var('message_uid', $header['uid']);
|
||||||
$headerdate = new egw_time($header['date']);
|
|
||||||
|
|
||||||
if ($dateToday == $headerdate->format('Y-m-d')) {
|
if ($dateToday == bofelamimail::_strtotime($header['date'],'Y-m-d')) {
|
||||||
$this->t->set_var('date', $headerdate->format('H:i:s')); //$GLOBALS['egw']->common->show_date($header['date'],'H:i:s'));
|
$this->t->set_var('date', bofelamimail::_strtotime($header['date'],'H:i:s')); //$GLOBALS['egw']->common->show_date($header['date'],'H:i:s'));
|
||||||
} else {
|
} 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']).
|
$this->t->set_var('datetime', bofelamimail::_strtotime($header['date'],$GLOBALS['egw_info']['user']['preferences']['common']['dateformat']).
|
||||||
' - '.$headerdate->format('H:i:s'));
|
' - '.bofelamimail::_strtotime($header['date'],'H:i:s'));
|
||||||
|
|
||||||
$this->t->set_var('size', $this->show_readable_size($header['size']));
|
$this->t->set_var('size', $this->show_readable_size($header['size']));
|
||||||
if ($firstuid === null)
|
if ($firstuid === null)
|
||||||
@ -661,14 +660,13 @@
|
|||||||
'uid' => $headerData['uid'],
|
'uid' => $headerData['uid'],
|
||||||
'mailbox' => base64_encode($_folderName)
|
'mailbox' => base64_encode($_folderName)
|
||||||
);
|
);
|
||||||
$headerdate = new egw_time($headerData['date']);
|
|
||||||
//_debug_array($GLOBALS['egw']->link('/index.php',$linkData));
|
//_debug_array($GLOBALS['egw']->link('/index.php',$linkData));
|
||||||
$IFRAMEBody = "<TABLE BORDER=\"1\" rules=\"rows\" style=\"table-layout:fixed;width:100%;\">
|
$IFRAMEBody = "<TABLE BORDER=\"1\" rules=\"rows\" style=\"table-layout:fixed;width:100%;\">
|
||||||
<TR class=\"th\" style=\"width:100%;\">
|
<TR class=\"th\" style=\"width:100%;\">
|
||||||
<TD nowrap valign=\"top\" style=\"overflow:hidden;\">
|
<TD nowrap valign=\"top\" style=\"overflow:hidden;\">
|
||||||
".($_folderType > 0?lang('to'):lang('from')).':<b>'.$full_address.' '.($fromAddress?$fromAddress:'') .'</b><br> '.
|
".($_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']).
|
lang('date').':<b>'.bofelamimail::_strtotime($headerData['date'],$GLOBALS['egw_info']['user']['preferences']['common']['dateformat']).
|
||||||
' - '.$headerdate->format('H:i:s')."</b><br>
|
' - '.bofelamimail::_strtotime($headerData['date'],'H:i:s')."</b><br>
|
||||||
".lang('subject').":<b>".$subject."</b>
|
".lang('subject').":<b>".$subject."</b>
|
||||||
</TD>
|
</TD>
|
||||||
<td style=\"width:20px;\" align=\"right\">
|
<td style=\"width:20px;\" align=\"right\">
|
||||||
|
Loading…
Reference in New Issue
Block a user