]> git.notmuchmail.org Git - notmuch/commitdiff
add_message: Use sha-1 in place of overly long message ID.
authorCarl Worth <cworth@cworth.org>
Sun, 22 Nov 2009 03:03:49 +0000 (04:03 +0100)
committerCarl Worth <cworth@cworth.org>
Sun, 22 Nov 2009 03:03:49 +0000 (04:03 +0100)
Since Xapian has a limit on the maximum length of a term, we have
to check for that before trying to add the message ID as a term.

This fixes the bug reported by Mike Hommey here:

<20091120132625.GA19246@glandium.org>

I've also constructed 20 files with a range of message ID lengths
centered around the Xapian term-length limit which I'll use to seed a
new test suite soon.

lib/database.cc

index 169dc5e20df424c67b9db2a092597f299bbc1959..f4a445aa8d4485e0a8419945f687402fa47adfb8 100644 (file)
@@ -892,7 +892,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
 
     const char *date, *header;
     const char *from, *to, *subject;
-    char *message_id;
+    char *message_id = NULL;
 
     if (message_ret)
        *message_ret = NULL;
@@ -937,11 +937,20 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
        header = notmuch_message_file_get_header (message_file, "message-id");
        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. */
            if (message_id == NULL)
                message_id = talloc_strdup (message_file, header);
-       } else {
+
+           /* Reject a Message ID that's too long. */
+           if (message_id && strlen (message_id) + 1 > NOTMUCH_TERM_MAX) {
+               talloc_free (message_id);
+               message_id = NULL;
+           }
+       }
+
+       if (message_id == NULL ) {
            /* No message-id at all, let's generate one by taking a
             * hash over the file's contents. */
            char *sha1 = notmuch_sha1_of_file (filename);