]> git.notmuchmail.org Git - notmuch/commitdiff
lib: Move message ID compression to _notmuch_message_create_for_message_id
authorAustin Clements <amdragon@mit.edu>
Mon, 6 Oct 2014 23:17:07 +0000 (17:17 -0600)
committerDavid Bremner <david@tethera.net>
Sat, 11 Oct 2014 05:09:54 +0000 (07:09 +0200)
Previously, this was performed by notmuch_database_add_message.  This
happens to be the only caller currently (which is why this was safe),
but we're about to introduce more callers, and it makes more sense to
put responsibility for ID compression in the lower-level function
rather than requiring each caller to handle it.

lib/database.cc
lib/message.cc
lib/notmuch-private.h

index a47a71d56d90ec2e017a54dab93fd3305e43f90e..4e687060c09d52cb5dce8024958f61eb79a99678 100644 (file)
@@ -390,8 +390,8 @@ find_document_for_doc_id (notmuch_database_t *notmuch, unsigned doc_id)
  *
  *     notmuch-sha1-<sha1_sum_of_message_id>
  */
-static char *
-_message_id_compressed (void *ctx, const char *message_id)
+char *
+_notmuch_message_id_compressed (void *ctx, const char *message_id)
 {
     char *sha1, *compressed;
 
@@ -415,7 +415,7 @@ notmuch_database_find_message (notmuch_database_t *notmuch,
        return NOTMUCH_STATUS_NULL_POINTER;
 
     if (strlen (message_id) > NOTMUCH_MESSAGE_ID_MAX)
-       message_id = _message_id_compressed (notmuch, message_id);
+       message_id = _notmuch_message_id_compressed (notmuch, message_id);
 
     try {
        status = _notmuch_database_find_unique_doc_id (notmuch, "id",
@@ -1728,7 +1728,7 @@ static char *
 _get_metadata_thread_id_key (void *ctx, const char *message_id)
 {
     if (strlen (message_id) > NOTMUCH_MESSAGE_ID_MAX)
-       message_id = _message_id_compressed (ctx, message_id);
+       message_id = _notmuch_message_id_compressed (ctx, message_id);
 
     return talloc_asprintf (ctx, NOTMUCH_METADATA_THREAD_ID_PREFIX "%s",
                            message_id);
@@ -2100,14 +2100,6 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
             * better than no message-id at all. */
            if (message_id == NULL)
                message_id = talloc_strdup (message_file, header);
-
-           /* If a message ID is too long, substitute its sha1 instead. */
-           if (message_id && strlen (message_id) > NOTMUCH_MESSAGE_ID_MAX) {
-               char *compressed = _message_id_compressed (message_file,
-                                                          message_id);
-               talloc_free (message_id);
-               message_id = compressed;
-           }
        }
 
        if (message_id == NULL ) {
index 7e825480ecc6e5782a93113e13b0e9730fac96fc..bbfc2500bd92f12dfade22db471fb6b22bf9613b 100644 (file)
@@ -226,6 +226,10 @@ _notmuch_message_create_for_message_id (notmuch_database_t *notmuch,
     else if (*status_ret)
        return NULL;
 
+    /* If the message ID is too long, substitute its sha1 instead. */
+    if (strlen (message_id) > NOTMUCH_MESSAGE_ID_MAX)
+       message_id = _notmuch_message_id_compressed (message, message_id);
+
     term = talloc_asprintf (NULL, "%s%s",
                            _find_prefix ("id"), message_id);
     if (term == NULL) {
index 17f30613bd00509e912d594101d21b7f587aae4d..36cc12b0df123c7a0eb79c0d81f8b40db9650d79 100644 (file)
@@ -174,6 +174,9 @@ typedef struct _notmuch_doc_id_set notmuch_doc_id_set_t;
 const char *
 _find_prefix (const char *name);
 
+char *
+_notmuch_message_id_compressed (void *ctx, const char *message_id);
+
 notmuch_status_t
 _notmuch_database_ensure_writable (notmuch_database_t *notmuch);