--- /dev/null
+Return-Path: <aclements@csail.mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 1E51C431FCF\r
+ for <notmuch@notmuchmail.org>; Fri, 3 Oct 2014 07:20:19 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.3\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id BZSI2emUxEFO for <notmuch@notmuchmail.org>;\r
+ Fri, 3 Oct 2014 07:20:11 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-8.mit.edu (dmz-mailsec-scanner-8.mit.edu\r
+ [18.7.68.37])\r
+ (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 8B405431FDE\r
+ for <notmuch@notmuchmail.org>; Fri, 3 Oct 2014 07:19:36 -0700 (PDT)\r
+X-AuditID: 12074425-f79e46d000002583-44-542eb0751d50\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+ (using TLS with cipher AES256-SHA (256/256 bits))\r
+ (Client did not present a certificate)\r
+ by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id 91.28.09603.570BE245; Fri, 3 Oct 2014 10:19:33 -0400 (EDT)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+ by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id s93EJNje020194; \r
+ Fri, 3 Oct 2014 10:19:23 -0400\r
+Received: from drake.dyndns.org\r
+ (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+ [216.15.114.40]) (authenticated bits=0)\r
+ (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+ by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s93EJLwW023306\r
+ (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT);\r
+ Fri, 3 Oct 2014 10:19:22 -0400\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.84)\r
+ (envelope-from <aclements@csail.mit.edu>)\r
+ id 1Xa3hY-0002JY-VT; Fri, 03 Oct 2014 10:19:20 -0400\r
+From: Austin Clements <aclements@csail.mit.edu>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 01/11] lib: Move message ID compression to\r
+ _notmuch_message_create_for_message_id\r
+Date: Fri, 3 Oct 2014 10:19:08 -0400\r
+Message-Id: <1412345958-8278-2-git-send-email-aclements@csail.mit.edu>\r
+X-Mailer: git-send-email 2.1.0\r
+In-Reply-To: <1412345958-8278-1-git-send-email-aclements@csail.mit.edu>\r
+References: <1412345958-8278-1-git-send-email-aclements@csail.mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFlrPIsWRmVeSWpSXmKPExsUixG6nrlu6QS/EoLXBwuL6zZnMDowez1bd\r
+ Yg5gjOKySUnNySxLLdK3S+DKWPlXr2CbVMWT+RtYGxiPi3YxcnJICJhIPD98nw3CFpO4cG89\r
+ mC0kMJtJYt+9ui5GLiB7A6NE+83jzBCJ20wSC9/KQiSWMEq83NjPCJJgE9CXWLF2EiuILSIg\r
+ LbHz7mwgm4ODWUBN4k+XCogpLJAoMXlSDUgFi4CqxJE9rWDVvAJuEld3TmSBuEFOYsPu/2AT\r
+ OQXcJS7cfQp1j5vEqmPdbBMY+RcwMqxilE3JrdLNTczMKU5N1i1OTszLSy3StdDLzSzRS00p\r
+ 3cQIDhcX1R2MEw4pHWIU4GBU4uH9eEM3RIg1say4MvcQoyQHk5Iob+VivRAhvqT8lMqMxOKM\r
+ +KLSnNTiQ4wSHMxKIrwLVgLleFMSK6tSi/JhUtIcLErivJt+8IUICaQnlqRmp6YWpBbBZGU4\r
+ OJQkeLmAcSEkWJSanlqRlplTgpBm4uAEGc4DNLx9Pcjw4oLE3OLMdIj8KUZFKXFeUZBmAZBE\r
+ RmkeXC8snl8xigO9IszLBFLFA0wFcN2vgAYzAQ1+Z68LMrgkESEl1cB4YbMg++NiDzuVf8Gc\r
+ daJ1y5js9wtbTsyIPVS9wvJPro346ndnPRmeaDzneHauzfP9+4/H5EKeCm75N+2/o7RvVs8R\r
+ DafEdtajFUHpjT96pjtNMi1av3CZqO9Spr3zD9d++hza8iCiJoHPWGu36+qzviuu+QieWjZX\r
+ 6+Oq2yFVzc+X6U9qbPinxFKckWioxVxUnAgAtz0vOsICAAA=\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 03 Oct 2014 14:20:19 -0000\r
+\r
+From: Austin Clements <amdragon@mit.edu>\r
+\r
+Previously, this was performed by notmuch_database_add_message. This\r
+happens to be the only caller currently (which is why this was safe),\r
+but we're about to introduce more callers, and it makes more sense to\r
+put responsibility for ID compression in the lower-level function\r
+rather than requiring each caller to handle it.\r
+---\r
+ lib/database.cc | 16 ++++------------\r
+ lib/message.cc | 4 ++++\r
+ lib/notmuch-private.h | 3 +++\r
+ 3 files changed, 11 insertions(+), 12 deletions(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index a47a71d..4e68706 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -390,8 +390,8 @@ find_document_for_doc_id (notmuch_database_t *notmuch, unsigned doc_id)\r
+ *\r
+ * notmuch-sha1-<sha1_sum_of_message_id>\r
+ */\r
+-static char *\r
+-_message_id_compressed (void *ctx, const char *message_id)\r
++char *\r
++_notmuch_message_id_compressed (void *ctx, const char *message_id)\r
+ {\r
+ char *sha1, *compressed;\r
+ \r
+@@ -415,7 +415,7 @@ notmuch_database_find_message (notmuch_database_t *notmuch,\r
+ return NOTMUCH_STATUS_NULL_POINTER;\r
+ \r
+ if (strlen (message_id) > NOTMUCH_MESSAGE_ID_MAX)\r
+- message_id = _message_id_compressed (notmuch, message_id);\r
++ message_id = _notmuch_message_id_compressed (notmuch, message_id);\r
+ \r
+ try {\r
+ status = _notmuch_database_find_unique_doc_id (notmuch, "id",\r
+@@ -1728,7 +1728,7 @@ static char *\r
+ _get_metadata_thread_id_key (void *ctx, const char *message_id)\r
+ {\r
+ if (strlen (message_id) > NOTMUCH_MESSAGE_ID_MAX)\r
+- message_id = _message_id_compressed (ctx, message_id);\r
++ message_id = _notmuch_message_id_compressed (ctx, message_id);\r
+ \r
+ return talloc_asprintf (ctx, NOTMUCH_METADATA_THREAD_ID_PREFIX "%s",\r
+ message_id);\r
+@@ -2100,14 +2100,6 @@ notmuch_database_add_message (notmuch_database_t *notmuch,\r
+ * better than no message-id at all. */\r
+ if (message_id == NULL)\r
+ message_id = talloc_strdup (message_file, header);\r
+-\r
+- /* If a message ID is too long, substitute its sha1 instead. */\r
+- if (message_id && strlen (message_id) > NOTMUCH_MESSAGE_ID_MAX) {\r
+- char *compressed = _message_id_compressed (message_file,\r
+- message_id);\r
+- talloc_free (message_id);\r
+- message_id = compressed;\r
+- }\r
+ }\r
+ \r
+ if (message_id == NULL ) {\r
+diff --git a/lib/message.cc b/lib/message.cc\r
+index 7e82548..bbfc250 100644\r
+--- a/lib/message.cc\r
++++ b/lib/message.cc\r
+@@ -226,6 +226,10 @@ _notmuch_message_create_for_message_id (notmuch_database_t *notmuch,\r
+ else if (*status_ret)\r
+ return NULL;\r
+ \r
++ /* If the message ID is too long, substitute its sha1 instead. */\r
++ if (strlen (message_id) > NOTMUCH_MESSAGE_ID_MAX)\r
++ message_id = _notmuch_message_id_compressed (message, message_id);\r
++\r
+ term = talloc_asprintf (NULL, "%s%s",\r
+ _find_prefix ("id"), message_id);\r
+ if (term == NULL) {\r
+diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
+index 17f3061..36cc12b 100644\r
+--- a/lib/notmuch-private.h\r
++++ b/lib/notmuch-private.h\r
+@@ -174,6 +174,9 @@ typedef struct _notmuch_doc_id_set notmuch_doc_id_set_t;\r
+ const char *\r
+ _find_prefix (const char *name);\r
+ \r
++char *\r
++_notmuch_message_id_compressed (void *ctx, const char *message_id);\r
++\r
+ notmuch_status_t\r
+ _notmuch_database_ensure_writable (notmuch_database_t *notmuch);\r
+ \r
+-- \r
+2.1.0\r
+\r