--- /dev/null
+Return-Path: <bremner@tesseract.cs.unb.ca>\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 27DF2431FB6\r
+ for <notmuch@notmuchmail.org>; Sat, 27 Sep 2014 01:17:43 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+ 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 OlL5B7m5z4fv for <notmuch@notmuchmail.org>;\r
+ Sat, 27 Sep 2014 01:17:36 -0700 (PDT)\r
+Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155])\r
+ (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 63394431FAF\r
+ for <notmuch@notmuchmail.org>; Sat, 27 Sep 2014 01:17:36 -0700 (PDT)\r
+Received: from remotemail by yantan.tethera.net with local (Exim 4.80)\r
+ (envelope-from <bremner@tesseract.cs.unb.ca>)\r
+ id 1XXnC3-0002xS-8n; Sat, 27 Sep 2014 05:17:27 -0300\r
+Received: (nullmailer pid 4070 invoked by uid 1000); Sat, 27 Sep 2014\r
+ 08:17:21 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [RFC] database: get and set mapping of dovecot compatible maildir\r
+ keywords\r
+Date: Sat, 27 Sep 2014 10:17:15 +0200\r
+Message-Id: <1411805835-3563-1-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.1.0\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: Sat, 27 Sep 2014 08:17:43 -0000\r
+\r
+A future modification of notmuch_message_tags_to_maildir_flags and\r
+notmuch_message_maildir_flags_to_tags could allow 26 more tags to be\r
+synced via maildir.\r
+---\r
+\r
+I'm not sure if this is worth pursuing or not, but I thought I'd toss\r
+it out there. On IRC the other day the topic of syncing IMAP keywords\r
+to notmuch tags came up again, in particular the dovecot variant that\r
+maps 26 user defined keywords to characters a-z on the end of the\r
+maildir info. One roadblock I saw at the time was the need for\r
+configuration of mapping of letters to tags. This patch is the result\r
+of my realizing that at least that part is not hard (unlike the rabbit\r
+hole we seemed to get into for e.g. log configuration).\r
+\r
+Some downsides of this approach are fairly obvious\r
+\r
+ - only 26 tags. It turns out I don't have that many non-nmbug tags\r
+ that I really care about. YMMV, of course.\r
+\r
+ - nonstandard. this won't roundtrip via offlineimap (unless\r
+ offlineimap is modified). Directly syncing the maildir or using\r
+ some dovecot specific syncer would work.\r
+\r
+Some upsides are:\r
+\r
+ - Provides an IMAP bridge solution; compatible with dovecot; my\r
+ impression is this is the most common imap solution among\r
+ notmuch users. \r
+ - relatively simple implementation, just need to\r
+ update the maildir name synching routines. Of course no\r
+ implementation is as simple as possible\r
+\r
+ lib/database.cc | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ lib/notmuch.h | 19 ++++++++++++++++++\r
+ 2 files changed, 80 insertions(+)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index a3a7cd3..5427f7c 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -1169,6 +1169,67 @@ notmuch_database_get_version (notmuch_database_t *notmuch)\r
+ return version;\r
+ }\r
+ \r
++notmuch_status_t\r
++notmuch_database_get_maildir_keyword (notmuch_database_t *notmuch,\r
++ int index, const char **tag)\r
++{\r
++ string tag_string;\r
++ const char *key;\r
++ const char *str;\r
++\r
++ if (!notmuch || !tag)\r
++ return NOTMUCH_STATUS_NULL_POINTER;\r
++\r
++ if (index < 0 || index > ('z' - 'a'))\r
++ return NOTMUCH_STATUS_UNSUPPORTED_OPERATION;\r
++\r
++ key = talloc_asprintf(notmuch, "maildir_keyword_%c", 'a' + index);\r
++ if (!key)\r
++ return NOTMUCH_STATUS_OUT_OF_MEMORY;\r
++\r
++ *tag = NULL;\r
++ tag_string = notmuch->xapian_db->get_metadata (key);\r
++ if (tag_string.empty ())\r
++ return NOTMUCH_STATUS_SUCCESS;\r
++\r
++ str = tag_string.c_str ();\r
++ if (str == NULL || *str == '\0')\r
++ return NOTMUCH_STATUS_SUCCESS;\r
++\r
++ *tag = str;\r
++\r
++ return NOTMUCH_STATUS_SUCCESS;\r
++}\r
++\r
++notmuch_status_t\r
++notmuch_database_set_maildir_keyword (notmuch_database_t *notmuch,\r
++ int index, const char *tag)\r
++{\r
++ string tag_string;\r
++ const char *key;\r
++ notmuch_status_t ret;\r
++ Xapian::WritableDatabase *db;\r
++\r
++ if (!notmuch || !tag)\r
++ return NOTMUCH_STATUS_NULL_POINTER;\r
++\r
++ ret = _notmuch_database_ensure_writable (notmuch);\r
++ if (ret)\r
++ return ret;\r
++\r
++ if (index < 0 || index > ('z' - 'a'))\r
++ return NOTMUCH_STATUS_UNSUPPORTED_OPERATION;\r
++\r
++ key = talloc_asprintf(notmuch, "maildir_keyword_%c", 'a' + index);\r
++ if (!key)\r
++ return NOTMUCH_STATUS_OUT_OF_MEMORY;\r
++\r
++ db = static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db);\r
++ db->set_metadata (key, tag);\r
++\r
++ return NOTMUCH_STATUS_SUCCESS;\r
++}\r
++\r
+ notmuch_bool_t\r
+ notmuch_database_needs_upgrade (notmuch_database_t *notmuch)\r
+ {\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index fe2340b..5fec8b3 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -614,6 +614,25 @@ notmuch_tags_t *\r
+ notmuch_database_get_all_tags (notmuch_database_t *db);\r
+ \r
+ /**\r
++ * Return the tag corresponding to a maildir keyword.\r
++ *\r
++ */\r
++notmuch_status_t\r
++notmuch_database_get_maildir_keyword(notmuch_database_t *db,\r
++ int index, char **tag);\r
++\r
++/**\r
++ * Set the tag corresponding to a maildir keyword.\r
++ *\r
++ * Note that no messages have their tags modified by this call.\r
++ */\r
++\r
++notmuch_status_t\r
++notmuch_database_set_maildir_keyword(notmuch_database_t *db,\r
++ int index, const char *tag);\r
++\r
++\r
++/**\r
+ * Create a new query for 'database'.\r
+ *\r
+ * Here, 'database' should be an open database, (see\r
+-- \r
+2.1.0\r
+\r