}
p_delete(&line);
- return (body);
+ return body;
}
void mutt_parse_part(FILE *fp, BODY *b)
mutt_parse_part(fp, b);
}
- return (head);
+ return head;
}
/* parses a date string in RFC822 format:
{
struct tm tm;
const char *loc;
+ time_t tz;
+
+ loc = setlocale(LC_ALL, "C");
p_clear(&tm, 1);
- loc = setlocale(LC_TIME, "C");
- s = strptime(s, "%a, %d %b %Y %T %z", &tm);
- setlocale(LC_TIME, loc);
- return mutt_mktime(&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_ALL, "");
+ return 0;
+
+ ok:
+ 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,
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
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);
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) {
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;
+}