better quotation formatting - does not convert to local time, but uses the original...
authorAlfons Hoogervorst <alfons@proteus.demon.nl>
Sun, 19 May 2002 11:45:31 +0000 (11:45 +0000)
committerAlfons Hoogervorst <alfons@proteus.demon.nl>
Sun, 19 May 2002 11:45:31 +0000 (11:45 +0000)
ChangeLog.claws
configure.in
src/procheader.c
src/procheader.h
src/quote_fmt.c
src/quote_fmt_parse.y

index a57e79d121d7482b54abc8ae5d53e6990b8742c1..5804d318dbd9cdd132741956a2b158089bc53623 100644 (file)
@@ -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
index ed2eb2dd429bf85bd4d42e56d673ab40142691ad..7a392678faf7858f44b67729f0ec75978e6823d9 100644 (file)
@@ -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
index 93fc862c5f5f1806127f43d2daa4d4d7e99ce6c9..36084cc2cfe04db94ea1d2ac37265849fb48f9b3 100644 (file)
@@ -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";
index 90f7b473c8c137a01b5ea339df603b1be512c420..6021380c1c50df517e78f548d879c802302d9142 100644 (file)
@@ -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);
index 45779cf8ce337f276ddc717c3ecfbadf267c5dc6..ac2da0576c0767a4cef2299296597e423d59ed44 100644 (file)
@@ -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 */
index 2f3ec9a4305e760058b3a49c36ebab3806b529c2..9f5e6f634d398566aa1e952f43b89d8b506818f8 100644 (file)
@@ -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, &lt, 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, &lt);
+                                                       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, &lt);
+                                               fptr  = NULL;
+                                       }
+                               }
+                               
+                               INSERT(result);
                        }
+#undef STR_SIZE                        
+#undef RLEFT                   
                }
        }
        | SHOW_DATE