Re: [DRAFT PATCH] emacs: support limiting the number of results shown in search results
[notmuch-archives.git] / 6a / fb1b366f9f4774aa7fbd995d7b6d1aaebadf7a
1 Return-Path: <jan@ryngle.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 0641B431FBC\r
6         for <notmuch@notmuchmail.org>; Wed, 25 Nov 2009 13:11:52 -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 QanLcv70ysoJ for <notmuch@notmuchmail.org>;\r
11         Wed, 25 Nov 2009 13:11:51 -0800 (PST)\r
12 Received: from mail-ew0-f213.google.com (mail-ew0-f213.google.com\r
13         [209.85.219.213])\r
14         by olra.theworths.org (Postfix) with ESMTP id 3D355431FAE\r
15         for <notmuch@notmuchmail.org>; Wed, 25 Nov 2009 13:11:51 -0800 (PST)\r
16 Received: by ewy5 with SMTP id 5so132569ewy.30\r
17         for <notmuch@notmuchmail.org>; Wed, 25 Nov 2009 13:11:50 -0800 (PST)\r
18 Received: by 10.213.1.7 with SMTP id 7mr7115660ebd.27.1259183507974;\r
19         Wed, 25 Nov 2009 13:11:47 -0800 (PST)\r
20 Received: from x61s.janakj ([213.192.30.141])\r
21         by mx.google.com with ESMTPS id 7sm225193eyb.42.2009.11.25.13.11.46\r
22         (version=TLSv1/SSLv3 cipher=RC4-MD5);\r
23         Wed, 25 Nov 2009 13:11:47 -0800 (PST)\r
24 Received: by x61s.janakj (Postfix, from userid 1000)\r
25         id 8140C440655; Wed, 25 Nov 2009 22:11:45 +0100 (CET)\r
26 From: Jan Janak <jan@ryngle.com>\r
27 To: notmuch@notmuchmail.org\r
28 Date: Wed, 25 Nov 2009 22:11:45 +0100\r
29 Message-Id: <1259183505-30840-1-git-send-email-jan@ryngle.com>\r
30 X-Mailer: git-send-email 1.6.3.3\r
31 In-Reply-To: <1259178195-30324-1-git-send-email-jan@ryngle.com>\r
32 References: <1259178195-30324-1-git-send-email-jan@ryngle.com>\r
33 Subject: [notmuch] [PATCH] notmuch-new: Test if directory looks like Maildir\r
34         before skipping tmp.\r
35 X-BeenThere: notmuch@notmuchmail.org\r
36 X-Mailman-Version: 2.1.12\r
37 Precedence: list\r
38 List-Id: "Use and development of the notmuch mail system."\r
39         <notmuch.notmuchmail.org>\r
40 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
41         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
43 List-Post: <mailto:notmuch@notmuchmail.org>\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
45 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
46         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
47 X-List-Received-Date: Wed, 25 Nov 2009 21:11:52 -0000\r
48 \r
49 'notmuch new' skips directory entries with the name 'tmp'. This is to\r
50 prevent notmuch from processing possibly incomplete Maildir messages\r
51 stored in that directory.\r
52 \r
53 This patch attempts to refine the feature. If "tmp" entry is found,\r
54 it first checks if the containing directory looks like a Maildir\r
55 directory. This is done by searching for other common Maildir\r
56 subdirectories. If they exist and if the entry "tmp" is a directory\r
57 then it is skipped.\r
58 \r
59 Files and subdirectories with the name "tmp" that do not look like\r
60 Maildir will still be processed by 'notmuch new'.\r
61 \r
62 Signed-off-by: Jan Janak <jan@ryngle.com>\r
63 ---\r
64  notmuch-new.c |   29 ++++++++++++++++++++++++++++-\r
65  1 files changed, 28 insertions(+), 1 deletions(-)\r
66 \r
67 diff --git a/notmuch-new.c b/notmuch-new.c\r
68 index e32b92a..10dc72b 100644\r
69 --- a/notmuch-new.c\r
70 +++ b/notmuch-new.c\r
71 @@ -80,6 +80,31 @@ static int ino_cmp(const struct dirent **a, const struct dirent **b)\r
72      return ((*a)->d_ino < (*b)->d_ino) ? -1 : 1;\r
73  }\r
74  \r
75 +/* Test if the directory looks like a Maildir directory.\r
76 + *\r
77 + * Search through the array of directory entries to see if we can find all\r
78 + * three subdirectories typical for Maildir, that is "new", "cur", and "tmp".\r
79 + *\r
80 + * Return 1 if the directory looks like a Maildir and 0 otherwise.\r
81 + */\r
82 +static int is_maildir (struct dirent **entries, int count)\r
83 +{\r
84 +    int i, found = 0;\r
85 +\r
86 +    for (i = 0; i < count; i++) {\r
87 +       if (entries[i]->d_type != DT_DIR) continue;\r
88 +       if (strcmp(entries[i]->d_name, "new") == 0 ||\r
89 +           strcmp(entries[i]->d_name, "cur") == 0 ||\r
90 +           strcmp(entries[i]->d_name, "tmp") == 0)\r
91 +       {\r
92 +           found++;\r
93 +           if (found == 3) return 1;\r
94 +       }\r
95 +    }\r
96 +\r
97 +    return 0;\r
98 +}\r
99 +\r
100  /* Examine 'path' recursively as follows:\r
101   *\r
102   *   o Ask the filesystem for the mtime of 'path' (path_mtime)\r
103 @@ -159,7 +184,9 @@ add_files_recursive (notmuch_database_t *notmuch,\r
104          * user specify files to be ignored. */\r
105         if (strcmp (entry->d_name, ".") == 0 ||\r
106             strcmp (entry->d_name, "..") == 0 ||\r
107 -           strcmp (entry->d_name, "tmp") == 0 ||\r
108 +           (entry->d_type == DT_DIR &&\r
109 +            (strcmp (entry->d_name, "tmp") == 0) &&\r
110 +            is_maildir (namelist, num_entries)) ||\r
111             strcmp (entry->d_name, ".notmuch") ==0)\r
112         {\r
113             continue;\r
114 -- \r
115 1.6.3.3\r
116 \r