<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.kde.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugs.kde.org/"
          
          maintainer="sysadmin@kde.org"
>

    <bug>
          <bug_id>117848</bug_id>
          
          <creation_ts>2005-12-07 11:16:05 +0000</creation_ts>
          <short_desc>Interpret old-fashioned time zone in email Date header</short_desc>
          <delta_ts>2009-08-30 18:25:12 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>10</classification_id>
          <classification>Unmaintained</classification>
          <product>kmail</product>
          <component>general</component>
          <version>1.8.3</version>
          <rep_platform>Ubuntu</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>NOR</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>0</everconfirmed>
          <reporter name="Jaap Weel">weel</reporter>
          <assigned_to name="kdepim bugs">pim-bugs-null</assigned_to>
          <cc>bensberg</cc>
          
          <cf_commitlink></cf_commitlink>
          <cf_versionfixedin></cf_versionfixedin>
          <cf_sentryurl></cf_sentryurl>
          <votes>0</votes>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>396370</commentid>
    <comment_count>0</comment_count>
    <who name="Jaap Weel">weel</who>
    <bug_when>2005-12-07 11:16:05 +0000</bug_when>
    <thetext>Version:           1.8.3 (using KDE KDE 3.4.3)
Installed from:    Ubuntu Packages
OS:                Linux

I regularly get email from someone with this type of header:

Date: Wed, 7 Dec 2005 10:21:09 CET

Kmail displays this time in the message index as 14:21. Both the sender and I are in the CET (+0100) time zone. It seems that kmail thinks that CET means -0300.

I understand that this is not standard according to RFC2822. Therefore, according to RFC2822, this should be interpreted as +0000. Alternatively, it might be reasonable, for compatibility with certain older MUAs that generate this header, to interpret the time zone as +0100 (Central European Time). I do not see any reason for -0300.

Note that this report is different from reports that merely complain about kmail interpreting weird time zones as +0000 .</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>403968</commentid>
    <comment_count>1</comment_count>
    <who name="Martin Koller">martin</who>
    <bug_when>2006-01-06 13:12:51 +0000</bug_when>
    <thetext>SVN commit 494852 by mkoller:

BUG:117848
Improve parsing of non-standard date strings.
It now parses in addition date strings in the format 
 &quot;WWW MMM dd HH:MM:SS [Z] YYYY&quot;  zone is optional
 e.g.: Fri Oct 14 09:21:49 CEST 2005
 or:   Tue Mar 23 18:00:02 2004



 M  +3 -0      datetime.cpp  
 M  +103 -32   dw_date.cpp   [POSSIBLY UNSAFE: scanf]


--- branches/KDE/3.5/kdepim/mimelib/datetime.cpp #494851:494852
@@ -45,6 +45,7 @@
        &quot;Jul&quot;, &quot;Aug&quot;, &quot;Sep&quot;, &quot;Oct&quot;, &quot;Nov&quot;, &quot;Dec&quot;};
 
 extern &quot;C&quot; int ParseRfc822Date(const char *str, struct tm *tms, int *z);
+extern &quot;C&quot; int ParseDate(const char *str, struct tm *tms, int *z);
 static DwInt32 ymd_to_jdnl(int year, int mon, int day, int julian);
 static void jdnl_to_ymd(DwInt32 jdn, int *year, int *mon, int *day, int julian);
 static DwUint32 my_inv_gmtime(struct tm* ptms);
@@ -282,6 +283,8 @@
     struct tm tms;
     int zone;
     int err = ParseRfc822Date(str, &amp;tms, &amp;zone);
+    if ( err == -1 )  // try another format
+        err = ParseDate(str, &amp;tms, &amp;zone);
     if (!err) {
         mYear   = tms.tm_year + 1900;
         mMonth  = tms.tm_mon+1;
--- branches/KDE/3.5/kdepim/mimelib/dw_date.cpp #494851:494852
@@ -526,10 +526,6 @@
         if (str[pos+1] == &apos;T&apos; || str[pos+1] == &apos;t&apos;) {
             zone = 0;
         }
-        else {
-            /* Military time zone */
-            zone = 480;
-        }
         break;
     case &apos;G&apos;:
     case &apos;g&apos;:
@@ -537,10 +533,6 @@
             &amp;&amp; (str[pos+2] == &apos;T&apos; || str[pos+2] == &apos;t&apos;)) {
             zone = 0;
         }
