Re: [feature request] emacs: use `notmuch insert` for FCC
[notmuch-archives.git] / e8 / 5c1bccb3998846828c4388fe088b5d1627f98d
1 Return-Path: <tsgatesv@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 olra.theworths.org (Postfix) with ESMTP id 5EE9D431FDE\r
6         for <notmuch@notmuchmail.org>; Thu, 25 Oct 2012 16:33:28 -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.699\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001,\r
13         RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id ibuNg8STPpy2 for <notmuch@notmuchmail.org>;\r
17         Thu, 25 Oct 2012 16:33:25 -0700 (PDT)\r
18 Received: from mail-qc0-f181.google.com (mail-qc0-f181.google.com\r
19         [209.85.216.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 5FB81431FAE\r
22         for <notmuch@notmuchmail.org>; Thu, 25 Oct 2012 16:33:25 -0700 (PDT)\r
23 Received: by mail-qc0-f181.google.com with SMTP id x40so1058185qcp.26\r
24         for <notmuch@notmuchmail.org>; Thu, 25 Oct 2012 16:33:25 -0700 (PDT)\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
26         h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to\r
27         :references; bh=P7Gk2RXu8IxuwzfhcBZ2hlp/jpTkc4Pe8RllG0E+6HA=;\r
28         b=vm8yvmciJVXVUIkD2yYdIjbEC+cxBX6cZjQYlkd5if1X1/SpkMd1/pw+HdOVVuyVvq\r
29         1tQNM3aHMtYErNrmtn0X7IwkKolcc9G7tEo3T7lJM4a05b+DaFLXvZbaxK7KtpDI8Bru\r
30         O+kJ4wV3fS8dB2/rDaHaakqpeS6yEjmWs4PoF2p+V/9NYFyROvzmpRpRHZEXKvguZtVr\r
31         H3LFdqd9QPObsjq8Jir0rBSBYpYZEdJeJ4jgqJ+5LrXbimMCmzBUz+Ns8jghdcd3VBBl\r
32         +aZpxQRsvwhwx8du493PoWbeX4q27VQrYeJ7qd6fGQpPqNhZKC5ScY50Kx28yaDTgZbC\r
33         bCbA==\r
34 Received: by 10.224.107.3 with SMTP id z3mr1880883qao.9.1351208005203;\r
35         Thu, 25 Oct 2012 16:33:25 -0700 (PDT)\r
36 Received: from skynet (26-4-166.dynamic.csail.mit.edu. [18.26.4.166])\r
37         by mx.google.com with ESMTPS id gw9sm161680qab.4.2012.10.25.16.33.23\r
38         (version=SSLv3 cipher=OTHER); Thu, 25 Oct 2012 16:33:24 -0700 (PDT)\r
39 Sender: Taesoo Kim <tsgatesv@gmail.com>\r
40 Received: by skynet (sSMTP sendmail emulation); Thu, 25 Oct 2012 19:34:44\r
41  -0400\r
42 From: Taesoo Kim <taesoo@mit.edu>\r
43 To: notmuch@notmuchmail.org\r
44 Subject: [PATCH 1/2] Automatic tagging based on maildir\r
45 Date: Thu, 25 Oct 2012 19:33:58 -0400\r
46 Message-Id: <1351208039-32293-2-git-send-email-taesoo@mit.edu>\r
47 X-Mailer: git-send-email 1.8.0\r
48 In-Reply-To: <1351208039-32293-1-git-send-email-taesoo@mit.edu>\r
49 References: <1351208039-32293-1-git-send-email-taesoo@mit.edu>\r
50 X-Mailman-Approved-At: Thu, 25 Oct 2012 22:45:51 -0700\r
51 Cc: Taesoo Kim <taesoo@mit.edu>\r
52 X-BeenThere: notmuch@notmuchmail.org\r
53 X-Mailman-Version: 2.1.13\r
54 Precedence: list\r
55 List-Id: "Use and development of the notmuch mail system."\r
56         <notmuch.notmuchmail.org>\r
57 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
58         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
59 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
60 List-Post: <mailto:notmuch@notmuchmail.org>\r
61 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
62 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
63         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
64 X-List-Received-Date: Thu, 25 Oct 2012 23:33:28 -0000\r
65 \r
66 Since gmail will provide labels as imap sub/folders, notmuch also can\r
67 take advantage of labels as tags, when maildir.add_as_tag_flags is\r
68 specified.\r
69 \r
70 Signed-off-by: Taesoo Kim <taesoo@mit.edu>\r
71 ---\r
72  notmuch-client.h |  7 +++++++\r
73  notmuch-config.c | 42 ++++++++++++++++++++++++++++++++++++++----\r
74  notmuch-new.c    | 32 ++++++++++++++++++++++++++++++++\r
75  3 files changed, 77 insertions(+), 4 deletions(-)\r
76 \r
77 diff --git a/notmuch-client.h b/notmuch-client.h\r
78 index ae9344b..ce05e52 100644\r
79 --- a/notmuch-client.h\r
80 +++ b/notmuch-client.h\r
81 @@ -265,6 +265,13 @@ void\r
82  notmuch_config_set_maildir_synchronize_flags (notmuch_config_t *config,\r
83                                               notmuch_bool_t synchronize_flags);\r
84  \r
85 +notmuch_bool_t\r
86 +notmuch_config_get_maildir_add_as_tag_flags (notmuch_config_t *config);\r
87 +\r
88 +void\r
89 +notmuch_config_set_maildir_add_as_tag_flags (notmuch_config_t *config,\r
90 +                                            notmuch_bool_t add_as_tag_flags);\r
91 +\r
92  const char **\r
93  notmuch_config_get_search_exclude_tags (notmuch_config_t *config, size_t *length);\r
94  \r
95 diff --git a/notmuch-config.c b/notmuch-config.c\r
96 index 3e37a2d..c95f9dd 100644\r
97 --- a/notmuch-config.c\r
98 +++ b/notmuch-config.c\r
99 @@ -88,7 +88,16 @@ static const char maildir_config_comment[] =\r
100      "\n"\r
101      "\tThe \"notmuch new\" command will notice flag changes in filenames\n"\r
102      "\tand update tags, while the \"notmuch tag\" and \"notmuch restore\"\n"\r
103 -    "\tcommands will notice tag changes and update flags in filenames\n";\r
104 +    "\tcommands will notice tag changes and update flags in filenames\n"\r
105 +    "\n"\r
106 +    "\tadd_as_tag_flags       Valid values are true and false.\n"\r
107 +    "\n"\r
108 +    "\nIf ture, then add the lower-cased name of maildirs"\r
109 +    "\n(also deliminated by .) as tags"\r
110 +    "\n"\r
111 +    "\n\te.g. Life              -> life"\r
112 +    "\n\te.g. MIT.CSAIL         -> mit, csail"\r
113 +    "\n\te.g. Mailing.OSS.Linux -> mailing, oss, linux";\r
114  \r
115  static const char search_config_comment[] =\r
116      " Search configuration\n"\r
117 @@ -114,6 +123,7 @@ struct _notmuch_config {\r
118      const char **new_ignore;\r
119      size_t new_ignore_length;\r
120      notmuch_bool_t maildir_synchronize_flags;\r
121 +    notmuch_bool_t maildir_add_as_tag_flags;\r
122      const char **search_exclude_tags;\r
123      size_t search_exclude_tags_length;\r
124  };\r
125 @@ -251,7 +261,7 @@ notmuch_config_open (void *ctx,\r
126         fprintf (stderr, "Out of memory.\n");\r
127         return NULL;\r
128      }\r
129 -    \r
130 +\r
131      talloc_set_destructor (config, notmuch_config_destructor);\r
132  \r
133      if (filename) {\r
134 @@ -393,6 +403,14 @@ notmuch_config_open (void *ctx,\r
135         g_error_free (error);\r
136      }\r
137  \r
138 +    config->maildir_add_as_tag_flags =\r
139 +       g_key_file_get_boolean (config->key_file,\r
140 +                               "maildir", "add_as_tag_flags", &error);\r
141 +    if (error) {\r
142 +       notmuch_config_set_maildir_add_as_tag_flags (config, FALSE);\r
143 +       g_error_free (error);\r
144 +    }\r
145 +\r
146      /* Whenever we know of configuration sections that don't appear in\r
147       * the configuration file, we add some comments to help the user\r
148       * understand what can be done. */\r
149 @@ -438,7 +456,7 @@ notmuch_config_open (void *ctx,\r
150  }\r
151  \r
152  /* Close the given notmuch_config_t object, freeing all resources.\r
153 - * \r
154 + *\r
155   * Note: Any changes made to the configuration are *not* saved by this\r
156   * function. To save changes, call notmuch_config_save before\r
157   * notmuch_config_close.\r
158 @@ -720,7 +738,7 @@ notmuch_config_command_get (void *ctx, char *item)\r
159      } else if (strcmp(item, "user.other_email") == 0) {\r
160         const char **other_email;\r
161         size_t i, length;\r
162 -       \r
163 +\r
164         other_email = notmuch_config_get_user_other_email (config, &length);\r
165         for (i = 0; i < length; i++)\r
166             printf ("%s\n", other_email[i]);\r
167 @@ -891,3 +909,19 @@ notmuch_config_set_maildir_synchronize_flags (notmuch_config_t *config,\r
168                             "maildir", "synchronize_flags", synchronize_flags);\r
169      config->maildir_synchronize_flags = synchronize_flags;\r
170  }\r
171 +\r
172 +\r
173 +notmuch_bool_t\r
174 +notmuch_config_get_maildir_add_as_tag_flags (notmuch_config_t *config)\r
175 +{\r
176 +    return config->maildir_add_as_tag_flags;\r
177 +}\r
178 +\r
179 +void\r
180 +notmuch_config_set_maildir_add_as_tag_flags (notmuch_config_t *config,\r
181 +                                            notmuch_bool_t add_as_tag_flags)\r
182 +{\r
183 +    g_key_file_set_boolean (config->key_file,\r
184 +                           "maildir", "add_as_tag_flags", add_as_tag_flags);\r
185 +    config->maildir_add_as_tag_flags = add_as_tag_flags;\r
186 +}\r
187 diff --git a/notmuch-new.c b/notmuch-new.c\r
188 index 56c4a6f..9ec983f 100644\r
189 --- a/notmuch-new.c\r
190 +++ b/notmuch-new.c\r
191 @@ -20,6 +20,7 @@\r
192  \r
193  #include "notmuch-client.h"\r
194  \r
195 +#include <ctype.h>\r
196  #include <unistd.h>\r
197  \r
198  typedef struct _filename_node {\r
199 @@ -53,6 +54,7 @@ typedef struct {\r
200      _filename_list_t *directory_mtimes;\r
201  \r
202      notmuch_bool_t synchronize_flags;\r
203 +    notmuch_bool_t add_as_tag_flags;\r
204  } add_files_state_t;\r
205  \r
206  static volatile sig_atomic_t do_print_progress = 0;\r
207 @@ -240,6 +242,32 @@ _entry_in_ignore_list (const char *entry, add_files_state_t *state)\r
208      return FALSE;\r
209  }\r
210  \r
211 +static void\r
212 +_add_maildir_as_tag(notmuch_database_t *notmuch,\r
213 +                   notmuch_message_t *msg, const char *path) \r
214 +{\r
215 +    char *tok = talloc_strdup (notmuch, path);\r
216 +    int len = strlen(tok);\r
217 +    \r
218 +    /* asserts path ends with /cur|/tmp|/new */\r
219 +    if (len > 4 && tok[len - 4] == '/') {\r
220 +       char *iter = tok + len - 4;\r
221 +       *iter = '\0';\r
222 +       while (-- iter && iter >= tok) {\r
223 +           char c = *iter;\r
224 +           if (c == '/' || c == '.') {\r
225 +               *iter = '\0';\r
226 +               notmuch_message_add_tag (msg, iter + 1);\r
227 +               if (c == '/') {\r
228 +                   break;\r
229 +               }\r
230 +           }\r
231 +           *iter = tolower(*iter);\r
232 +       }\r
233 +    }\r
234 +    talloc_free (tok);\r
235 +}\r
236 +\r
237  /* Examine 'path' recursively as follows:\r
238   *\r
239   *   o Ask the filesystem for the mtime of 'path' (fs_mtime)\r
240 @@ -508,6 +536,9 @@ add_files (notmuch_database_t *notmuch,\r
241             notmuch_message_freeze (message);\r
242             for (tag=state->new_tags; *tag != NULL; tag++)\r
243                 notmuch_message_add_tag (message, *tag);\r
244 +           if (state->add_as_tag_flags == TRUE) {\r
245 +               _add_maildir_as_tag(notmuch, message, path);\r
246 +           }\r
247             if (state->synchronize_flags == TRUE)\r
248                 notmuch_message_maildir_flags_to_tags (message);\r
249             notmuch_message_thaw (message);\r
250 @@ -878,6 +909,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
251      add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length);\r
252      add_files_state.new_ignore = notmuch_config_get_new_ignore (config, &add_files_state.new_ignore_length);\r
253      add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
254 +    add_files_state.add_as_tag_flags = notmuch_config_get_maildir_add_as_tag_flags (config);\r
255      db_path = notmuch_config_get_database_path (config);\r
256  \r
257      if (run_hooks) {\r
258 -- \r
259 1.8.0\r
260 \r