Improvement to replying to messages without Date:

Tor Lillqvist <[email protected]>
Newsgroups gmane.comp.gnome.evolution.patches
Message-ID <1140510964.2916.23.camel@pettson>
When replying to a message without Date: header,
camel_mime_message_get_date() returns CAMEL_MESSAGE_DATE_CURRENT (-1).
attribution_format() in em-composer-utils.c does not check for this, and
proceeds to pass this bogus time to gmtime_r(). (Which presumably on
most Unixes is interpreted as one second before the Unix epoch. The
Win32 gmtime() returns NULL when given a -1, though... which is what
made me notice this.)

It would be better to then just return an attribution without date like
"${Sender} wrote:", but as we are in a string freeze, a workaround is to
look for the Received: headers instead.

OK to commit?

--tml

_______________________________________________
Evolution-patches mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/evolution-patches
mail.diff (text/x-patch, 2.3 KB)
? mail/em-folder-view.c.THREAD-HACK
? mail/em-migrate.c.HUUH
? mail/mail.error
? mail/message-list.c.THREAD-HACK
? mail/message-list.h.THREAD-HACK
Index: mail/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/mail/ChangeLog,v
retrieving revision 1.3806
diff -p -u -2 -r1.3806 ChangeLog
--- mail/ChangeLog	20 Feb 2006 16:01:00 -0000	1.3806
+++ mail/ChangeLog	21 Feb 2006 08:13:48 -0000
@@ -1,2 +1,11 @@
+2006-02-21  Tor Lillqvist  <[email protected]>
+
+	* 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.
+
 2006-02-20  Srinivasa Ragavan <[email protected]>
 
Index: mail/em-composer-utils.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/em-composer-utils.c,v
retrieving revision 1.51
diff -p -u -2 -r1.51 em-composer-utils.c
--- mail/em-composer-utils.c	8 Feb 2006 11:51:31 -0000	1.51
+++ mail/em-composer-utils.c	21 Feb 2006 08:13:50 -0000
@@ -57,4 +57,14 @@
 #include <camel/camel-vee-folder.h>
 
+#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);
 
@@ -1717,13 +1727,20 @@ attribution_format (const char *format, 
 	
 	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;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.