>From 52292c548512214fd3dd205edb4ca9cf7955f2b3 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Fri, 20 Nov 2009 19:31:00 +0100 Subject: [PATCH 1/3] add_message: Properly handle missing Message-ID once again. There's been a fair amount of fallout from when we changed message_file_get_header from returning NULL to returning "" for missing headers. This is yet more fallout from that, (where we were accepting an empty message-ID rather than generating one like we want to). --- lib/database.cc | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/lib/database.cc b/lib/database.cc index 726c5a9..294247e 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -908,7 +908,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch, * is to find a message ID (or else create one ourselves). */ header = notmuch_message_file_get_header (message_file, "message-id"); - if (header) { + if (header && *header != '\0') { message_id = _parse_message_id (message_file, header, NULL); /* So the header value isn't RFC-compliant, but it's * better than no message-id at all. */ -- 1.6.5.2 >From 656e4c413d84984dcc5fbd8016907ed03c343cb8 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Fri, 20 Nov 2009 21:02:11 +0100 Subject: [PATCH 2/3] notmuch_database_add_message: Add missing error-value propagation. Thanks to Mike Hommey for doing the analysis that led to noticing that this was missing. --- lib/database.cc | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/lib/database.cc b/lib/database.cc index 294247e..58a350d 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -940,8 +940,11 @@ notmuch_database_add_message (notmuch_database_t *notmuch, talloc_free (message_id); - if (message == NULL) + if (message == NULL) { + ret = COERCE_STATUS (private_status, + "Unexpected status value from _notmuch_message_create_for_message_id"); goto DONE; + } /* Is this a newly created message object? */ if (private_status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND) { -- 1.6.5.2 >From 3ae12b1e286d1c0041a2e3957cb01daa2981dad9 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Fri, 20 Nov 2009 21:46:37 +0100 Subject: [PATCH 3/3] add_message: Re-fix handling of non-mail files. More fallout from _get_header now returning "" for missing headers. The bug here is that we would no longer detect that a file is not an email message and give up on it like we should. And this time, I actually audited all callers to notmuch_message_get_header, so hopefully we're done fixing this bug over and over. --- lib/database.cc | 10 +++++----- lib/message.cc | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/database.cc b/lib/database.cc index 58a350d..207246c 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -323,7 +323,7 @@ _parse_message_id (void *ctx, const char *message_id, const char **next) const char *s, *end; char *result; - if (message_id == NULL) + if (message_id == NULL || *message_id == '\0') return NULL; s = message_id; @@ -391,7 +391,7 @@ parse_references (void *ctx, { char *ref; - if (refs == NULL) + if (refs == NULL || *refs == '\0') return; while (*refs) { @@ -896,9 +896,9 @@ notmuch_database_add_message (notmuch_database_t *notmuch, subject = notmuch_message_file_get_header (message_file, "subject"); to = notmuch_message_file_get_header (message_file, "to"); - if (from == NULL && - subject == NULL && - to == NULL) + if ((from == NULL || *from == '\0') && + (subject == NULL || *subject == '\0') && + (to == NULL || *to == '\0')) { ret = NOTMUCH_STATUS_FILE_NOT_EMAIL; goto DONE; diff --git a/lib/message.cc b/lib/message.cc index 41dddd0..e0b8a8e 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -491,7 +491,7 @@ _notmuch_message_set_date (notmuch_message_t *message, /* GMime really doesn't want to see a NULL date, so protect its * sensibilities. */ - if (date == NULL) + if (date == NULL || *date == '\0') time_value = 0; else time_value = g_mime_utils_header_decode_date (date, NULL); -- 1.6.5.2