From: Alfons Hoogervorst Date: Sun, 19 May 2002 11:45:31 +0000 (+0000) Subject: better quotation formatting - does not convert to local time, but uses the original... X-Git-Tag: rel_0_7_7~63 X-Git-Url: http://git.claws-mail.org/?p=claws.git;a=commitdiff_plain;h=991952d75b979d306ed53a1546ab452f6d9ef2b1 better quotation formatting - does not convert to local time, but uses the original date string. --- diff --git a/ChangeLog.claws b/ChangeLog.claws index a57e79d12..5804d318d 100644 --- a/ChangeLog.claws +++ b/ChangeLog.claws @@ -1,3 +1,17 @@ +2002-05-19 [alfons] 0.7.6claws5 + + * src/procheader.c + * src/procheader.h + add function for returning ime zone offset + * src/quote_fmt.c + * src/quote_fmt_parse.y + better quotation formatting - does not convert + to local time, but uses the original date string. + + Note: %z inserts the timezone offset (should + work also on platforms where strftime does not + support %z). + 2002-05-18 [christoph] 0.7.6claws4 * src/summaryview.c diff --git a/configure.in b/configure.in index ed2eb2dd4..7a392678f 100644 --- a/configure.in +++ b/configure.in @@ -8,7 +8,7 @@ MINOR_VERSION=7 MICRO_VERSION=6 INTERFACE_AGE=0 BINARY_AGE=0 -EXTRA_VERSION=claws4 +EXTRA_VERSION=claws5 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION dnl set $target diff --git a/src/procheader.c b/src/procheader.c index 93fc862c5..36084cc2c 100644 --- a/src/procheader.c +++ b/src/procheader.c @@ -734,6 +734,62 @@ static gint procheader_scan_date_string(const gchar *str, return -1; } +/* + * Hiro, most UNIXen support this function: + * http://www.mcsr.olemiss.edu/cgi-bin/man-cgi?getdate + */ +gboolean procheader_date_parse_to_tm(const gchar *src, struct tm *t, char *zone) +{ + static gchar monthstr[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; + gchar weekday[11]; + gint day; + gchar month[10]; + gint year; + gint hh, mm, ss; + GDateMonth dmonth; + gchar *p; + time_t timer; + + if (!t) + return FALSE; + + memset(t, 0, sizeof *t); + + if (procheader_scan_date_string(src, weekday, &day, month, &year, + &hh, &mm, &ss, zone) < 0) { + g_warning("Invalid date: %s\n", src); + return FALSE; + } + + /* Y2K compliant :) */ + if (year < 100) { + if (year < 70) + year += 2000; + else + year += 1900; + } + + month[3] = '\0'; + if ((p = strstr(monthstr, month)) != NULL) + dmonth = (gint)(p - monthstr) / 3 + 1; + else { + g_warning("Invalid month: %s\n", month); + dmonth = G_DATE_BAD_MONTH; + } + + t->tm_sec = ss; + t->tm_min = mm; + t->tm_hour = hh; + t->tm_mday = day; + t->tm_mon = dmonth - 1; + t->tm_year = year - 1900; + t->tm_wday = 0; + t->tm_yday = 0; + t->tm_isdst = -1; + + return TRUE; +} + time_t procheader_date_parse(gchar *dest, const gchar *src, gint len) { static gchar monthstr[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; diff --git a/src/procheader.h b/src/procheader.h index 90f7b473c..6021380c1 100644 --- a/src/procheader.h +++ b/src/procheader.h @@ -71,6 +71,10 @@ MsgInfo *procheader_file_parse (FILE *fp, gchar *procheader_get_fromname (const gchar *str); +gboolean procheader_date_parse_to_tm (const gchar *str, + struct tm *t, + char *zone); + time_t procheader_date_parse (gchar *dest, const gchar *src, gint len); diff --git a/src/quote_fmt.c b/src/quote_fmt.c index 45779cf8c..ac2da0576 100644 --- a/src/quote_fmt.c +++ b/src/quote_fmt.c @@ -36,6 +36,7 @@ static void quote_fmt_quote_description_key_pressed (GtkWidget *widget, static gchar *symbol_table[][2] = { + {"%D{fmt}", N_("Customize date format (see man strftime)")}, /* date expression */ {"%d", N_("Date")}, /* date */ {"%f", N_("From")}, /* from */ {"%N", N_("Full Name of Sender")}, /* full name */ diff --git a/src/quote_fmt_parse.y b/src/quote_fmt_parse.y index 2f3ec9a43..9f5e6f634 100644 --- a/src/quote_fmt_parse.y +++ b/src/quote_fmt_parse.y @@ -9,6 +9,7 @@ #include "procmime.h" #include "utils.h" #include "intl.h" +#include "procheader.h" #include "quote_fmt.h" #include "quote_fmt_lex.h" @@ -194,14 +195,64 @@ special: } | SHOW_DATE_EXPR OPARENT string CPARENT { - if (msginfo->date_t) { - char timef[128]; - struct tm *lt; - - if (NULL != (lt = localtime(&msginfo->date_t))) { - strftime(timef, sizeof timef, $3, lt); - INSERT(timef); + /* + * ALF - GNU C's strftime() has a nice format specifier + * for time zone offset (%z). Non-standard however, so + * emulate it. + */ + if (msginfo->date) { + char result[100]; + char *rptr; + char zone[6]; + struct tm lt; + const char *fptr; + const char *zptr; + +#define RLEFT (sizeof result) - (rptr - result) +#define STR_SIZE(x) (sizeof (x) - 1) + + zone[0] = 0; + + if (procheader_date_parse_to_tm(msginfo->date, <, zone)) { + /* + * break up format string in tiny bits delimited by valid %z's and + * feed it to strftime(). don't forget that '%%z' mean literal '%z'. + */ + for (rptr = result, fptr = $3; fptr && *fptr && rptr < &result[sizeof result - 1];) { + int perc; + const char *p; + char *tmp; + + if (NULL != (zptr = strstr(fptr, "%z"))) { + /* + * count nr. of prepended percent chars + */ + for (perc = 0, p = zptr; p && p >= $3 && *p == '%'; p--, perc++) + ; + /* + * feed to strftime() + */ + tmp = g_strndup(fptr, zptr - fptr + (perc % 2 ? 0 : STR_SIZE("%z"))); + if (tmp) { + rptr += strftime(rptr, RLEFT, tmp, <); + g_free(tmp); + } + /* + * append time zone offset + */ + if (zone[0] && perc % 2) + rptr += g_snprintf(rptr, RLEFT, "%s", zone); + fptr = zptr + STR_SIZE("%z"); + } else { + rptr += strftime(rptr, RLEFT, fptr, <); + fptr = NULL; + } + } + + INSERT(result); } +#undef STR_SIZE +#undef RLEFT } } | SHOW_DATE