From 945b2343595dbd3d9fbd5dd9e145a9de03ba5068 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Wed, 22 Feb 2006 08:56:47 +0000 Subject: Use the same Win32 macro for gmtime_r() that guards against gmtime() 2006-02-21 Tor Lillqvist * em-composer-utils.c: Use the same Win32 macro for gmtime_r() that guards against gmtime() returning NULL as elsewhere. gmtime() is thread-safe on Win32. (attribution_format): Check if camel returns CAMEL_MESSAGE_DATE_CURRENT for Date:, try the date from Received: then. If that doesn't work either, use current date. svn path=/trunk/; revision=31560 --- mail/em-composer-utils.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'mail/em-composer-utils.c') diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c index 583c0ba3a7..f9b1bf9f9c 100644 --- a/mail/em-composer-utils.c +++ b/mail/em-composer-utils.c @@ -56,6 +56,16 @@ #include #include +#ifdef G_OS_WIN32 +/* Undef the similar macro from pthread.h, it doesn't check if + * gmtime() returns NULL. + */ +#undef gmtime_r + +/* The gmtime() in Microsoft's C library is MT-safe */ +#define gmtime_r(tp,tmp) (gmtime(tp)?(*(tmp)=*gmtime(tp),(tmp)):0) +#endif + static EAccount * guess_account (CamelMimeMessage *message, CamelFolder *folder); struct emcs_t { @@ -1716,15 +1726,22 @@ attribution_format (const char *format, CamelMimeMessage *message) str = g_string_new (""); date = camel_mime_message_get_date (message, &tzone); + + if (date == CAMEL_MESSAGE_DATE_CURRENT) { + /* The message has no Date: header, look at Received: */ + date = camel_mime_message_get_date_received (message, &tzone); + } + if (date == CAMEL_MESSAGE_DATE_CURRENT) { + /* That didn't work either, use current time */ + time (&date); + tzone = 0; + } + /* Convert to UTC */ date += (tzone / 100) * 60 * 60; date += (tzone % 100) * 60; -#ifdef HAVE_GMTIME_R gmtime_r (&date, &tm); -#else - memcpy (&tm, gmtime (&date), sizeof (struct tm)); -#endif start = inptr = format; while (*inptr != '\0') { -- cgit v1.2.3