From: Tomi Ollila <tomi.ollila@iki.fi>
To: David Bremner <david@tethera.net>,
Johannes Schauer <j.schauer@email.de>,
notmuch@notmuchmail.org
Subject: Re: [PATCH 2/2] lib: clamp return value of g_mime_utils_header_decode_date to >=0
Date: Wed, 15 Mar 2017 22:09:18 +0200 [thread overview]
Message-ID: <m2shmel2tt.fsf@guru.guru-group.fi> (raw)
In-Reply-To: <20170312125101.21656-2-david@tethera.net>
On Sun, Mar 12 2017, David Bremner <david@tethera.net> wrote:
> 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 | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/lib/message.cc b/lib/message.cc
> index 007f1171..8a8a25b4 100644
> --- a/lib/message.cc
> +++ b/lib/message.cc
> @@ -1034,10 +1034,15 @@ _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;
"Too bad" we already do this time_value = 0, otherwise I'd suggested
-2111111111
$ perl -le 'print scalar localtime -2111111111'
Sat Feb 7 21:54:38 1903
That is something where Julian calendar is also in 20th century ;)
> - else
> + } else {
> time_value = g_mime_utils_header_decode_date (date, NULL);
> + /*
> + * Workaround for https://bugzilla.gnome.org/show_bug.cgi?id=779923
> + */
> + time_value = (time_value < 0) ? 0 : time_value;
Although the above probably realizes as..., I'd propose (IMO for clarity)
if (time_value < 0)
time_value = 0;
Anyway, LGTM.
Tomi
Btw: I Added notmuch show --format=json '*' >&6 to the test script, and it
printed:
[[[{"id": "msg-001@notmuch-test-suite", "match": true, "excluded": false,
"filename": ["/home/too/vc/ext/notmuch/test/tmp.T111-x/mail/msg-001"],
"timestamp": 2085892096, "date_relative": "1899-12-31", "tags": ["inbox",
"unread"], "headers": {"Subject": "Test message #1", "From": "Notmuch Test
Suite <test_suite@notmuchmail.org>", "To": "Notmuch Test Suite
<test_suite@notmuchmail.org>", "Date": "Sun, 31 Dec 1899 00:00:00 +0000"},
"body": [{"id": 1, "content-type": "text/plain", "content": "This is just a
test message (#1)\n"}]}, []]]]
(... which one can see I just pasted to a new file... ;)
$ perl -le 'print scalar localtime 2085892096'
Wed Feb 6 08:28:16 2036
So, it looks like we store the large negative time_value to a 32-bit signed
integer...
> + }
>
> message->doc.add_value (NOTMUCH_VALUE_TIMESTAMP,
> Xapian::sortable_serialise (time_value));
> --
> 2.11.0
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch
next prev parent reply other threads:[~2017-03-15 20:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-22 6:56 bug: notmuch cannot handle invalid Date fields Johannes Schauer
2015-04-22 13:37 ` Tomi Ollila
2015-04-22 13:42 ` Johannes Schauer
2017-03-12 1:38 ` David Bremner
2017-03-12 12:51 ` [PATCH 1/2] lib: add known broken test for parsing bad dates David Bremner
2017-03-12 12:51 ` [PATCH 2/2] lib: clamp return value of g_mime_utils_header_decode_date to >=0 David Bremner
2017-03-15 20:09 ` Tomi Ollila [this message]
2017-03-16 1:16 ` David Bremner
2017-03-19 12:31 ` bug: notmuch cannot handle invalid Date fields David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2shmel2tt.fsf@guru.guru-group.fi \
--to=tomi.ollila@iki.fi \
--cc=david@tethera.net \
--cc=j.schauer@email.de \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).