Re: bug#6214: 23.1; json-read-string crashes emacs with long string
[notmuch-archives.git] / 07 / 0c7ec7b390924875a2fd51abbe9a86c181c13e
1 Return-Path: <notmuch@stoakes.net>\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 02B43431FAE\r
6         for <notmuch@notmuchmail.org>; Tue,  9 Feb 2010 19:23:08 -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: -2.599\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-2.599 tagged_above=-999 required=5\r
12         tests=[BAYES_00=-2.599] autolearn=unavailable\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 t6LIzCYvEBo4 for <notmuch@notmuchmail.org>;\r
16         Tue,  9 Feb 2010 19:23:06 -0800 (PST)\r
17 Received: from outbound-mail04.westnet.com.au (outbound-mail04.westnet.com.au\r
18         [203.10.1.245])\r
19         by olra.theworths.org (Postfix) with ESMTP id 5F6F8431FBC\r
20         for <notmuch@notmuchmail.org>; Tue,  9 Feb 2010 19:23:05 -0800 (PST)\r
21 X-IronPort-Anti-Spam-Filtered: true\r
22 X-IronPort-Anti-Spam-Result: AvsEAFCzcUvKrYlp/2dsb2JhbACaZHW9Z4RUBA\r
23 X-IronPort-AV: E=Sophos;i="4.49,440,1262534400"; d="scan'208";a="19317446"\r
24 Received: from dsl-202-173-137-105.sa.westnet.com.au (HELO mail.stoakes.net)\r
25         ([202.173.137.105])\r
26         by outbound-mail04.westnet.com.au with ESMTP/TLS/ADH-CAMELLIA256-SHA;\r
27         10 Feb 2010 11:13:43 +0800\r
28 Received: from noodle.stoakes.net (unknown [192.168.20.220])\r
29         by mail.stoakes.net (Postfix) with ESMTP id 15CD9EE486;\r
30         Wed, 10 Feb 2010 13:43:40 +1030 (CST)\r
31 Received: by noodle.stoakes.net (Postfix, from userid 1000)\r
32         id 7C9677F0BD; Wed, 10 Feb 2010 13:43:39 +1030 (CST)\r
33 Date: Wed, 10 Feb 2010 13:43:39 +1030\r
34 From: Tim Stoakes <notmuch@stoakes.net>\r
35 To: Michiel Buddingh' <michiel@michielbuddingh.net>\r
36 Message-ID: <20100210031339.GH16686@mail.rocksoft.com>\r
37 References: <87bpiv4t9h.fsf@yoom.home.cworth.org>\r
38         <87y6lz39nd.fsf@yoom.home.cworth.org>\r
39         <20091121221207.GB17268@jukie.net>\r
40         <9cce5525b093b87fe74d427954ffad89@localhost>\r
41         <87d43b2oif.fsf@yoom.home.cworth.org>\r
42         <9bfdedddeab9c58cd45d8d448323d0fc@localhost>\r
43         <87skc23327.fsf@yoom.home.cworth.org>\r
44         <4b0eef22.JwxdgTGElffx149F%michiel@michielbuddingh.net>\r
45         <87ws1bjpmm.fsf@yoom.home.cworth.org> <878wdfkhcl.fsf@aegir.org.uk>\r
46 MIME-Version: 1.0\r
47 Content-Type: text/plain; charset=us-ascii\r
48 Content-Disposition: inline\r
49 In-Reply-To: <878wdfkhcl.fsf@aegir.org.uk>\r
50 User-Agent: Mutt/1.5.20 (2009-06-14)\r
51 Cc: notmuch@notmuchmail.org\r
52 Subject: Re: [notmuch] [PATCH] notmuch: Respect maildir message flags\r
53 X-BeenThere: notmuch@notmuchmail.org\r
54 X-Mailman-Version: 2.1.13\r
55 Precedence: list\r
56 List-Id: "Use and development of the notmuch mail system."\r
57         <notmuch.notmuchmail.org>\r
58 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
59         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
60 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
61 List-Post: <mailto:notmuch@notmuchmail.org>\r
62 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
63 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
64         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
65 X-List-Received-Date: Wed, 10 Feb 2010 03:23:08 -0000\r
66 \r
67 Michiel Buddingh'(michiel@michielbuddingh.net)@061209-20:55:\r
68 >\r
69 ...\r
70 > A new patch is attached.  Apologies for the rather verbose Maildir\r
71 > handling logic, but I couldn't find a way to minimize the calls to\r
72 > is_maildir that was both neat and readable.\r
73 \r
74 \r
75 Hi notmuch-ers,\r
76 \r
77 My apologies for dredging up an old thread. I don't want to restart the\r
78 religious war over whether notmuch should respect Maildir flags -\r
79 suffice to say that *I* want that, and the patch posted by Michiel\r
80 seemed to be the best way to make that happen.\r
81 \r
82 Since it no longer applies cleanly, I've ported it forward to\r
83 79d3f9773c58d6fd7113871362687d8cfc0b1a59, to save someone else the\r
84 trouble. It works for me, but that's all the testing I've done.\r
85 \r
86 Tim\r
87 \r
88 -- \r
89 Tim Stoakes\r
90 \r
91 \r
92 \r
93 ---\r
94  notmuch-new.c |   86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-\r
95  1 files changed, 85 insertions(+), 1 deletions(-)\r
96 \r
97 diff --git a/notmuch-new.c b/notmuch-new.c\r
98 index f25c71f..3264653 100644\r
99 --- a/notmuch-new.c\r
100 +++ b/notmuch-new.c\r
101 @@ -39,6 +39,7 @@ typedef struct {\r
102      int total_files;\r
103      int processed_files;\r
104      int added_messages;\r
105 +    int tag_maildir;\r
106      struct timeval tv_start;\r
107  \r
108      _filename_list_t *removed_files;\r
109 @@ -169,6 +170,60 @@ _entries_resemble_maildir (struct dirent **entries, int count)\r
110      return 0;\r
111  }\r
112  \r
113 +/* Tag new mail according to its Maildir attribute flags.\r
114 + *\r
115 + * Test if the mail file's filename contains any of the\r
116 + * standard Maildir attributes, and translate these to\r
117 + * the corresponding standard notmuch tags.\r
118 + *\r
119 + * If the message is not marked as 'seen', or if no\r
120 + * flags are present, tag as 'inbox, unread'.\r
121 + */\r
122 +static void\r
123 +derive_tags_from_maildir_flags (notmuch_message_t *message,\r
124 +                               const char * path)\r
125 +{\r
126 +    int seen = FALSE;\r
127 +    int end_of_flags = FALSE;\r
128 +    size_t l = strlen(path);\r
129 +\r
130 +    /* Non-experimental message flags start with this */\r
131 +    char * i = strstr(path, ":2,");\r
132 +    i = (i) ? i : strstr(path, "!2,"); /* This format is used on VFAT */\r
133 +    if (i != NULL) {\r
134 +       i += 3;\r
135 +       for (; i < (path + l) && !end_of_flags; i++) {\r
136 +           switch (*i) {\r
137 +           case 'F' :\r
138 +               notmuch_message_add_tag (message, "flagged");\r
139 +               break;\r
140 +           case 'R': /* replied */\r
141 +               notmuch_message_add_tag (message, "answered");\r
142 +               break;\r
143 +           case 'D':\r
144 +               notmuch_message_add_tag (message, "draft");\r
145 +               break;\r
146 +           case 'S': /* seen */\r
147 +               seen = TRUE;\r
148 +               break;\r
149 +           case 'T': /* trashed */\r
150 +               notmuch_message_add_tag (message, "deleted");\r
151 +               break;\r
152 +           case 'P': /* passed */\r
153 +               notmuch_message_add_tag (message, "forwarded");\r
154 +               break;\r
155 +           default:\r
156 +               end_of_flags = TRUE;\r
157 +               break;\r
158 +           }\r
159 +       }\r
160 +    }\r
161 +\r
162 +    if (i == NULL || !seen) {\r
163 +       tag_inbox_and_unread (message);\r
164 +    }\r
165 +}\r
166 +\r
167  /* Examine 'path' recursively as follows:\r
168   *\r
169   *   o Ask the filesystem for the mtime of 'path' (fs_mtime)\r
170 @@ -222,6 +277,7 @@ add_files_recursive (notmuch_database_t *notmuch,\r
171      notmuch_filenames_t *db_subdirs = NULL;\r
172      struct stat st;\r
173      notmuch_bool_t is_maildir, new_directory;\r
174 +    int maildir_detected = -1;\r
175  \r
176      if (stat (path, &st)) {\r
177         fprintf (stderr, "Error reading directory %s: %s\n",\r
178 @@ -301,6 +357,28 @@ add_files_recursive (notmuch_database_t *notmuch,\r
179             continue;\r
180         }\r
181  \r
182 +       /* If this directory is a Maildir folder, we need to\r
183 +        * ignore any subdirectories marked tmp/, and scan for\r
184 +        * Maildir attributes on messages contained in the sub-\r
185 +        * directories 'new' and 'cur'. */\r
186 +       if (maildir_detected != 0 &&\r
187 +           entry->d_type == DT_DIR &&\r
188 +           ((strcmp (entry->d_name, "tmp") == 0) ||\r
189 +            (strcmp (entry->d_name, "new") == 0) ||\r
190 +            (strcmp (entry->d_name, "cur") == 0))) {\r
191 +\r
192 +    if (maildir_detected == -1) {\r
193 +      maildir_detected = _entries_resemble_maildir(fs_entries, num_fs_entries);\r
194 +    }\r
195 +    if (maildir_detected == 1) {\r
196 +      if (strcmp (entry->d_name, "tmp") == 0) {\r
197 +        continue;\r
198 +      } else {\r
199 +        state->tag_maildir = TRUE;\r
200 +      }\r
201 +    }\r
202 +  }\r
203 +\r
204         next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);\r
205         status = add_files_recursive (notmuch, next, state);\r
206         if (status && ret == NOTMUCH_STATUS_SUCCESS)\r
207 @@ -412,7 +490,12 @@ add_files_recursive (notmuch_database_t *notmuch,\r
208         /* success */\r
209         case NOTMUCH_STATUS_SUCCESS:\r
210             state->added_messages++;\r
211 -           tag_inbox_and_unread (message);\r
212 +                       if (state->tag_maildir) {\r
213 +                           derive_tags_from_maildir_flags (message,\r
214 +                                                           entry->d_name);\r
215 +                       } else {\r
216 +                           tag_inbox_and_unread (message);\r
217 +                       }\r
218             break;\r
219         /* Non-fatal issues (go on to next file) */\r
220         case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:\r
221 @@ -482,6 +565,7 @@ add_files_recursive (notmuch_database_t *notmuch,\r
222         status = notmuch_directory_set_mtime (directory, fs_mtime);\r
223         if (status && ret == NOTMUCH_STATUS_SUCCESS)\r
224             ret = status;\r
225 +           state->tag_maildir = FALSE;\r
226      }\r
227  \r
228    DONE:\r
229 -- \r
230 1.6.6.1\r
231 \r