Index: hdrline.c =================================================================== --- hdrline.c (revision 802) +++ hdrline.c (working copy) @@ -302,11 +302,11 @@ case '(': case '<': - /* preprocess $date_format to handle %Z */ + /* preprocess $date_format to handle %Z and %Q,%q */ { const char *cp; - struct tm *tm; - time_t T; + struct tm *tm, *TM; + time_t t, T; p = dest; @@ -318,6 +318,28 @@ else do_locales = 1; + if (do_locales && Locale) + setlocale (LC_TIME, Locale); + + tm = alloca(sizeof(struct tm)); + if (op == '[' || op == 'D') + tm = localtime_r (&hdr->date_sent, tm); + else if (op == '(') + tm = localtime_r (&hdr->received, tm); + else if (op == '<') { + T = time (NULL); + tm = localtime_r (&T, tm); + } + else { + /* restore sender's time zone */ + T = hdr->date_sent; + if (hdr->zoccident) + T -= (hdr->zhours * 3600 + hdr->zminutes * 60); + else + T += (hdr->zhours * 3600 + hdr->zminutes * 60); + tm = gmtime_r (&T, tm); + } + len = destlen - 1; while (len > 0 && (((op == 'd' || op == 'D') && *cp) || (op == '{' && *cp != '}') || @@ -335,6 +357,43 @@ } else break; /* not enough space left */ + } else if (*cp == 'Q' || *cp == 'q') { + t = mktime (tm); + T = time (NULL); + TM = localtime (&T); + + if (len < 6) + break; /* not enough space left */ + + /* figure out what the date format should be: + * if the message is in the future: treat as if it were in + * the past + * if the message was within the last 12 hours: "%k:%M " + * if the message was within the last 7 days: "%a-%d" + * if the message was within the last 12 months: "%d-%b" + * if the message is older than a year: "%b-%y" + */ + + if (t > T) /* future: reverse */ + t -= 2 * (t - T); + + if (t > T - 43200) { /* 12 hours */ + sprintf (p, "%s", "%H:%M "); + p += 1; + len -= 1; + } + else if (t >= T - 518400) { /* 6 days */ + sprintf (p, "%s", "%a-%d"); + } + else if (((TM->tm_year - tm->tm_year) * 12 + TM->tm_mon) - + tm->tm_mon < 12) { /* last 11 months */ + sprintf (p, "%s", "%d-%b"); + } + else { /* older than a year */ + sprintf (p, "%s", "%b-%y"); + } + p += 5; + len -= 5; } else { if (len >= 2) { @@ -354,27 +413,6 @@ } *p = 0; - if (do_locales && Locale) - setlocale (LC_TIME, Locale); - - if (op == '[' || op == 'D') - tm = localtime (&hdr->date_sent); - else if (op == '(') - tm = localtime (&hdr->received); - else if (op == '<') { - T = time (NULL); - tm = localtime (&T); - } - else { - /* restore sender's time zone */ - T = hdr->date_sent; - if (hdr->zoccident) - T -= (hdr->zhours * 3600 + hdr->zminutes * 60); - else - T += (hdr->zhours * 3600 + hdr->zminutes * 60); - tm = gmtime (&T); - } - strftime (buf2, sizeof (buf2), dest, tm); if (do_locales) @@ -751,3 +789,4 @@ mutt_FormatString (dest, destlen, s, hdr_format_str, (unsigned long) &hfi, flags); } +/* vim:set expandtab sw=2 ts=2: */