workaround a stupid issue in how decoding is performed in mutt *sigh*
[apps/madmutt.git] / lib-mime / rfc822parse.c
index d5614fc..a1b4d54 100644 (file)
@@ -592,20 +592,22 @@ time_t mutt_parse_date(const char *s, HEADER *h)
 {
     struct tm tm;
     const char *loc;
-    loc = setlocale(LC_TIME, "C");
+    time_t tz;
 
+    loc = setlocale(LC_ALL, "C");
     p_clear(&tm, 1);
     if (strptime(s, "%a, %d %b %Y %H:%M:%S %z", &tm))
         goto ok;
     p_clear(&tm, 1);
     if (strptime(s, "%a, %d %b %Y %H:%M %z", &tm))
         goto ok;
-    setlocale(LC_TIME, loc);
+    setlocale(LC_ALL, "");
     return 0;
 
   ok:
-    setlocale(LC_TIME, loc);
-    return mutt_mktime(&tm, 1);
+    setlocale(LC_ALL, "");
+    tz = tm.tm_gmtoff;
+    return timegm(&tm) - tz;
 }
 
 string_list_t **mutt_parse_rfc822_line(ENVELOPE *e, HEADER *hdr, char *line, char *p,
@@ -668,15 +670,6 @@ string_list_t **mutt_parse_rfc822_line(ENVELOPE *e, HEADER *hdr, char *line, cha
             hdr->expired = 1;
         break;
 
-#ifdef USE_NNTP
-      case MIME_FOLLOWUP_TO:
-        if (!e->followup_to) {
-            m_strrtrim(p);
-            e->followup_to = m_strdup(skipspaces(p));
-        }
-        break;
-#endif
-
       case MIME_FROM:
         e->from = rfc822_parse_adrlist(e->from, p);
         /* don't leave from info NULL if there's an invalid address (or
@@ -748,14 +741,6 @@ string_list_t **mutt_parse_rfc822_line(ENVELOPE *e, HEADER *hdr, char *line, cha
             hdr->mime = 1;
         break;
 
-#ifdef USE_NNTP
-      case MIME_NEWSGROUPS:
-        p_delete(&e->newsgroups);
-        m_strrtrim(p);
-        e->newsgroups = m_strdup(skipspaces(p));
-        break;
-#endif
-
       case MIME_ORGANIZATION:
         if (!e->organization && mime_which_token(p, -1) == MIME_UNKNOWN)
             e->organization = m_strdup(p);
@@ -824,13 +809,6 @@ string_list_t **mutt_parse_rfc822_line(ENVELOPE *e, HEADER *hdr, char *line, cha
         e->x_label = m_strdup(p);
         break;
 
-#ifdef USE_NNTP
-      case MIME_XREF:
-        if (!e->xref)
-            e->xref = m_strdup(p);
-        break;
-#endif
-
       case MIME_X_STATUS:
         if (hdr) {
             while (*p) {
@@ -1058,3 +1036,72 @@ int mutt_count_body_parts(HEADER *hdr, int flags)
     hdr->attach_valid = 1;
     return hdr->attach_total;
 }
+
+/*
+ * A valid message separator looks like:
+ *
+ * From [ <return-path> ] <weekday> <month> <day> <time> [ <timezone> ] <year>
+ */
+bool is_from(const char *s, char *path, ssize_t pathlen, time_t *tp)
+{
+    const char *p;
+    struct tm tm;
+    char *loc;
+    int q = 0;
+
+    if (path)
+        *path = 0;
+
+    if (m_strncmp("From ", s, 5) != 0)
+        return false;
+
+    s = skipspaces(s + 5);         /* skip over the From part. */
+    if (!*s)
+        return false;
+
+    for (p = s; *p && (q || !ISSPACE(*p)); p++) {
+        if (*p == '\\') {
+            if (*++p == '\0')
+                return false;
+        }
+        else if (*p == '"') {
+            q = !q;
+        }
+    }
+
+    if (q || !*p)
+        return false;
+
+    if (path)
+        m_strncpy(path, pathlen, s, p - s);
+
+    s = vskipspaces(p + 1);
+    if (!*s)
+        return false;
+
+    loc = setlocale(LC_TIME, "C");
+    for (int i = 0; i < 4; i++) {
+        static char const * const formats[] = {
+            "%a %b %d %H:%M:%S %Y",
+            "%a %b %d %H:%M:%S %z %Y",
+            "%a %b %d %H:%M %Y",
+            "%a %b %d %H:%M %z %Y",
+        };
+
+        p_clear(&tm, 1);
+        p = strptime(s, formats[i], &tm);
+        if (p) {
+            s = p;
+            goto ok;
+        }
+    }
+    setlocale(LC_TIME, loc);
+    return false;
+
+  ok:
+    if (tp) {
+        *tp = tm.tm_gmtoff;
+        *tp = timegm(&tm) - *tp;
+    }
+    return true;
+}