{
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->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;
+}