From: Pierre Habouzit Date: Thu, 16 Aug 2007 00:03:48 +0000 (+0200) Subject: Use str[pf]time. X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=e0571c496935f226abe4a22921b5b4e10d1481e8;p=apps%2Fmadmutt.git Use str[pf]time. Signed-off-by: Pierre Habouzit --- diff --git a/imap/util.c b/imap/util.c index 230f005..16aa75f 100644 --- a/imap/util.c +++ b/imap/util.c @@ -256,38 +256,15 @@ char *imap_next_word (char *s) /* imap_parse_date: date is of the form: DD-MMM-YYYY HH:MM:SS +ZZzz */ time_t imap_parse_date (char *s) { - struct tm t; - time_t tz; - - t.tm_mday = strtol(s, &s, 10); - if (*s++ != '-') - return 0; - t.tm_mon = mutt_check_month(s); - s += 3; - if (*s++ != '-') - return 0; - t.tm_year = strtol(s, &s, 10) - 1900; - if (*s++ != ' ') - return 0; - - /* time */ - t.tm_hour = strtol(s, &s, 10); - if (*s++ != ':') - return 0; - t.tm_min = strtol(s, &s, 10); - if (*s++ != ':') - return 0; - t.tm_sec = strtol(s, &s, 10); - if (*s++ != ' ') - return 0; - - /* timezone */ - tz = strtol(s + 1, NULL, 10); - tz = (tz / 100) * 3600 + (tz % 100) * 60; - if (s[0] == '+') - tz = -tz; - - return (mutt_mktime (&t, 0) + tz); + struct tm tm; + const char *loc; + time_t tz; + + p_clear(&tm, 1); + loc = setlocale(LC_TIME, "C"); + strptime(s, "%d-%b-%Y %T %z", &tm); + setlocale(LC_TIME, loc); + return mutt_mktime(&tm, 1); } /* imap_qualify_path: make an absolute IMAP folder target, given IMAP_MBOX 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, diff --git a/lib-sys/mutt_ssl.cpkg b/lib-sys/mutt_ssl.cpkg index 3717ba4..17556c3 100644 --- a/lib-sys/mutt_ssl.cpkg +++ b/lib-sys/mutt_ssl.cpkg @@ -429,16 +429,18 @@ static void tls_fingerprint (gnutls_digest_algorithm algo, static char *tls_make_date (time_t t, char *s, ssize_t len) { - struct tm *l = gmtime (&t); - - if (l) - snprintf (s, len, "%s, %d %s %d %02d:%02d:%02d UTC", - Weekdays[l->tm_wday], l->tm_mday, Months[l->tm_mon], - l->tm_year + 1900, l->tm_hour, l->tm_min, l->tm_sec); - else - m_strcpy(s, len, _("[invalid date]")); + struct tm *l = gmtime(&t); + + if (l) { + const char *loc; + loc = setlocale(LC_TIME, "C"); + strftime(s, len, "%a, %d %b %Y %T UTC", l); + setlocale(LC_TIME, loc); + } else { + m_strcpy(s, len, _("[invalid date]")); + } - return (s); + return (s); } static int tls_check_stored_hostname (const gnutls_datum * cert, diff --git a/sendlib.c b/sendlib.c index 3196347..9881bbe 100644 --- a/sendlib.c +++ b/sendlib.c @@ -1248,17 +1248,13 @@ BODY *mutt_remove_multipart (BODY * b) char *mutt_make_date (char *s, ssize_t len) { - time_t t = time (NULL); - struct tm *l = localtime (&t); - time_t tz = mutt_local_tz (t); + time_t t = time(NULL); + const char *loc; - tz /= 60; - - snprintf (s, len, "Date: %s, %d %s %d %02d:%02d:%02d %+03d%02d\n", - Weekdays[l->tm_wday], l->tm_mday, Months[l->tm_mon], - l->tm_year + 1900, l->tm_hour, l->tm_min, l->tm_sec, - (int) tz / 60, (int) abs (tz) % 60); - return (s); + loc = setlocale(LC_TIME, "C"); + strftime(s, len, "Date: %a, %d %b %Y %T %z\n", localtime(&t)); + setlocale(LC_TIME, loc); + return s; } /* wrapper around mutt_write_address() so we can handle very large