[PATCH] configure: add --without-api-docs option
[notmuch-archives.git] / 17 / fa9c18d6aa00fc8803137e0e878ba6340056ef
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
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.992\r
10 X-Spam-Level: \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
18         [208.97.132.74])\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
22         [129.132.133.204])\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
33         a new message\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: Mon, 01 Mar 2010 13:29:10 -0000\r
47 \r
48 When importing a new mail do check for maildir tags and assign corresponding notmuch tags.\r
49 \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
51 \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
53 \r
54 Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>\r
55 ---\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
59 \r
60 diff --git a/notmuch-new.c b/notmuch-new.c\r
61 index f25c71f..5a75950 100644\r
62 --- a/notmuch-new.c\r
63 +++ b/notmuch-new.c\r
64 @@ -39,6 +39,7 @@ typedef struct {\r
65      int total_files;\r
66      int processed_files;\r
67      int added_messages;\r
68 +    notmuch_bool_t tag_maildir;\r
69      struct timeval tv_start;\r
70  \r
71      _filename_list_t *removed_files;\r
72 @@ -169,6 +170,60 @@ _entries_resemble_maildir (struct dirent **entries, int count)\r
73      return 0;\r
74  }\r
75  \r
76 +/* Tag new mail according to its Maildir attribute flags.\r
77 + *\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
81 + *\r
82 + * If the message is not marked as 'seen', or if no\r
83 + * flags are present, tag as 'inbox, unread'.\r
84 + */\r
85 +static void\r
86 +derive_tags_from_maildir_flags (notmuch_message_t *message,\r
87 +                           const char * path)\r
88 +{\r
89 +    int seen = FALSE;\r
90 +    int end_of_flags = FALSE;\r
91 +    size_t l = strlen(path);\r
92 +\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
96 +    if (i != NULL) {\r
97 +   i += 3;\r
98 +   for (; i < (path + l) && !end_of_flags; i++) {\r
99 +       switch (*i) {\r
100 +       case 'F' :\r
101 +           notmuch_message_add_tag (message, "maildir::flagged");\r
102 +           break;\r
103 +       case 'R': /* replied */\r
104 +           notmuch_message_add_tag (message, "maildir::replied");\r
105 +           break;\r
106 +       case 'D':\r
107 +           notmuch_message_add_tag (message, "maildir::draft");\r
108 +           break;\r
109 +       case 'S': /* seen */\r
110 +           seen = TRUE;\r
111 +           break;\r
112 +       case 'T': /* trashed */\r
113 +           notmuch_message_add_tag (message, "maildir::trashed");\r
114 +           break;\r
115 +       case 'P': /* passed */\r
116 +           notmuch_message_add_tag (message, "maildir::forwarded");\r
117 +           break;\r
118 +       default:\r
119 +           end_of_flags = TRUE;\r
120 +           break;\r
121 +       }\r
122 +   }\r
123 +    }\r
124 +\r
125 +    if (i == NULL || !seen) {\r
126 +   tag_inbox_and_unread (message);\r
127 +    }\r
128 +}\r
129 +\r
130  /* Examine 'path' recursively as follows:\r
131   *\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
135         {\r
136             continue;\r
137 +       } else {\r
138 +           state->tag_maildir = TRUE;\r
139         }\r
140  \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
143         /* success */\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
149 +                                             entry->d_name);\r
150 +           } else {\r
151 +               tag_inbox_and_unread (message);\r
152 +           }\r
153             break;\r
154         /* Non-fatal issues (go on to next file) */\r
155         case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:\r
156 -- \r
157 1.6.3.3\r
158 \r