]> git.notmuchmail.org Git - notmuch/commitdiff
lib: clamp return value of g_mime_utils_header_decode_date to >=0
authorDavid Bremner <david@tethera.net>
Sun, 12 Mar 2017 12:51:01 +0000 (09:51 -0300)
committerDavid Bremner <david@tethera.net>
Thu, 16 Mar 2017 00:58:25 +0000 (21:58 -0300)
For reasons not completely understood at this time, gmime (as of
2.6.22) is returning a date before 1900 on bad date input. Since this
confuses some other software, we clamp such dates to 0,
i.e. 1970-01-01.

lib/message.cc
test/T660-bad-date.sh

index 007f11715eb8f97d495f0ed68e1180e9fcc86452..e08659e5d96a15b7564e280cc0716b3d83985516 100644 (file)
@@ -1034,10 +1034,16 @@ _notmuch_message_set_header_values (notmuch_message_t *message,
 
     /* GMime really doesn't want to see a NULL date, so protect its
      * sensibilities. */
-    if (date == NULL || *date == '\0')
+    if (date == NULL || *date == '\0') {
        time_value = 0;
-    else
+    } else {
        time_value = g_mime_utils_header_decode_date (date, NULL);
+       /*
+        * Workaround for https://bugzilla.gnome.org/show_bug.cgi?id=779923
+        */
+       if (time_value < 0)
+           time_value = 0;
+    }
 
     message->doc.add_value (NOTMUCH_VALUE_TIMESTAMP,
                            Xapian::sortable_serialise (time_value));
index 6463d5b8a36d52dc73e56ab1d7de729c2a357442..a98e11c88714aace6ec417d50de92fce2da916cf 100755 (executable)
@@ -5,7 +5,6 @@ test_description="parsing of bad dates"
 add_message [date]='"()"'
 
 test_begin_subtest 'Bad dates translate to a date after the Unix epoch'
-test_subtest_known_broken
 cat <<EOF >EXPECTED
 thread:0000000000000001   1970-01-01 [1/1] Notmuch Test Suite; Test message #1 (inbox unread)
 EOF