X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-mime%2Frfc822parse.c;h=d2fb218af4e03a2a5ef84aa26f90717732770965;hp=40c84f5dd9142f4aff9ce614fb7fe3a6bd621d2f;hb=e0571c496935f226abe4a22921b5b4e10d1481e8;hpb=9e2951a515b7fe75d244f9388a2ac3f3e3e3a67a diff --git a/lib-mime/rfc822parse.c b/lib-mime/rfc822parse.c index 40c84f5..d2fb218 100644 --- a/lib-mime/rfc822parse.c +++ b/lib-mime/rfc822parse.c @@ -581,23 +581,6 @@ mutt_parse_multipart(FILE *fp, const char *bound, off_t end_off, int digest) return (head); } -static const char * -uncomment_timezone(char *buf, size_t buflen, const char *tz) -{ - char *p; - - if (*tz != '(') - return tz; /* no need to do anything */ - - tz = vskipspaces(tz + 1); - p = strpbrk(tz, " )"); - if (!p) - return tz; - - m_strncpy(buf, buflen, tz, p - tz); - return buf; -} - /* parses a date string in RFC822 format: * * Date: [ weekday , ] day-of-month month year hour:minute:second timezone @@ -607,96 +590,13 @@ uncomment_timezone(char *buf, size_t buflen, const char *tz) */ time_t mutt_parse_date(const char *s, HEADER *h) { - int zhours = 0, zminutes = 0, zoccident = 0; - char scratch[STRING]; struct tm tm; - int count = 0; - char *p; - - /* Don't modify our argument. Fixed-size buffer is ok here since - the date format imposes a natural limit. */ - - m_strcpy(scratch, sizeof(scratch), s); - - /* kill the day of the week, if it exists. */ - p = strchr(scratch, ','); - p = vskipspaces(p ? p + 1 : scratch); - + const char *loc; p_clear(&tm, 1); - - while ((p = strtok (p, " \t")) != NULL) { - char tzstr[STRING]; - const char *ptz; - - switch (count) { - case 0: /* day of the month */ - if (!isdigit((unsigned char)*p)) - return -1; - tm.tm_mday = atoi(p); - if (tm.tm_mday > 31) - return -1; - break; - - case 1: /* month of the year */ - tm.tm_mon = mutt_check_month(p); - if (tm.tm_mon < 0) - return -1; - break; - - case 2: /* year */ - tm.tm_year = atoi(p); - if (tm.tm_year < 50) - tm.tm_year += 100; - else if (tm.tm_year >= 1900) - tm.tm_year -= 1900; - break; - - case 3: /* time of day */ - tm.tm_hour = strtol(p, &p, 10); - if (*p++ != ':') - return -1; - tm.tm_min = strtol(p, &p, 10); - if (*p++ == ':') { - tm.tm_sec = strtol(p, &p, 10); - } else { - tm.tm_sec = 0; - } - break; - - case 4: /* timezone */ - /* sometimes we see things like (MST) or (-0700) so attempt to - * compensate by uncommenting the string if non-RFC822 compliant - */ - ptz = uncomment_timezone(tzstr, sizeof(tzstr), p); - - if (*ptz == '+' || *ptz == '-') { - if (isdigit((unsigned char)ptz[1]) - && isdigit((unsigned char)ptz[2]) - && isdigit((unsigned char)ptz[3]) - && isdigit((unsigned char)ptz[4])) - { - zoccident = ptz[0] == '-'; - zhours = (ptz[1] - '0') * 10 + (ptz[2] - '0'); - zminutes = (ptz[3] - '0') * 10 + (ptz[4] - '0'); - } - } - break; - } - count++; - p = NULL; - } - - if (count < 4) { /* don't check for missing timezone */ - return -1; - } - - if (h) { - h->zhours = zhours; - h->zminutes = zminutes; - h->zoccident = zoccident; - } - - return mutt_mktime(&tm, 0) + (zoccident ? 1 : -1) * (zhours * 3600 + zminutes * 60); + loc = setlocale(LC_TIME, "C"); + s = strptime(s, "%a, %d %b %Y %T %z", &tm); + setlocale(LC_TIME, loc); + return mutt_mktime(&tm, 1); } string_list_t **mutt_parse_rfc822_line(ENVELOPE *e, HEADER *hdr, char *line, char *p,