From 62822a4e2dee695c486383f0fe3d90edafae24db Mon Sep 17 00:00:00 2001 From: David Bremner Date: Sun, 12 Mar 2017 09:51:01 -0300 Subject: [PATCH] lib: clamp return value of g_mime_utils_header_decode_date to >=0 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 | 10 ++++++++-- test/T660-bad-date.sh | 1 - 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/message.cc b/lib/message.cc index 007f1171..e08659e5 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -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)); diff --git a/test/T660-bad-date.sh b/test/T660-bad-date.sh index 6463d5b8..a98e11c8 100755 --- a/test/T660-bad-date.sh +++ b/test/T660-bad-date.sh @@ -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 <EXPECTED thread:0000000000000001 1970-01-01 [1/1] Notmuch Test Suite; Test message #1 (inbox unread) EOF -- 2.26.2