Re: [PATCH v4 01/16] add util/search-path.{c, h} to test for executables in $PATH
[notmuch-archives.git] / 09 / c48512e124c65b558649f406b773ace74f8d22
1 Return-Path: <meskio@noblezabaturra.org>\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 6B15240DEED\r
6         for <notmuch@notmuchmail.org>; Fri, 19 Nov 2010 07:41:22 -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: -1.9\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5\r
12         tests=[BAYES_00=-1.9] 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 NhrncPgbpVFI for <notmuch@notmuchmail.org>;\r
16         Fri, 19 Nov 2010 07:41:10 -0800 (PST)\r
17 Received: from heal.cauterized.net (heal.cauterized.net [89.140.131.167])\r
18         by olra.theworths.org (Postfix) with ESMTP id BE70A40DEEB\r
19         for <notmuch@notmuchmail.org>; Fri, 19 Nov 2010 07:41:09 -0800 (PST)\r
20 Received: from localhost.localdomain (pb-d-128-141-44-147.cern.ch\r
21         [128.141.44.147])\r
22         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
23         (No client certificate requested)\r
24         by heal.cauterized.net (Postfix) with ESMTPSA id EAD9F7024564;\r
25         Fri, 19 Nov 2010 16:41:06 +0100 (CET)\r
26 From: meskio@sindominio.net\r
27 To: notmuch@notmuchmail.org\r
28 Subject: [PATCH] Including 'unread' tag to mails without maildir flags\r
29 Date: Fri, 19 Nov 2010 16:41:04 +0100\r
30 Message-Id: <1290181264-5900-1-git-send-email-meskio@sindominio.net>\r
31 X-Mailer: git-send-email 1.7.1\r
32 In-Reply-To: <20101118153744.GE3049@blackspot>\r
33 References: <20101118153744.GE3049@blackspot>\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: Fri, 19 Nov 2010 15:41:22 -0000\r
47 \r
48 From: Ruben Pollan <meskio@sindominio.net>\r
49 \r
50 Some mail fetchers, like fetchmail, leaves the email without ':2,' at the end of\r
51 the filename. Notmuch didn't detect this emails as maildir, it didn't add the\r
52 maildir flags to them.\r
53 \r
54 Now it detects if a mail is in a maildir by the directory structure, and add its\r
55 maildir flags correctly.\r
56 ---\r
57  lib/message.cc |   87 +++++++++++++++++++++++++++++---------------------------\r
58  1 files changed, 45 insertions(+), 42 deletions(-)\r
59 \r
60 diff --git a/lib/message.cc b/lib/message.cc\r
61 index 225b7e9..996c1df 100644\r
62 --- a/lib/message.cc\r
63 +++ b/lib/message.cc\r
64 @@ -854,6 +854,47 @@ notmuch_message_remove_tag (notmuch_message_t *message, const char *tag)\r
65      return NOTMUCH_STATUS_SUCCESS;\r
66  }\r
67  \r
68 +/* Is the given filename within a maildir directory?\r
69 + *\r
70 + * Specifically, is the final directory component of 'filename' either\r
71 + * "cur" or "new". If so, return a pointer to that final directory\r
72 + * component within 'filename'. If not, return NULL.\r
73 + *\r
74 + * A non-NULL return value is guaranteed to be a valid string pointer\r
75 + * pointing to the characters "new/" or "cur/", (but not\r
76 + * NUL-terminated).\r
77 + */\r
78 +static const char *\r
79 +_filename_is_in_maildir (const char *filename)\r
80 +{\r
81 +    const char *slash, *dir = NULL;\r
82 +\r
83 +    /* Find the last '/' separating directory from filename. */\r
84 +    slash = strrchr (filename, '/');\r
85 +    if (slash == NULL)\r
86 +       return NULL;\r
87 +\r
88 +    /* Jump back 4 characters to where the previous '/' will be if the\r
89 +     * directory is named "cur" or "new". */\r
90 +    if (slash - filename < 4)\r
91 +       return NULL;\r
92 +\r
93 +    slash -= 4;\r
94 +\r
95 +    if (*slash != '/')\r
96 +       return NULL;\r
97 +\r
98 +    dir = slash + 1;\r
99 +\r
100 +    if (STRNCMP_LITERAL (dir, "cur/") == 0 ||\r
101 +       STRNCMP_LITERAL (dir, "new/") == 0)\r
102 +    {\r
103 +       return dir;\r
104 +    }\r
105 +\r
106 +    return NULL;\r
107 +}\r
108 +\r
109  notmuch_status_t\r
110  notmuch_message_maildir_flags_to_tags (notmuch_message_t *message)\r
111  {\r
112 @@ -871,11 +912,14 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message)\r
113      {\r
114         filename = notmuch_filenames_get (filenames);\r
115  \r
116 +       if (! _filename_is_in_maildir(filename))\r
117 +           continue;\r
118 +       seen_maildir_info = 1;\r
119 +\r
120         flags = strstr (filename, ":2,");\r
121         if (! flags)\r
122             continue;\r
123  \r
124 -       seen_maildir_info = 1;\r
125         flags += 3;\r
126  \r
127         combined_flags = talloc_strdup_append (combined_flags, flags);\r
128 @@ -910,47 +954,6 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message)\r
129      return status;\r
130  }\r
131  \r
132 -/* Is the given filename within a maildir directory?\r
133 - *\r
134 - * Specifically, is the final directory component of 'filename' either\r
135 - * "cur" or "new". If so, return a pointer to that final directory\r
136 - * component within 'filename'. If not, return NULL.\r
137 - *\r
138 - * A non-NULL return value is guaranteed to be a valid string pointer\r
139 - * pointing to the characters "new/" or "cur/", (but not\r
140 - * NUL-terminated).\r
141 - */\r
142 -static const char *\r
143 -_filename_is_in_maildir (const char *filename)\r
144 -{\r
145 -    const char *slash, *dir = NULL;\r
146 -\r
147 -    /* Find the last '/' separating directory from filename. */\r
148 -    slash = strrchr (filename, '/');\r
149 -    if (slash == NULL)\r
150 -       return NULL;\r
151 -\r
152 -    /* Jump back 4 characters to where the previous '/' will be if the\r
153 -     * directory is named "cur" or "new". */\r
154 -    if (slash - filename < 4)\r
155 -       return NULL;\r
156 -\r
157 -    slash -= 4;\r
158 -\r
159 -    if (*slash != '/')\r
160 -       return NULL;\r
161 -\r
162 -    dir = slash + 1;\r
163 -\r
164 -    if (STRNCMP_LITERAL (dir, "cur/") == 0 ||\r
165 -       STRNCMP_LITERAL (dir, "new/") == 0)\r
166 -    {\r
167 -       return dir;\r
168 -    }\r
169 -\r
170 -    return NULL;\r
171 -}\r
172 -\r
173  /* From the set of tags on 'message' and the flag2tag table, compute a\r
174   * set of maildir-flag actions to be taken, (flags that should be\r
175   * either set or cleared).\r
176 -- \r
177 1.7.1\r
178 \r