Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 24 / 9f5204f6a5808ece3bd7f7bfd865f0dbfa2e6d
1 Return-Path: <igor.contato@gmail.com>\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 arlo.cworth.org (Postfix) with ESMTP id 275DA6DE19A0\r
6  for <notmuch@notmuchmail.org>; Wed, 25 Nov 2015 18:17:16 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.705\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.705 tagged_above=-999 required=5 tests=[AWL=0.096,\r
12   DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001,\r
13  RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001]\r
14  autolearn=disabled\r
15 Received: from arlo.cworth.org ([127.0.0.1])\r
16  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
17  with ESMTP id yaO4D-L94-rr for <notmuch@notmuchmail.org>;\r
18  Wed, 25 Nov 2015 18:17:14 -0800 (PST)\r
19 Received: from mail-qg0-f46.google.com (mail-qg0-f46.google.com\r
20  [209.85.192.46])\r
21  by arlo.cworth.org (Postfix) with ESMTPS id CE9316DE1989\r
22  for <notmuch@notmuchmail.org>; Wed, 25 Nov 2015 18:16:55 -0800 (PST)\r
23 Received: by qgcc31 with SMTP id c31so45657815qgc.3\r
24  for <notmuch@notmuchmail.org>; Wed, 25 Nov 2015 18:16:54 -0800 (PST)\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
26  h=from:to:cc:subject:date:message-id:in-reply-to:references;\r
27  bh=2ZT7nQ5OyGT646RI+kkwMsxiIBYqBcNG34q48V+odqY=;\r
28  b=pquWHaOBIyvrPo6qK3Vc/B1xgaoyqQ2mSu3obJhPEJQ+0QbvHDwPnEwbNAgvnwIczD\r
29  Dbi6qXihmIOL3775xsNbc/k03MowV+E1JwbpxE3rkos79bNJv3RaoT5rpqNgoLLZ9DPf\r
30  VvXNI9tHzry/W7smSFW2N+zUl96ZWapIaALROtXfhNHX+bWBGK/3kx7f/vYUOyT9pINM\r
31  evHt+RgSQRQ08/q5rsozGtoSWVpDF6VsJY+t6IrkGXpNIXt7Y+/i+Y/r7q6+bHQ/dwGq\r
32  KGeo/kEfDoprxGze6T0DZVIv5IwR/Y9iqoc3P3nCVttVAORUOxptvD2PUrW8PoGKl5Bq\r
33  RGZA==\r
34 X-Received: by 10.140.31.161 with SMTP id f30mr42861846qgf.95.1448504214817;\r
35  Wed, 25 Nov 2015 18:16:54 -0800 (PST)\r
36 Received: from arch-laptop.localdomain ([200.195.16.216])\r
37  by smtp.gmail.com with ESMTPSA id h206sm1566011qhc.43.2015.11.25.18.16.52\r
38  (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);\r
39  Wed, 25 Nov 2015 18:16:53 -0800 (PST)\r
40 From: Igor Almeida <igor.contato@gmail.com>\r
41 To: notmuch@notmuchmail.org\r
42 Subject: [PATCH/RFC 3/3] notmuch new: sync maildir custom flag user\r
43  configuration\r
44 Date: Wed, 25 Nov 2015 23:16:31 -0300\r
45 Message-Id: <1448504191-30974-4-git-send-email-igor.contato@gmail.com>\r
46 X-Mailer: git-send-email 2.5.3\r
47 In-Reply-To: <1448504191-30974-1-git-send-email-igor.contato@gmail.com>\r
48 References: <1448504191-30974-1-git-send-email-igor.contato@gmail.com>\r
49 X-BeenThere: notmuch@notmuchmail.org\r
50 X-Mailman-Version: 2.1.20\r
51 Precedence: list\r
52 List-Id: "Use and development of the notmuch mail system."\r
53  <notmuch.notmuchmail.org>\r
54 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
55  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
56 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
57 List-Post: <mailto:notmuch@notmuchmail.org>\r
58 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
59 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
60  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
61 X-List-Received-Date: Thu, 26 Nov 2015 02:17:16 -0000\r
62 \r
63 This allows the user to specify in the config file how maildir custom\r
64 flags translate to notmuch tags (this mapping is stored in the db metadata).\r
65 \r
66 Command 'notmuch new' will pick up changes in the config and update the\r
67 database metadata, but will not retag the messages.\r
68 \r
69 Example config:\r
70         [maildir]\r
71         synchronize_flags=true\r
72         customflag_j = todo\r
73         customflag_e = important\r
74 \r
75 Signed-off-by: Igor Almeida <igor.contato@gmail.com>\r
76 ---\r
77  notmuch-client.h |  4 ++++\r
78  notmuch-config.c | 24 +++++++++++++++++++++++-\r
79  notmuch-new.c    | 49 +++++++++++++++++++++++++++++++++++++++++++++++++\r
80  3 files changed, 76 insertions(+), 1 deletion(-)\r
81 \r
82 diff --git a/notmuch-client.h b/notmuch-client.h\r
83 index 3bd2903..9f5bb8f 100644\r
84 --- a/notmuch-client.h\r
85 +++ b/notmuch-client.h\r
86 @@ -324,6 +324,10 @@ void\r
87  notmuch_config_set_maildir_synchronize_flags (notmuch_config_t *config,\r
88                                               notmuch_bool_t synchronize_flags);\r
89  \r
90 +const char *\r
91 +notmuch_config_get_maildir_customflag_map (notmuch_config_t *config,\r
92 +                                          const char maildir_custom_flag);\r
93 +\r
94  const char **\r
95  notmuch_config_get_search_exclude_tags (notmuch_config_t *config, size_t *length);\r
96  \r
97 diff --git a/notmuch-config.c b/notmuch-config.c\r
98 index d252bb2..f2a25b1 100644\r
99 --- a/notmuch-config.c\r
100 +++ b/notmuch-config.c\r
101 @@ -72,7 +72,7 @@ static const char user_config_comment[] =\r
102  static const char maildir_config_comment[] =\r
103      " Maildir compatibility configuration\n"\r
104      "\n"\r
105 -    " The following option is supported here:\n"\r
106 +    " The following options are supported here:\n"\r
107      "\n"\r
108      "\tsynchronize_flags      Valid values are true and false.\n"\r
109      "\n"\r
110 @@ -87,6 +87,11 @@ static const char maildir_config_comment[] =\r
111      "\t\tR     replied\n"\r
112      "\t\tS     unread (added when 'S' flag is not present)\n"\r
113      "\n"\r
114 +    "\tIf true, then the following option is also considered, and messages\n"\r
115 +    "\twill be tagged based on the lower-case letters in the maildir flags:\n"\r
116 +    "\n"\r
117 +    "\tcustomflag_[a-z]       Valid values are tag names.\n"\r
118 +    "\n"\r
119      "\tThe \"notmuch new\" command will notice flag changes in filenames\n"\r
120      "\tand update tags, while the \"notmuch tag\" and \"notmuch restore\"\n"\r
121      "\tcommands will notice tag changes and update flags in filenames\n";\r
122 @@ -127,6 +132,8 @@ struct _notmuch_config {\r
123      notmuch_bool_t maildir_synchronize_flags;\r
124      const char **search_exclude_tags;\r
125      size_t search_exclude_tags_length;\r
126 +\r
127 +    char *customflag_map[26 /* 'a' to 'z' */];\r
128  };\r
129  \r
130  static int\r
131 @@ -931,3 +938,18 @@ notmuch_config_set_maildir_synchronize_flags (notmuch_config_t *config,\r
132                             "maildir", "synchronize_flags", synchronize_flags);\r
133      config->maildir_synchronize_flags = synchronize_flags;\r
134  }\r
135 +\r
136 +const char *\r
137 +notmuch_config_get_maildir_customflag_map (notmuch_config_t *config,\r
138 +                                          const char maildir_customflag)\r
139 +{\r
140 +    char key[] = "customflag_a";\r
141 +    key[sizeof(key) - 2] = maildir_customflag;\r
142 +\r
143 +    int index = maildir_customflag - 'a';\r
144 +\r
145 +    return _config_get (\r
146 +       config,\r
147 +       &config->customflag_map[index],\r
148 +       "maildir", key);\r
149 +}\r
150 diff --git a/notmuch-new.c b/notmuch-new.c\r
151 index d45d0af..d4bb6c7 100644\r
152 --- a/notmuch-new.c\r
153 +++ b/notmuch-new.c\r
154 @@ -923,6 +923,50 @@ print_results (const add_files_state_t *state)\r
155      printf ("\n");\r
156  }\r
157  \r
158 +static void\r
159 +_sync_config_and_database_customflag_mapping (notmuch_config_t *config,\r
160 +                                             notmuch_database_t *notmuch)\r
161 +{\r
162 +    char c;\r
163 +    const char *config_customflag;\r
164 +    const char *db_customflag;\r
165 +\r
166 +    notmuch_status_t status;\r
167 +    int index;\r
168 +\r
169 +    /* Compare the config mapping and the db mapping, warn the user and\r
170 +     * overwrite the db if they differ\r
171 +     */\r
172 +    for (c = 'a'; c <= 'z'; c++) {\r
173 +       index = c - 'a';\r
174 +       config_customflag = notmuch_config_get_maildir_customflag_map (config, c);\r
175 +\r
176 +       if (config_customflag != NULL) {\r
177 +           status = notmuch_database_get_maildir_keyword (\r
178 +               notmuch, index, &db_customflag);\r
179 +           if (status) {\r
180 +               /* TODO what now? break and let 'notmuch new' fail later? */\r
181 +           } else {\r
182 +               if (db_customflag != NULL &&\r
183 +                       strcmp(config_customflag, db_customflag)) {\r
184 +                   printf ("Your configuration for maildir custom flags has "\r
185 +                           "changed.\n"\r
186 +                           "I will overwrite the mapping in the db metadata, "\r
187 +                           "but you will have to retag the messages "\r
188 +                           "yourself, with something like this:\n"\r
189 +                           "\tnotmuch tag +%s tag:%s\n"\r
190 +                           "\tnotmuch tag -%s tag:%s\n",\r
191 +                               config_customflag, db_customflag,\r
192 +                               db_customflag, config_customflag);\r
193 +               }\r
194 +\r
195 +               notmuch_database_set_maildir_keyword (\r
196 +                   notmuch, index, config_customflag);\r
197 +           }\r
198 +       }\r
199 +    }\r
200 +}\r
201 +\r
202  int\r
203  notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
204  {\r
205 @@ -1068,6 +1112,11 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
206      if (notmuch == NULL)\r
207         return EXIT_FAILURE;\r
208  \r
209 +    /* Make sure our database's maildir customflag mapping matches the config,\r
210 +     * warn the user if not\r
211 +     */\r
212 +    _sync_config_and_database_customflag_mapping (config, notmuch);\r
213 +\r
214      /* Set up our handler for SIGINT. We do this after having\r
215       * potentially done a database upgrade we this interrupt handler\r
216       * won't support. */\r
217 -- \r
218 2.5.3\r
219 \r