From cd108bfa9a9c3812f232cbbaa23e74d151fe4550 Mon Sep 17 00:00:00 2001 From: Klaus Leithoff Date: Fri, 27 Aug 2010 08:13:42 +0000 Subject: [PATCH] =?UTF-8?q?Using=20egw=5Ftime=20for=20date/time=20handling?= =?UTF-8?q?;=20handle=20unrecognized=20timezones=20like=20'Westeurop=C3=A4?= =?UTF-8?q?ische=20Sommerzeit'=20by=20splitting=20them=20off,=20when=20str?= =?UTF-8?q?totime=20failes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- felamimail/inc/class.bofelamimail.inc.php | 22 ++++++++++++++++++++-- felamimail/inc/class.uidisplay.inc.php | 8 ++++---- felamimail/inc/class.uiwidgets.inc.php | 17 ++++++++++------- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/felamimail/inc/class.bofelamimail.inc.php b/felamimail/inc/class.bofelamimail.inc.php index 1b3eadb5d5..1f47a6ff96 100644 --- a/felamimail/inc/class.bofelamimail.inc.php +++ b/felamimail/inc/class.bofelamimail.inc.php @@ -2077,7 +2077,7 @@ $retValue['header'][$sortOrder[$uid]]['subject'] = $this->decode_subject($headerObject['SUBJECT']); $retValue['header'][$sortOrder[$uid]]['size'] = $headerObject['SIZE']; - $retValue['header'][$sortOrder[$uid]]['date'] = strtotime($headerObject['DATE']); + $retValue['header'][$sortOrder[$uid]]['date'] = self::_strtotime($headerObject['DATE']); $retValue['header'][$sortOrder[$uid]]['mimetype'] = $headerObject['MIMETYPE']; $retValue['header'][$sortOrder[$uid]]['id'] = $headerObject['MSG_NUM']; $retValue['header'][$sortOrder[$uid]]['uid'] = $headerObject['UID']; @@ -2895,7 +2895,7 @@ if ( preg_match('/\b'.$identity->emailAddress.'\b/',$headers['TO']) ) { $send->From = $identity->emailAddress; $send->FromName = $identity->realName; - error_log('Not Default '.$send->From); + error_log('using identity for send from:'.$send->From.' to match header information:'.$headers['TO']); break; } if($identity->default) { @@ -3018,4 +3018,22 @@ $needle = '/(=[0-9][A-F])|(=[A-F][0-9])|(=[A-F][A-F])|(=[0-9][0-9])/'; return preg_match("$needle",$string); } + /** + * Helper function to handle wrong or unrecognized timezones + */ + static function _strtotime($date='') + { + if (strtotime($date)===false) + { + $dtarr = explode(' ',$date); + $test = false; + while ($test===false) + { + array_pop($dtarr); + $test=strtotime(implode(' ',$dtarr)); + if ($test) $date = implode(' ',$dtarr); + } + } + return $date; + } } diff --git a/felamimail/inc/class.uidisplay.inc.php b/felamimail/inc/class.uidisplay.inc.php index 0a03110bfd..32ea08557f 100644 --- a/felamimail/inc/class.uidisplay.inc.php +++ b/felamimail/inc/class.uidisplay.inc.php @@ -445,9 +445,9 @@ } else { $this->t->set_var("bcc_data_part",''); } - + $headerdate = new egw_time(bofelamimail::_strtotime($headers['DATE'])); $this->t->set_var("date_received", - @htmlspecialchars($GLOBALS['egw']->common->show_date(strtotime($headers['DATE'])), + @htmlspecialchars($headerdate->format($GLOBALS['egw_info']['user']['preferences']['common']['dateformat']).' - '.$headerdate->format('H:i:s'), ENT_QUOTES,$this->displayCharset)); $this->t->set_var("subject_data", @@ -1426,9 +1426,9 @@ } else { $this->t->set_var("cc_data_part",''); } - + $headerdate = new egw_time(bofelamimail::_strtotime($headers['DATE'])); $this->t->set_var("date_data", - @htmlspecialchars($GLOBALS['egw']->common->show_date(strtotime($headers['DATE'])), ENT_QUOTES,$this->displayCharset)); + @htmlspecialchars($headerdate->format($GLOBALS['egw_info']['user']['preferences']['common']['dateformat']).' - '.$headerdate->format('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 9c63628a1b..bf29384713 100644 --- a/felamimail/inc/class.uiwidgets.inc.php +++ b/felamimail/inc/class.uiwidgets.inc.php @@ -415,13 +415,15 @@ $this->t->set_var('message_counter', $i); $this->t->set_var('message_uid', $header['uid']); - - if ($dateToday == date('Y-m-d', $header['date'])) { - $this->t->set_var('date', $GLOBALS['egw']->common->show_date($header['date'],'H:i:s')); + $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')); } else { - $this->t->set_var('date', $GLOBALS['egw']->common->show_date($header['date'],$GLOBALS['egw_info']['user']['preferences']['common']['dateformat'])); + $this->t->set_var('date', $headerdate->format($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'])); } - $this->t->set_var('datetime', $GLOBALS['egw']->common->show_date($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('size', $this->show_readable_size($header['size'])); if ($firstuid === null) @@ -659,13 +661,14 @@ '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').':'.$GLOBALS['egw']->common->show_date($headerData['date']/*,$GLOBALS['egw_info']['user']['preferences']['common']['dateformat']*/)."
+ lang('date').':'.$headerdate->format($GLOBALS['egw_info']['user']['preferences']['common']['dateformat']). + ' - '.$headerdate->format('H:i:s')."
".lang('subject').":".$subject."