Re: [PATCH] Fix typo in Message.maildir_flags_to_tags
[notmuch-archives.git] / af / 36a38b60e48634e080239bbf029e72af6a2b5b
1 Return-Path: <bremner@tesseract.cs.unb.ca>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 27DF2431FB6\r
6         for <notmuch@notmuchmail.org>; Sat, 27 Sep 2014 01:17:43 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id OlL5B7m5z4fv for <notmuch@notmuchmail.org>;\r
16         Sat, 27 Sep 2014 01:17:36 -0700 (PDT)\r
17 Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155])\r
18         (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 63394431FAF\r
21         for <notmuch@notmuchmail.org>; Sat, 27 Sep 2014 01:17:36 -0700 (PDT)\r
22 Received: from remotemail by yantan.tethera.net with local (Exim 4.80)\r
23         (envelope-from <bremner@tesseract.cs.unb.ca>)\r
24         id 1XXnC3-0002xS-8n; Sat, 27 Sep 2014 05:17:27 -0300\r
25 Received: (nullmailer pid 4070 invoked by uid 1000); Sat, 27 Sep 2014\r
26         08:17:21 -0000\r
27 From: David Bremner <david@tethera.net>\r
28 To: notmuch@notmuchmail.org\r
29 Subject: [RFC] database: get and set mapping of dovecot compatible maildir\r
30         keywords\r
31 Date: Sat, 27 Sep 2014 10:17:15 +0200\r
32 Message-Id: <1411805835-3563-1-git-send-email-david@tethera.net>\r
33 X-Mailer: git-send-email 2.1.0\r
34 X-BeenThere: notmuch@notmuchmail.org\r
35 X-Mailman-Version: 2.1.13\r
36 Precedence: list\r
37 List-Id: "Use and development of the notmuch mail system."\r
38         <notmuch.notmuchmail.org>\r
39 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
40         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
42 List-Post: <mailto:notmuch@notmuchmail.org>\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
44 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
45         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
46 X-List-Received-Date: Sat, 27 Sep 2014 08:17:43 -0000\r
47 \r
48 A future modification of notmuch_message_tags_to_maildir_flags and\r
49 notmuch_message_maildir_flags_to_tags could allow 26 more tags to be\r
50 synced via maildir.\r
51 ---\r
52 \r
53 I'm not sure if this is worth pursuing or not, but I thought I'd toss\r
54 it out there.  On IRC the other day the topic of syncing IMAP keywords\r
55 to notmuch tags came up again, in particular the dovecot variant that\r
56 maps 26 user defined keywords to characters a-z on the end of the\r
57 maildir info.  One roadblock I saw at the time was the need for\r
58 configuration of mapping of letters to tags.  This patch is the result\r
59 of my realizing that at least that part is not hard (unlike the rabbit\r
60 hole we seemed to get into for e.g. log configuration).\r
61 \r
62 Some downsides of this approach are fairly obvious\r
63 \r
64     - only 26 tags. It turns out I don't have that many non-nmbug tags\r
65       that I really care about. YMMV, of course.\r
66 \r
67     - nonstandard. this won't roundtrip via offlineimap (unless\r
68       offlineimap is modified).  Directly syncing the maildir or using\r
69       some dovecot specific syncer would work.\r
70 \r
71 Some upsides are:\r
72 \r
73     - Provides an IMAP bridge solution; compatible with dovecot; my\r
74       impression is this is the most common imap solution among\r
75       notmuch users.  \r
76     - relatively simple implementation, just need to\r
77       update the maildir name synching routines. Of course no\r
78       implementation is as simple as possible\r
79 \r
80  lib/database.cc | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
81  lib/notmuch.h   | 19 ++++++++++++++++++\r
82  2 files changed, 80 insertions(+)\r
83 \r
84 diff --git a/lib/database.cc b/lib/database.cc\r
85 index a3a7cd3..5427f7c 100644\r
86 --- a/lib/database.cc\r
87 +++ b/lib/database.cc\r
88 @@ -1169,6 +1169,67 @@ notmuch_database_get_version (notmuch_database_t *notmuch)\r
89      return version;\r
90  }\r
91  \r
92 +notmuch_status_t\r
93 +notmuch_database_get_maildir_keyword (notmuch_database_t *notmuch,\r
94 +                                     int index, const char **tag)\r
95 +{\r
96 +    string tag_string;\r
97 +    const char *key;\r
98 +    const char *str;\r
99 +\r
100 +    if (!notmuch || !tag)\r
101 +       return NOTMUCH_STATUS_NULL_POINTER;\r
102 +\r
103 +    if (index < 0 || index > ('z' - 'a'))\r
104 +       return NOTMUCH_STATUS_UNSUPPORTED_OPERATION;\r
105 +\r
106 +    key = talloc_asprintf(notmuch, "maildir_keyword_%c", 'a' + index);\r
107 +    if (!key)\r
108 +       return NOTMUCH_STATUS_OUT_OF_MEMORY;\r
109 +\r
110 +    *tag = NULL;\r
111 +    tag_string = notmuch->xapian_db->get_metadata (key);\r
112 +    if (tag_string.empty ())\r
113 +       return NOTMUCH_STATUS_SUCCESS;\r
114 +\r
115 +    str = tag_string.c_str ();\r
116 +    if (str == NULL || *str == '\0')\r
117 +       return NOTMUCH_STATUS_SUCCESS;\r
118 +\r
119 +    *tag = str;\r
120 +\r
121 +    return NOTMUCH_STATUS_SUCCESS;\r
122 +}\r
123 +\r
124 +notmuch_status_t\r
125 +notmuch_database_set_maildir_keyword (notmuch_database_t *notmuch,\r
126 +                                     int index, const char *tag)\r
127 +{\r
128 +    string tag_string;\r
129 +    const char *key;\r
130 +    notmuch_status_t ret;\r
131 +    Xapian::WritableDatabase *db;\r
132 +\r
133 +    if (!notmuch || !tag)\r
134 +       return NOTMUCH_STATUS_NULL_POINTER;\r
135 +\r
136 +    ret = _notmuch_database_ensure_writable (notmuch);\r
137 +    if (ret)\r
138 +       return ret;\r
139 +\r
140 +    if (index < 0 || index > ('z' - 'a'))\r
141 +       return NOTMUCH_STATUS_UNSUPPORTED_OPERATION;\r
142 +\r
143 +    key = talloc_asprintf(notmuch, "maildir_keyword_%c", 'a' + index);\r
144 +    if (!key)\r
145 +       return NOTMUCH_STATUS_OUT_OF_MEMORY;\r
146 +\r
147 +    db = static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db);\r
148 +    db->set_metadata (key, tag);\r
149 +\r
150 +    return NOTMUCH_STATUS_SUCCESS;\r
151 +}\r
152 +\r
153  notmuch_bool_t\r
154  notmuch_database_needs_upgrade (notmuch_database_t *notmuch)\r
155  {\r
156 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
157 index fe2340b..5fec8b3 100644\r
158 --- a/lib/notmuch.h\r
159 +++ b/lib/notmuch.h\r
160 @@ -614,6 +614,25 @@ notmuch_tags_t *\r
161  notmuch_database_get_all_tags (notmuch_database_t *db);\r
162  \r
163  /**\r
164 + * Return the tag corresponding to a maildir keyword.\r
165 + *\r
166 + */\r
167 +notmuch_status_t\r
168 +notmuch_database_get_maildir_keyword(notmuch_database_t *db,\r
169 +                                    int index, char **tag);\r
170 +\r
171 +/**\r
172 + * Set the tag corresponding to a maildir keyword.\r
173 + *\r
174 + * Note that no messages have their tags modified by this call.\r
175 + */\r
176 +\r
177 +notmuch_status_t\r
178 +notmuch_database_set_maildir_keyword(notmuch_database_t *db,\r
179 +                                    int index, const char *tag);\r
180 +\r
181 +\r
182 +/**\r
183   * Create a new query for 'database'.\r
184   *\r
185   * Here, 'database' should be an open database, (see\r
186 -- \r
187 2.1.0\r
188 \r