Re: [PATCH 0/4] Allow specifying alternate names for addresses in other_email
[notmuch-archives.git] / f2 / 3666f8c6613a2d8c4082b3a159535a36de231a
1 Return-Path: <amthrax@drake.mit.edu>\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 35476431FAF\r
6         for <notmuch@notmuchmail.org>; Fri, 20 Jan 2012 14:00:32 -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.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\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 g6862dLp+x3l for <notmuch@notmuchmail.org>;\r
16         Fri, 20 Jan 2012 14:00:31 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-3.mit.edu (DMZ-MAILSEC-SCANNER-3.MIT.EDU\r
18         [18.9.25.14])\r
19         by olra.theworths.org (Postfix) with ESMTP id 57D6E431FAE\r
20         for <notmuch@notmuchmail.org>; Fri, 20 Jan 2012 14:00:31 -0800 (PST)\r
21 X-AuditID: 1209190e-b7f7c6d0000008c3-ce-4f19e3fe5698\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
23         by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id A8.7C.02243.EF3E91F4; Fri, 20 Jan 2012 17:00:30 -0500 (EST)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q0KM0UiT008003; \r
27         Fri, 20 Jan 2012 17:00:30 -0500\r
28 Received: from drake.mit.edu (26-4-166.dynamic.csail.mit.edu [18.26.4.166])\r
29         (authenticated bits=0)\r
30         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
31         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q0KM0Sbp019875\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Fri, 20 Jan 2012 17:00:29 -0500 (EST)\r
34 Received: from amthrax by drake.mit.edu with local (Exim 4.77)\r
35         (envelope-from <amthrax@drake.mit.edu>)\r
36         id 1RoMVY-0001Zu-Ox; Fri, 20 Jan 2012 17:00:28 -0500\r
37 From: Austin Clements <amdragon@MIT.EDU>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH] lib: Save filenames for files detected as "not an email file"\r
40         in the database.\r
41 Date: Fri, 20 Jan 2012 17:00:27 -0500\r
42 Message-Id: <1327096827-5760-1-git-send-email-amdragon@mit.edu>\r
43 X-Mailer: git-send-email 1.7.7.3\r
44 X-Brightmail-Tracker:\r
45  H4sIAAAAAAAAA+NgFprFIsWRmVeSWpSXmKPExsUixG6nrvvvsaS/weTdZhbXb85kdmD0eLbq\r
46         FnMAYxSXTUpqTmZZapG+XQJXxpzpK5gK1qlWzJ17lbmBsU+ui5GTQ0LARGLW9EXsELaYxIV7\r
47         69m6GLk4hAT2MUq86l7PBOFsYJS49uYUE0iVkMBxJokVD7khEvMZJe5d2MYCkmAT0JDYtn85\r
48         I4gtIiAtsfPubNYuRg4OZgE1iT9dKiBhYYF4iV+L34FtYxFQlXj8cRWYzStgL3Hs8QUmiCsU\r
49         JM6tPsc+gZF3ASPDKkbZlNwq3dzEzJzi1GTd4uTEvLzUIl1jvdzMEr3UlNJNjKAg4JTk28H4\r
50         9aDSIUYBDkYlHt7EfZL+QqyJZcWVuYcYJTmYlER51R8BhfiS8lMqMxKLM+KLSnNSiw8xSnAw\r
51         K4nwlnUB5XhTEiurUovyYVLSHCxK4rxqWu/8hATSE0tSs1NTC1KLYLIyHBxKErx2wGAXEixK\r
52         TU+tSMvMKUFIM3FwggznARpeAVLDW1yQmFucmQ6RP8WoKCXOGwCSEABJZJTmwfXCovQVozjQ\r
53         K8K8wSBVPMAIh+t+BTSYCWiwR5MYyOCSRISUVANjt4hcFedc0+uPTPpN6ovVd+d+ul2nU/Ng\r
54         T/NmvuqOV/Mv7FrIn8lv82XyihrligAr5Q6VpOlHmTVucutN2VW92T/TlWnKe/WtK6zs1t3x\r
55         qC0XSQ480Cq8+Oz6i9On+FYVLAi1Vl/HwLxj/QvmRxE7/+Y5T7de8PLX7mTfe1UVr13+pKc+\r
56         iJqkxFKckWioxVxUnAgA8jibYq0CAAA=\r
57 X-BeenThere: notmuch@notmuchmail.org\r
58 X-Mailman-Version: 2.1.13\r
59 Precedence: list\r
60 List-Id: "Use and development of the notmuch mail system."\r
61         <notmuch.notmuchmail.org>\r
62 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
63         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
64 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
65 List-Post: <mailto:notmuch@notmuchmail.org>\r
66 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
67 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
68         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
69 X-List-Received-Date: Fri, 20 Jan 2012 22:00:32 -0000\r
70 \r
71 Later runs of "notmuch new" won't scan these files again and won't\r
72 print warnings.\r
73 \r
74 Various programs (Dovecot, in my case) store indexes and caches and\r
75 such in the maildir.  Without this, notmuch persistently complains\r
76 about such files.\r
77 ---\r
78 Every time I run notmuch new I get a slew of these warnings.  It was\r
79 starting to get on my nerves, so I implemented the solution suggested\r
80 by the TODO file.\r
81 \r
82  devel/TODO      |    9 +++------\r
83  lib/database.cc |   41 +++++++++++++++++++++++++++++++++++++++++\r
84  test/new        |   23 +++++++++++++++++++++++\r
85  3 files changed, 67 insertions(+), 6 deletions(-)\r
86 \r
87 diff --git a/devel/TODO b/devel/TODO\r
88 index 4dda6f4..b64a26e 100644\r
89 --- a/devel/TODO\r
90 +++ b/devel/TODO\r
91 @@ -260,12 +260,9 @@ existing messages at the next database upgrade).\r
92  Add support for the user to specify custom headers to be indexed (and\r
93  re-index these for existing messages at the next database upgrade).\r
94  \r
95 -Save filenames for files detected as "not an email file" in the\r
96 -database. This would allow for two things: 1. Optimizing "notmuch new"\r
97 -to not have to look at these files again (since they are potentially\r
98 -large so the detection could be potentially slow). 2. A "notmuch\r
99 -search" syntax could be added to allow the user to find these files,\r
100 -(and perhaps delete them or move them away as appropriate).\r
101 +Add a "notmuch search" syntax to allow uses to find files recorded as\r
102 +non-emails in the database (and perhaps delete them or move them away\r
103 +as appropriate).\r
104  \r
105  Fix filesystem/notmuch-new race condition by not updating database\r
106  mtime for a directory if it is the same as the current mtime.\r
107 diff --git a/lib/database.cc b/lib/database.cc\r
108 index 8103bd9..fd1ec6e 100644\r
109 --- a/lib/database.cc\r
110 +++ b/lib/database.cc\r
111 @@ -1618,6 +1618,43 @@ _notmuch_database_link_message (notmuch_database_t *notmuch,\r
112      return NOTMUCH_STATUS_SUCCESS;\r
113  }\r
114  \r
115 +static notmuch_status_t\r
116 +_notmuch_database_add_nonemail (notmuch_database_t *notmuch,\r
117 +                               const char *filename)\r
118 +{\r
119 +    notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;\r
120 +    void *local = talloc_new (notmuch);\r
121 +    char *term, *direntry;\r
122 +    Xapian::docid id;\r
123 +\r
124 +    if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY)\r
125 +       INTERNAL_ERROR ("Failure to ensure database is writable");\r
126 +\r
127 +    Xapian::WritableDatabase *db =\r
128 +       static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db);\r
129 +\r
130 +    /* Create a document to record the non-email */\r
131 +    Xapian::Document nonemail;\r
132 +    term = talloc_asprintf (local, "%s%s", _find_prefix ("type"), "nonemail");\r
133 +    nonemail.add_term (term, 0);\r
134 +\r
135 +    status = _notmuch_database_filename_to_direntry (local, notmuch,\r
136 +                                                    filename, &direntry);\r
137 +    if (status)\r
138 +       goto DONE;\r
139 +    term = talloc_asprintf (local, "%s%s", _find_prefix ("file-direntry"),\r
140 +                           direntry);\r
141 +    nonemail.add_term (term, 0);\r
142 +\r
143 +    /* Add it to the database */\r
144 +    id = _notmuch_database_generate_doc_id (notmuch);\r
145 +    db->replace_document (id, nonemail);\r
146 +\r
147 +  DONE:\r
148 +    talloc_free (local);\r
149 +    return status;\r
150 +}\r
151 +\r
152  notmuch_status_t\r
153  notmuch_database_add_message (notmuch_database_t *notmuch,\r
154                               const char *filename,\r
155 @@ -1673,6 +1710,10 @@ notmuch_database_add_message (notmuch_database_t *notmuch,\r
156             (subject == NULL || *subject == '\0') &&\r
157             (to == NULL || *to == '\0'))\r
158         {\r
159 +           /* The file is not an email.  Record it so we don't\r
160 +            * reconsider this file in the future, which prevents\r
161 +            * potentially expensive scans and annoying warnings. */\r
162 +           _notmuch_database_add_nonemail (notmuch, filename);\r
163             ret = NOTMUCH_STATUS_FILE_NOT_EMAIL;\r
164             goto DONE;\r
165         }\r
166 diff --git a/test/new b/test/new\r
167 index 49f390d..346d453 100755\r
168 --- a/test/new\r
169 +++ b/test/new\r
170 @@ -153,4 +153,27 @@ rm -rf "${MAIL_DIR}"/two\r
171  output=$(NOTMUCH_NEW)\r
172  test_expect_equal "$output" "No new mail. Removed 3 messages."\r
173  \r
174 +\r
175 +test_begin_subtest "Skips non-email"\r
176 +PRE_COUNT=$(notmuch search '*' | wc -l)\r
177 +echo "I am not an email" > "${MAIL_DIR}"/nonemail\r
178 +output=$(NOTMUCH_NEW 2>&1 | sed -n '/^Note:/p;$p' | sed 's/\(file:\) .*/\1 XXX/')\r
179 +test_expect_equal "$output" "Note: Ignoring non-mail file: XXX\r
180 +No new mail."\r
181 +\r
182 +test_begin_subtest "Non-email files are not indexed"\r
183 +POST_COUNT=$(notmuch search '*' | wc -l)\r
184 +test_expect_equal "$PRE_COUNT" "$POST_COUNT"\r
185 +\r
186 +test_begin_subtest "Ignores non-email on second pass"\r
187 +touch "${MAIL_DIR}"\r
188 +output=$(NOTMUCH_NEW 2>&1 | sed -n '/^Note:/p;$p' | sed 's/\(file:\) .*/\1 XXX/')\r
189 +test_expect_equal "$output" "No new mail."\r
190 +\r
191 +test_begin_subtest "Detects deletion of non-email"\r
192 +rm "${MAIL_DIR}"/nonemail\r
193 +output=$(NOTMUCH_NEW)\r
194 +test_expect_equal "$output" "No new mail. Removed 1 message."\r
195 +\r
196 +\r
197  test_done\r
198 -- \r
199 1.7.7.3\r
200 \r