-        else {
-            /* Military time zone */
-            zone = -420;
-        }
         break;
     case &apos;E&apos;:
     case &apos;e&apos;:
@@ -552,10 +544,6 @@
             &amp;&amp; (str[pos+2] == &apos;T&apos; || str[pos+2] == &apos;t&apos;)) {
             zone = -240;
         }
-        else {
-            /* Military time zone */
-            zone = -300;
-        }
         break;
     case &apos;C&apos;:
     case &apos;c&apos;:
@@ -567,10 +555,15 @@
             &amp;&amp; (str[pos+2] == &apos;T&apos; || str[pos+2] == &apos;t&apos;)) {
             zone = -300;
         }
-        else {
-            /* Military time zone */
-            zone = -180;
+        else if ((str[pos+1] == &apos;E&apos; || str[pos+1] == &apos;e&apos;)    // allow non-RFC822 &quot;CET&quot;
+            &amp;&amp; (str[pos+2] == &apos;T&apos; || str[pos+2] == &apos;t&apos;)) {
+            zone = 60;
         }
+        else if ((str[pos+1] == &apos;E&apos; || str[pos+1] == &apos;e&apos;)    // allow non-RFC822 &quot;CEST&quot;
+            &amp;&amp; (str[pos+2] == &apos;S&apos; || str[pos+2] == &apos;s&apos;)
+            &amp;&amp; (str[pos+3] == &apos;T&apos; || str[pos+3] == &apos;t&apos;)) {
+            zone = 120;
+        }
         break;
     case &apos;M&apos;:
     case &apos;m&apos;:
@@ -582,10 +575,6 @@
             &amp;&amp; (str[pos+2] == &apos;T&apos; || str[pos+2] == &apos;t&apos;)) {
             zone = -360;
         }
-        else {
-            /* Military time zone */
-            zone = -720;
-        }
         break;
     case &apos;P&apos;:
     case &apos;p&apos;:
@@ -597,10 +586,6 @@
             &amp;&amp; (str[pos+2] == &apos;T&apos; || str[pos+2] == &apos;t&apos;)) {
             zone = -420;
         }
-        else {
-            /* Military time zone */
-            zone = 180;
-        }
         break;
     case &apos;Z&apos;:
         /* Military time zone */
@@ -653,7 +638,16 @@
     return isValid ? 0 : -1;
 }
 
+const char* wdays[] = {
+    &quot;Sun&quot;, &quot;Mon&quot;, &quot;Tue&quot;, &quot;Wed&quot;, &quot;Thu&quot;, &quot;Fri&quot;, &quot;Sat&quot;
+};
 
+const char* months[] = {
+    &quot;Jan&quot;, &quot;Feb&quot;, &quot;Mar&quot;, &quot;Apr&quot;, &quot;May&quot;, &quot;Jun&quot;,
+    &quot;Jul&quot;, &quot;Aug&quot;, &quot;Sep&quot;, &quot;Oct&quot;, &quot;Nov&quot;, &quot;Dec&quot;
+};
+
+
 #ifdef DW_TESTING_DATEPARSER
 
 #include &lt;stdio.h&gt;
@@ -664,15 +658,6 @@
     &quot;&quot;
 };
 
-const char* wdays[] = {
-    &quot;Sun&quot;, &quot;Mon&quot;, &quot;Tue&quot;, &quot;Wed&quot;, &quot;Thu&quot;, &quot;Fri&quot;, &quot;Sat&quot;
-};
-
-const char* months[] = {
-    &quot;Jan&quot;, &quot;Feb&quot;, &quot;Mar&quot;, &quot;Apr&quot;, &quot;May&quot;, &quot;Jun&quot;,
-    &quot;Jul&quot;, &quot;Aug&quot;, &quot;Sep&quot;, &quot;Oct&quot;, &quot;Nov&quot;, &quot;Dec&quot;
-};
-
 int main()
 {
     struct tm *ptms, tms1, tms2;
@@ -723,3 +708,89 @@
 }
 
 #endif
