1 Return-Path: <Sebastian@SSpaeth.de>
\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 6912B431FBD
\r
6 for <notmuch@notmuchmail.org>; Mon, 1 Mar 2010 05:29:10 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.992 tagged_above=-999 required=5
\r
12 tests=[AWL=-0.252, BAYES_20=-0.74] autolearn=ham
\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 YFTIHcWxeFeS for <notmuch@notmuchmail.org>;
\r
16 Mon, 1 Mar 2010 05:29:09 -0800 (PST)
\r
17 Received: from homiemail-a15.g.dreamhost.com (caiajhbdcahe.dreamhost.com
\r
19 by olra.theworths.org (Postfix) with ESMTP id 94C61431FAE
\r
20 for <notmuch@notmuchmail.org>; Mon, 1 Mar 2010 05:29:09 -0800 (PST)
\r
21 Received: from localhost.localdomain (mtec-hg-docking-1-dhcp-204.ethz.ch
\r
23 by homiemail-a15.g.dreamhost.com (Postfix) with ESMTPA id D3B0F76C065;
\r
24 Mon, 1 Mar 2010 05:29:00 -0800 (PST)
\r
25 From: Sebastian Spaeth <Sebastian@SSpaeth.de>
\r
26 To: notmuch@notmuchmail.org
\r
27 Date: Mon, 1 Mar 2010 14:28:56 +0100
\r
28 Message-Id: <1267450136-31749-1-git-send-email-Sebastian@SSpaeth.de>
\r
29 X-Mailer: git-send-email 1.6.3.3
\r
30 In-Reply-To: <20100216022128.GH22402@flamingspork.com>
\r
31 References: <20100216022128.GH22402@flamingspork.com>
\r
32 Subject: [notmuch] [PATCH] notmuch-new: Respect maildir flags when importing
\r
34 X-BeenThere: notmuch@notmuchmail.org
\r
35 X-Mailman-Version: 2.1.13
\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: Mon, 01 Mar 2010 13:29:10 -0000
\r
48 When importing a new mail do check for maildir tags and assign corresponding notmuch tags.
\r
50 Based on a patch by Michiel Buddingh <michiel@michielbuddingh.net> and subsequently modified by Tim Stoakes, Stewart Smith, and Sebastian Spaeth (see mail thread around mail id:20100210031339.GH16686@mail.rocksoft.com)
\r
52 Do note that this will only add tags when importing a really new message, and will not do anything when detecting a file rename (although someone should really make it honor file renames as well). Deleteing an existing message in another IMAP client will therefore not trigger tagging (as it counts as a file rename).
\r
54 Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
\r
56 I cleaned up the patch by Stewart Smith a bit more, but it's basically his last version of the patch. The biggest caveat is really that file renames won't cause any change. So this approach is really only part of the solution to sync with e.g. thunderbird usage.
\r
57 notmuch-new.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
\r
58 1 files changed, 63 insertions(+), 1 deletions(-)
\r
60 diff --git a/notmuch-new.c b/notmuch-new.c
\r
61 index f25c71f..5a75950 100644
\r
64 @@ -39,6 +39,7 @@ typedef struct {
\r
66 int processed_files;
\r
68 + notmuch_bool_t tag_maildir;
\r
69 struct timeval tv_start;
\r
71 _filename_list_t *removed_files;
\r
72 @@ -169,6 +170,60 @@ _entries_resemble_maildir (struct dirent **entries, int count)
\r
76 +/* Tag new mail according to its Maildir attribute flags.
\r
78 + * Test if the mail file's filename contains any of the
\r
79 + * standard Maildir attributes, and translate these to
\r
80 + * the corresponding standard notmuch tags.
\r
82 + * If the message is not marked as 'seen', or if no
\r
83 + * flags are present, tag as 'inbox, unread'.
\r
86 +derive_tags_from_maildir_flags (notmuch_message_t *message,
\r
87 + const char * path)
\r
90 + int end_of_flags = FALSE;
\r
91 + size_t l = strlen(path);
\r
93 + /* Non-experimental message flags start with this */
\r
94 + char * i = strstr(path, ":2,");
\r
95 + i = (i) ? i : strstr(path, "!2,"); /* This format is used on VFAT */
\r
98 + for (; i < (path + l) && !end_of_flags; i++) {
\r
101 + notmuch_message_add_tag (message, "maildir::flagged");
\r
103 + case 'R': /* replied */
\r
104 + notmuch_message_add_tag (message, "maildir::replied");
\r
107 + notmuch_message_add_tag (message, "maildir::draft");
\r
109 + case 'S': /* seen */
\r
112 + case 'T': /* trashed */
\r
113 + notmuch_message_add_tag (message, "maildir::trashed");
\r
115 + case 'P': /* passed */
\r
116 + notmuch_message_add_tag (message, "maildir::forwarded");
\r
119 + end_of_flags = TRUE;
\r
125 + if (i == NULL || !seen) {
\r
126 + tag_inbox_and_unread (message);
\r
130 /* Examine 'path' recursively as follows:
\r
132 * o Ask the filesystem for the mtime of 'path' (fs_mtime)
\r
133 @@ -299,6 +354,8 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
134 strcmp (entry->d_name, ".notmuch") ==0)
\r
138 + state->tag_maildir = TRUE;
\r
141 next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);
\r
142 @@ -412,7 +469,12 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
144 case NOTMUCH_STATUS_SUCCESS:
\r
145 state->added_messages++;
\r
146 - tag_inbox_and_unread (message);
\r
147 + if (state->tag_maildir) {
\r
148 + derive_tags_from_maildir_flags (message,
\r
151 + tag_inbox_and_unread (message);
\r
154 /* Non-fatal issues (go on to next file) */
\r
155 case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
\r