1 Return-Path: <stewart@flamingspork.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 6E2D5431FBC
\r
6 for <notmuch@notmuchmail.org>; Mon, 15 Feb 2010 17:59:02 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.778 tagged_above=-999 required=5
\r
12 tests=[AWL=-0.593, BAYES_40=-0.185] 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 6uRP7vDbRfwh for <notmuch@notmuchmail.org>;
\r
16 Mon, 15 Feb 2010 17:59:01 -0800 (PST)
\r
17 Received: from kaylee.flamingspork.com (kaylee.flamingspork.com
\r
19 by olra.theworths.org (Postfix) with ESMTP id 8F4D4431FAE
\r
20 for <notmuch@notmuchmail.org>; Mon, 15 Feb 2010 17:59:01 -0800 (PST)
\r
21 Received: from willster (localhost [127.0.0.1])
\r
22 by kaylee.flamingspork.com (Postfix) with ESMTPS id 0244C6393;
\r
23 Tue, 16 Feb 2010 01:56:00 +0000 (UTC)
\r
24 Received: from flamingspork.com (localhost.localdomain [127.0.0.1])
\r
25 by willster (Postfix) with ESMTPS id A039B10260A3;
\r
26 Tue, 16 Feb 2010 12:58:58 +1100 (EST)
\r
27 Date: Tue, 16 Feb 2010 12:58:56 +1100
\r
28 From: Stewart Smith <stewart@flamingspork.com>
\r
29 To: Tim Stoakes <notmuch@stoakes.net>
\r
30 Message-ID: <20100216015856.GG22402@flamingspork.com>
\r
31 References: <20091121221207.GB17268@jukie.net>
\r
32 <9cce5525b093b87fe74d427954ffad89@localhost>
\r
33 <87d43b2oif.fsf@yoom.home.cworth.org>
\r
34 <9bfdedddeab9c58cd45d8d448323d0fc@localhost>
\r
35 <87skc23327.fsf@yoom.home.cworth.org>
\r
36 <4b0eef22.JwxdgTGElffx149F%michiel@michielbuddingh.net>
\r
37 <87ws1bjpmm.fsf@yoom.home.cworth.org> <878wdfkhcl.fsf@aegir.org.uk>
\r
38 <20100210031339.GH16686@mail.rocksoft.com>
\r
39 <20100215081331.GD22402@flamingspork.com>
\r
41 Content-Type: text/plain; charset=us-ascii
\r
42 Content-Disposition: inline
\r
43 In-Reply-To: <20100215081331.GD22402@flamingspork.com>
\r
44 User-Agent: Mutt/1.5.20 (2009-06-14)
\r
45 Cc: notmuch@notmuchmail.org
\r
46 Subject: [notmuch] [PATCH] notmuch: Respect maildir message flags
\r
47 X-BeenThere: notmuch@notmuchmail.org
\r
48 X-Mailman-Version: 2.1.13
\r
50 List-Id: "Use and development of the notmuch mail system."
\r
51 <notmuch.notmuchmail.org>
\r
52 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
53 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
54 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
55 List-Post: <mailto:notmuch@notmuchmail.org>
\r
56 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
57 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
58 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
59 X-List-Received-Date: Tue, 16 Feb 2010 01:59:02 -0000
\r
61 New patch that does it. Pretty much same as the old one, just with
\r
62 that one bug I mentioned fixed. This is what I've currently used to
\r
63 import my Maildir. I'm now happy :)
\r
65 diff --git a/notmuch-new.c b/notmuch-new.c
\r
66 index f25c71f..43371a3 100644
\r
69 @@ -39,6 +39,7 @@ typedef struct {
\r
71 int processed_files;
\r
74 struct timeval tv_start;
\r
76 _filename_list_t *removed_files;
\r
77 @@ -169,6 +170,60 @@ _entries_resemble_maildir (struct dirent **entries, int count)
\r
81 +/* Tag new mail according to its Maildir attribute flags.
\r
83 + * Test if the mail file's filename contains any of the
\r
84 + * standard Maildir attributes, and translate these to
\r
85 + * the corresponding standard notmuch tags.
\r
87 + * If the message is not marked as 'seen', or if no
\r
88 + * flags are present, tag as 'inbox, unread'.
\r
91 +derive_tags_from_maildir_flags (notmuch_message_t *message,
\r
92 + const char * path)
\r
95 + int end_of_flags = FALSE;
\r
96 + size_t l = strlen(path);
\r
98 + /* Non-experimental message flags start with this */
\r
99 + char * i = strstr(path, ":2,");
\r
100 + i = (i) ? i : strstr(path, "!2,"); /* This format is used on VFAT */
\r
103 + for (; i < (path + l) && !end_of_flags; i++) {
\r
106 + notmuch_message_add_tag (message, "flagged");
\r
108 + case 'R': /* replied */
\r
109 + notmuch_message_add_tag (message, "answered");
\r
112 + notmuch_message_add_tag (message, "draft");
\r
114 + case 'S': /* seen */
\r
117 + case 'T': /* trashed */
\r
118 + notmuch_message_add_tag (message, "deleted");
\r
120 + case 'P': /* passed */
\r
121 + notmuch_message_add_tag (message, "forwarded");
\r
124 + end_of_flags = TRUE;
\r
130 + if (i == NULL || !seen) {
\r
131 + tag_inbox_and_unread (message);
\r
135 /* Examine 'path' recursively as follows:
\r
137 * o Ask the filesystem for the mtime of 'path' (fs_mtime)
\r
138 @@ -222,6 +277,7 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
139 notmuch_filenames_t *db_subdirs = NULL;
\r
141 notmuch_bool_t is_maildir, new_directory;
\r
142 + int maildir_detected = -1;
\r
144 if (stat (path, &st)) {
\r
145 fprintf (stderr, "Error reading directory %s: %s\n",
\r
146 @@ -301,6 +357,28 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
150 + /* If this directory is a Maildir folder, we need to
\r
151 + * ignore any subdirectories marked tmp/, and scan for
\r
152 + * Maildir attributes on messages contained in the sub-
\r
153 + * directories 'new' and 'cur'. */
\r
154 + if (maildir_detected != 0 &&
\r
155 + (entry->d_type == DT_DIR || entry->d_type == DT_UNKNOWN) &&
\r
156 + ((strcmp (entry->d_name, "tmp") == 0) ||
\r
157 + (strcmp (entry->d_name, "new") == 0) ||
\r
158 + (strcmp (entry->d_name, "cur") == 0))) {
\r
160 + if (maildir_detected == -1) {
\r
161 + maildir_detected = _entries_resemble_maildir(fs_entries, num_fs_entries);
\r
163 + if (maildir_detected == 1) {
\r
164 + if (strcmp (entry->d_name, "tmp") == 0) {
\r
167 + state->tag_maildir = TRUE;
\r
172 next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);
\r
173 status = add_files_recursive (notmuch, next, state);
\r
174 if (status && ret == NOTMUCH_STATUS_SUCCESS)
\r
175 @@ -412,7 +490,12 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
177 case NOTMUCH_STATUS_SUCCESS:
\r
178 state->added_messages++;
\r
179 - tag_inbox_and_unread (message);
\r
180 + if (state->tag_maildir) {
\r
181 + derive_tags_from_maildir_flags (message,
\r
184 + tag_inbox_and_unread (message);
\r
187 /* Non-fatal issues (go on to next file) */
\r
188 case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
\r