Re: Bug in emacs showing long threads
[notmuch-archives.git] / 15 / 74c52e3181aabe954a7cb6a5e4fbb36922aca0
1 Return-Path: <djcb@djcbsoftware.nl>\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 D95B0431FBC\r
6         for <notmuch@notmuchmail.org>; Sun, 10 Jan 2010 06:22:50 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 Received: from olra.theworths.org ([127.0.0.1])\r
9         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
10         with ESMTP id uvPPXZ2C0OkF for <notmuch@notmuchmail.org>;\r
11         Sun, 10 Jan 2010 06:22:49 -0800 (PST)\r
12 Received: from gw03.mail.saunalahti.fi (gw03.mail.saunalahti.fi\r
13         [195.197.172.111])\r
14         by olra.theworths.org (Postfix) with ESMTP id 61FD1431FAE\r
15         for <notmuch@notmuchmail.org>; Sun, 10 Jan 2010 06:22:49 -0800 (PST)\r
16 Received: from djcbsoftware.nl (a88-114-93-212.elisa-laajakaista.fi\r
17         [88.114.93.212])\r
18         (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))\r
19         (No client certificate requested)\r
20         by gw03.mail.saunalahti.fi (Postfix) with ESMTP id 060D42167BD\r
21         for <notmuch@notmuchmail.org>; Sun, 10 Jan 2010 16:22:44 +0200 (EET)\r
22 Received: from cthulhu.mindcrime.djcbsoftware.nl (localhost [127.0.0.1])\r
23         by djcbsoftware.nl (Postfix) with ESMTP id 8D4FB39C598\r
24         for <notmuch@notmuchmail.org>; Sun, 10 Jan 2010 16:22:20 +0200 (EET)\r
25 Date: Sun, 10 Jan 2010 16:22:20 +0200\r
26 Message-ID: <878wc69h0j.wl%djcb@djcbsoftware.nl>\r
27 From: Dirk-Jan C. Binnema <djcb.bulk@gmail.com>\r
28 To: "notmuch@notmuchmail org" <notmuch@notmuchmail.org>\r
29 Mail-Reply-To: djcb@djcbsoftware.nl\r
30 User-Agent: Wanderlust/2.15.6 (Almost Unreal) Emacs/23.1 Mule/6.0\r
31         (HANACHIRUSATO)\r
32 Organization: DJCBSoftware\r
33 MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka")\r
34 Content-Type: text/plain; charset=US-ASCII\r
35 Subject: [notmuch] [PATCH] * notmuch-new.c: refactor and improve\r
36         dirs-to-ignore a bit\r
37 X-BeenThere: notmuch@notmuchmail.org\r
38 X-Mailman-Version: 2.1.13\r
39 Precedence: list\r
40 Reply-To: djcb@djcbsoftware.nl\r
41 List-Id: "Use and development of the notmuch mail system."\r
42         <notmuch.notmuchmail.org>\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
44         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
46 List-Post: <mailto:notmuch@notmuchmail.org>\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
50 X-List-Received-Date: Sun, 10 Jan 2010 14:22:51 -0000\r
51 \r
52 \r
53 Below, an updated patch for the latest notmuch; this refractors the dir check\r
54 a bit, and adds the useful feature of making 'notmuch new' ignore directories\r
55 with a '.noindex'-file in them.\r
56 \r
57 Best wishes,\r
58 Dirk.\r
59 \r
60 ----\r
61  [PATCH] * notmuch-new.c: refactor and improve dirs-to-ignore a bit\r
62  \r
63   add a new function ignore_dir_entry, which determines whether a dir entry\r
64   should be ignored (not entered).\r
65 \r
66   dirs to ignore are: '.' and '..', '.notmuch' and 'nnmaildir' (the later from\r
67   gnus). Also, ignore dirs that contain a file called '.noindex'; thus, we can\r
68   tell not much not to consider e.g. dirs with spam messages.\r
69 ---\r
70  notmuch-new.c |   76 ++++++++++++++++++++++++++++++++++++++++++---------------\r
71  1 files changed, 56 insertions(+), 20 deletions(-)\r
72 \r
73 diff --git a/notmuch-new.c b/notmuch-new.c\r
74 index b740ee2..d1526cd 100644\r
75 --- a/notmuch-new.c\r
76 +++ b/notmuch-new.c\r
77 @@ -169,6 +169,47 @@ _entries_resemble_maildir (struct dirent **entries, int count)\r
78      return 0;\r
79  }\r
80  \r
81 +\r
82 +/* Ignore special directories to avoid infinite recursion.\r
83 + * Also ignore the .notmuch directory and any "tmp" directory\r
84 + * that appears within a maildir.\r
85 + */\r
86 +static int\r
87 +ignore_dir_entry (const char* path, struct dirent *entry)\r
88 +{\r
89 +    char noindex[4096]; /* any path will fit */\r
90 +    \r
91 +    /* ignore everything starting with a dot; this covers hidden\r
92 +     * files, as well as special dir (. and ..), but also things like\r
93 +     * gnus .nnmaildir or .notmuch */\r
94 +    \r
95 +    /* special handling for dot-dirs */\r
96 +    if (entry->d_name[0] == '.') {\r
97 +       \r
98 +       /* ignore '.' and '..' */\r
99 +       if (entry->d_name[1] == '\0' ||\r
100 +           (entry->d_name[1] == '.' && entry->d_name[2] == '\0')) \r
101 +           return 1;\r
102 +       \r
103 +       if (entry->d_name[1] == 'n')  { /* optimization */\r
104 +           /* ignore notmuch, gnus special dirs (or such-named files) */\r
105 +           if (strcmp (entry->d_name, ".notmuch") == 0 ||\r
106 +               strcmp (entry->d_name, ".nnmaildir") == 0)\r
107 +               return 1;\r
108 +       }\r
109 +    }\r
110 +    \r
111 +    /* we also check if dir contains a file called '.noindex'; if so,\r
112 +     * we ignore this directory; alloca would be suitable here, if not\r
113 +     * for the portability. */\r
114 +    snprintf (noindex, sizeof(noindex), "%s/%s/.noindex", path, entry->d_name);\r
115 +    if (access (noindex, F_OK) == 0)\r
116 +       return 1;\r
117 +\r
118 +    return 0; /* don't ignore */\r
119 +}\r
120 +\r
121 +\r
122  /* Examine 'path' recursively as follows:\r
123   *\r
124   *   o Ask the filesystem for the mtime of 'path' (fs_mtime)\r
125 @@ -275,21 +316,18 @@ add_files_recursive (notmuch_database_t *notmuch,\r
126  \r
127         if (entry->d_type != DT_DIR && entry->d_type != DT_LNK)\r
128             continue;\r
129 +       \r
130 +       /* ignore tmp Maildirs, for obvious reasons */\r
131 +       if (is_maildir && strcmp (entry->d_name, "tmp") == 0)\r
132 +           continue;\r
133  \r
134         /* Ignore special directories to avoid infinite recursion.\r
135 -        * Also ignore the .notmuch directory and any "tmp" directory\r
136 -        * that appears within a maildir.\r
137 +        * Also ignore Maildir tmp-dirs, dirs contain .noindex files, and\r
138 +        * the .notmuch and .nnmaildir directories.\r
139          */\r
140 -       /* XXX: Eventually we'll want more sophistication to let the\r
141 -        * user specify files to be ignored. */\r
142 -       if (strcmp (entry->d_name, ".") == 0 ||\r
143 -           strcmp (entry->d_name, "..") == 0 ||\r
144 -           (is_maildir && strcmp (entry->d_name, "tmp") == 0) ||\r
145 -           strcmp (entry->d_name, ".notmuch") ==0)\r
146 -       {\r
147 +       if (ignore_dir_entry (path, entry))\r
148             continue;\r
149 -       }\r
150 -\r
151 +       \r
152         next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);\r
153         status = add_files_recursive (notmuch, next, state);\r
154         if (status && ret == NOTMUCH_STATUS_SUCCESS)\r
155 @@ -575,18 +613,16 @@ count_files (const char *path, int *count)\r
156  \r
157          entry = fs_entries[i++];\r
158  \r
159 +       /* Note: it seems we're missing the '_entries_resemble_maildir' check\r
160 +        * here */\r
161 +       \r
162         /* Ignore special directories to avoid infinite recursion.\r
163 -        * Also ignore the .notmuch directory.\r
164 +        * Also ignore Maildir tmp-dirs, dirs contain .noindex files, and\r
165 +        * the .notmuch and .nnmaildir directories.\r
166          */\r
167 -       /* XXX: Eventually we'll want more sophistication to let the\r
168 -        * user specify files to be ignored. */\r
169 -       if (strcmp (entry->d_name, ".") == 0 ||\r
170 -           strcmp (entry->d_name, "..") == 0 ||\r
171 -           strcmp (entry->d_name, ".notmuch") == 0)\r
172 -       {\r
173 +       if (ignore_dir_entry (path, entry))\r
174             continue;\r
175 -       }\r
176 -\r
177 +       \r
178         if (asprintf (&next, "%s/%s", path, entry->d_name) == -1) {\r
179             next = NULL;\r
180             fprintf (stderr, "Error descending from %s to %s: Out of memory\n",\r
181 -- \r
182 1.6.3.3\r
183 \r
184 -- \r
185 Dirk-Jan C. Binnema                  Helsinki, Finland\r
186 e:djcb@djcbsoftware.nl           w:www.djcbsoftware.nl\r
187 pgp: D09C E664 897D 7D39 5047 A178 E96A C7A1 017D DA3C\r