+
+// try to parse a date/time string given in a format not
+// correctly specified in RFC822 format
+// Here we detect the following format:
+// &quot;WWW MMM dd HH:MM:SS [Z] YYYY&quot;  zone is optional
+// e.g.: Fri Oct 14 09:21:49 CEST 2005
+// or:   Tue Mar 23 18:00:02 2004
+
+#include &lt;string.h&gt;
+#include &lt;stdio.h&gt;
+
+#ifdef __cplusplus
+extern &quot;C&quot;
+#endif
+int ParseDate(const char *str, struct tm *tms, int *z)
+{
+    if ( !str )
+      return -1;
+
+    size_t len = strlen(str);
+
+    if ( len &lt; 24 )  // at least &quot;WWW MMM dd HH:MM:SS YYYY&quot;
+      return -1;
+
+    int day=1, month=0, year=1970, hour=0, minute=0, second=0, zone=0;
+    int i;
+
+    for (i = 0; i &lt; 7; i++)
+      if ( strncmp(str, wdays[i], 3) == 0 )
+        break;
+
+    if ( i == 7 )
+      return -1;
+
+    for (i = 0; i &lt; 12; i++)
+      if ( strncmp(str+4, months[i], 3) == 0 )
+        break;
+
+    if ( i == 12 )
+      return -1;
+
+    month = i;
+
+    if ( sscanf(str+8, &quot;%d %d:%d:%d&quot;, &amp;day, &amp;hour, &amp;minute, &amp;second) != 4 )
+      return -1;
+
+    if ( isdigit(str[20]) ) {   // year without zone info, as in ctime()
+      if ( sscanf(str+20, &quot;%d&quot;, &amp;year) != 1 )
+        return -1;
+    }
+    else {
+      if ( sscanf(str+20, &quot;%*s %d&quot;, &amp;year) != 1 )
+        return -1;
+
+      if      ( strncmp(str+20, &quot;EST&quot; , 3) == 0 ) zone = -5 * 60;
+      else if ( strncmp(str+20, &quot;EDT&quot; , 3) == 0 ) zone = -4 * 60;
+      else if ( strncmp(str+20, &quot;CST&quot; , 3) == 0 ) zone = -6 * 60;
+      else if ( strncmp(str+20, &quot;CDT&quot; , 3) == 0 ) zone = -5 * 60;
+      else if ( strncmp(str+20, &quot;MST&quot; , 3) == 0 ) zone = -7 * 60;
+      else if ( strncmp(str+20, &quot;MDT&quot; , 3) == 0 ) zone = -6 * 60;
+      else if ( strncmp(str+20, &quot;PST&quot; , 3) == 0 ) zone = -8 * 60;
+      else if ( strncmp(str+20, &quot;PDT&quot; , 3) == 0 ) zone = -7 * 60;
+      else if ( strncmp(str+20, &quot;CET&quot; , 3) == 0 ) zone = 60;
+      else if ( strncmp(str+20, &quot;CEST&quot;, 4) == 0 ) zone = 120;
+    }
+
+    if ( (day    &lt; 1) || (day    &gt; 31) ||
+         (hour   &lt; 0) || (hour   &gt; 23) ||
+         (minute &lt; 0) || (minute &gt; 59) ||
+         (second &lt; 0) || (second &gt; 59) ||
+         (year   &lt; 1900) )
+      return -1;
+
+    if ( tms ) {
+      tms-&gt;tm_year = year - 1900;
+      tms-&gt;tm_mon  = month;
+      tms-&gt;tm_mday = day;
+      tms-&gt;tm_hour = hour;
+      tms-&gt;tm_min  = minute;
+      tms-&gt;tm_sec  = second;
+    }
+
+    if ( z ) *z = zone;
+
+    return 0;
+}
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>821720</commentid>
    <comment_count>2</comment_count>
    <who name="Martin Koller">martin</who>
    <bug_when>2009-08-30 18:25:12 +0000</bug_when>
    <thetext>*** Bug 115829 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>