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