Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 5d / fb4285165bf7d4d1a2157c7ab1334d7dcc493d
1 Return-Path: <jani@nikula.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 EF579431FAF\r
6         for <notmuch@notmuchmail.org>; Sat, 21 Jan 2012 15:00:25 -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 mELzT1vSxpN1 for <notmuch@notmuchmail.org>;\r
16         Sat, 21 Jan 2012 15:00:25 -0800 (PST)\r
17 Received: from mail-ee0-f53.google.com (mail-ee0-f53.google.com\r
18  [74.125.83.53])        (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
19  certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
20  CB812431FAE    for <notmuch@notmuchmail.org>; Sat, 21 Jan 2012 15:00:24 -0800\r
21  (PST)\r
22 Received: by eeke51 with SMTP id e51so924473eek.26\r
23         for <notmuch@notmuchmail.org>; Sat, 21 Jan 2012 15:00:22 -0800 (PST)\r
24 Received: by 10.14.94.134 with SMTP id n6mr1018516eef.63.1327186821998;\r
25         Sat, 21 Jan 2012 15:00:21 -0800 (PST)\r
26 Received: from localhost (dsl-hkibrasgw4-fe50f800-253.dhcp.inet.fi.\r
27         [84.248.80.253])\r
28         by mx.google.com with ESMTPS id 28sm31798992eed.0.2012.01.21.15.00.18\r
29         (version=SSLv3 cipher=OTHER); Sat, 21 Jan 2012 15:00:20 -0800 (PST)\r
30 From: Jani Nikula <jani@nikula.org>\r
31 To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org\r
32 Subject: Re: [PATCH] lib: Save filenames for files detected as "not an email\r
33         file" in the database.\r
34 In-Reply-To: <1327096827-5760-1-git-send-email-amdragon@mit.edu>\r
35 References: <1327096827-5760-1-git-send-email-amdragon@mit.edu>\r
36 User-Agent: Notmuch/0.11+76~g1de742d (http://notmuchmail.org) Emacs/23.3.1\r
37         (i686-pc-linux-gnu)\r
38 Date: Sun, 22 Jan 2012 01:00:17 +0200\r
39 Message-ID: <87lip0acfy.fsf@nikula.org>\r
40 MIME-Version: 1.0\r
41 X-Gm-Message-State:\r
42  ALoCoQk0Q/8QP1EusrnjJve665fElY+GfCcegQyUxCzkG8Xef9QTZLpiay8Vt+JsHnZ777tbGgC+\r
43 Content-Type: text/plain; charset=us-ascii\r
44 X-BeenThere: notmuch@notmuchmail.org\r
45 X-Mailman-Version: 2.1.13\r
46 Precedence: list\r
47 List-Id: "Use and development of the notmuch mail system."\r
48         <notmuch.notmuchmail.org>\r
49 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
50         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
51 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
52 List-Post: <mailto:notmuch@notmuchmail.org>\r
53 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
54 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
55         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
56 X-List-Received-Date: Sat, 21 Jan 2012 23:00:26 -0000\r
57 \r
58 On Fri, 20 Jan 2012 17:00:27 -0500, Austin Clements <amdragon@MIT.EDU> wrote:\r
59 > Later runs of "notmuch new" won't scan these files again and won't\r
60 > print warnings.\r
61\r
62 > Various programs (Dovecot, in my case) store indexes and caches and\r
63 > such in the maildir.  Without this, notmuch persistently complains\r
64 > about such files.\r
65 \r
66 Overall, sounds good and doing this automagically is nice. Superficially\r
67 the code looks sensible, but I didn't really dig into it. A few nasty\r
68 questions instead:\r
69 \r
70 What happens if you delete a non-email file? Does the entry stay in the\r
71 database?\r
72 \r
73 What happens if you replace a non-email file with an email file?\r
74 \r
75 Does it matter what happens above?\r
76 \r
77 These are corner cases, but what remains in TODO suggests that it would\r
78 be difficult to debug and figure out if the above ever did happen to\r
79 someone.\r
80 \r
81 \r
82 BR,\r
83 Jani.\r
84 \r
85 \r
86 > ---\r
87 > Every time I run notmuch new I get a slew of these warnings.  It was\r
88 > starting to get on my nerves, so I implemented the solution suggested\r
89 > by the TODO file.\r
90\r
91 >  devel/TODO      |    9 +++------\r
92 >  lib/database.cc |   41 +++++++++++++++++++++++++++++++++++++++++\r
93 >  test/new        |   23 +++++++++++++++++++++++\r
94 >  3 files changed, 67 insertions(+), 6 deletions(-)\r
95\r
96 > diff --git a/devel/TODO b/devel/TODO\r
97 > index 4dda6f4..b64a26e 100644\r
98 > --- a/devel/TODO\r
99 > +++ b/devel/TODO\r
100 > @@ -260,12 +260,9 @@ existing messages at the next database upgrade).\r
101 >  Add support for the user to specify custom headers to be indexed (and\r
102 >  re-index these for existing messages at the next database upgrade).\r
103 >  \r
104 > -Save filenames for files detected as "not an email file" in the\r
105 > -database. This would allow for two things: 1. Optimizing "notmuch new"\r
106 > -to not have to look at these files again (since they are potentially\r
107 > -large so the detection could be potentially slow). 2. A "notmuch\r
108 > -search" syntax could be added to allow the user to find these files,\r
109 > -(and perhaps delete them or move them away as appropriate).\r
110 > +Add a "notmuch search" syntax to allow uses to find files recorded as\r
111 > +non-emails in the database (and perhaps delete them or move them away\r
112 > +as appropriate).\r
113 >  \r
114 >  Fix filesystem/notmuch-new race condition by not updating database\r
115 >  mtime for a directory if it is the same as the current mtime.\r
116 > diff --git a/lib/database.cc b/lib/database.cc\r
117 > index 8103bd9..fd1ec6e 100644\r
118 > --- a/lib/database.cc\r
119 > +++ b/lib/database.cc\r
120 > @@ -1618,6 +1618,43 @@ _notmuch_database_link_message (notmuch_database_t *notmuch,\r
121 >      return NOTMUCH_STATUS_SUCCESS;\r
122 >  }\r
123 >  \r
124 > +static notmuch_status_t\r
125 > +_notmuch_database_add_nonemail (notmuch_database_t *notmuch,\r
126 > +                             const char *filename)\r
127 > +{\r
128 > +    notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;\r
129 > +    void *local = talloc_new (notmuch);\r
130 > +    char *term, *direntry;\r
131 > +    Xapian::docid id;\r
132 > +\r
133 > +    if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY)\r
134 > +     INTERNAL_ERROR ("Failure to ensure database is writable");\r
135 > +\r
136 > +    Xapian::WritableDatabase *db =\r
137 > +     static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db);\r
138 > +\r
139 > +    /* Create a document to record the non-email */\r
140 > +    Xapian::Document nonemail;\r
141 > +    term = talloc_asprintf (local, "%s%s", _find_prefix ("type"), "nonemail");\r
142 > +    nonemail.add_term (term, 0);\r
143 > +\r
144 > +    status = _notmuch_database_filename_to_direntry (local, notmuch,\r
145 > +                                                  filename, &direntry);\r
146 > +    if (status)\r
147 > +     goto DONE;\r
148 > +    term = talloc_asprintf (local, "%s%s", _find_prefix ("file-direntry"),\r
149 > +                         direntry);\r
150 > +    nonemail.add_term (term, 0);\r
151 > +\r
152 > +    /* Add it to the database */\r
153 > +    id = _notmuch_database_generate_doc_id (notmuch);\r
154 > +    db->replace_document (id, nonemail);\r
155 > +\r
156 > +  DONE:\r
157 > +    talloc_free (local);\r
158 > +    return status;\r
159 > +}\r
160 > +\r
161 >  notmuch_status_t\r
162 >  notmuch_database_add_message (notmuch_database_t *notmuch,\r
163 >                             const char *filename,\r
164 > @@ -1673,6 +1710,10 @@ notmuch_database_add_message (notmuch_database_t *notmuch,\r
165 >           (subject == NULL || *subject == '\0') &&\r
166 >           (to == NULL || *to == '\0'))\r
167 >       {\r
168 > +         /* The file is not an email.  Record it so we don't\r
169 > +          * reconsider this file in the future, which prevents\r
170 > +          * potentially expensive scans and annoying warnings. */\r
171 > +         _notmuch_database_add_nonemail (notmuch, filename);\r
172 >           ret = NOTMUCH_STATUS_FILE_NOT_EMAIL;\r
173 >           goto DONE;\r
174 >       }\r
175 > diff --git a/test/new b/test/new\r
176 > index 49f390d..346d453 100755\r
177 > --- a/test/new\r
178 > +++ b/test/new\r
179 > @@ -153,4 +153,27 @@ rm -rf "${MAIL_DIR}"/two\r
180 >  output=$(NOTMUCH_NEW)\r
181 >  test_expect_equal "$output" "No new mail. Removed 3 messages."\r
182 >  \r
183 > +\r
184 > +test_begin_subtest "Skips non-email"\r
185 > +PRE_COUNT=$(notmuch search '*' | wc -l)\r
186 > +echo "I am not an email" > "${MAIL_DIR}"/nonemail\r
187 > +output=$(NOTMUCH_NEW 2>&1 | sed -n '/^Note:/p;$p' | sed 's/\(file:\) .*/\1 XXX/')\r
188 > +test_expect_equal "$output" "Note: Ignoring non-mail file: XXX\r
189 > +No new mail."\r
190 > +\r
191 > +test_begin_subtest "Non-email files are not indexed"\r
192 > +POST_COUNT=$(notmuch search '*' | wc -l)\r
193 > +test_expect_equal "$PRE_COUNT" "$POST_COUNT"\r
194 > +\r
195 > +test_begin_subtest "Ignores non-email on second pass"\r
196 > +touch "${MAIL_DIR}"\r
197 > +output=$(NOTMUCH_NEW 2>&1 | sed -n '/^Note:/p;$p' | sed 's/\(file:\) .*/\1 XXX/')\r
198 > +test_expect_equal "$output" "No new mail."\r
199 > +\r
200 > +test_begin_subtest "Detects deletion of non-email"\r
201 > +rm "${MAIL_DIR}"/nonemail\r
202 > +output=$(NOTMUCH_NEW)\r
203 > +test_expect_equal "$output" "No new mail. Removed 1 message."\r
204 > +\r
205 > +\r
206 >  test_done\r
207 > -- \r
208 > 1.7.7.3\r
209\r
210 > _______________________________________________\r
211 > notmuch mailing list\r
212 > notmuch@notmuchmail.org\r
213 > http://notmuchmail.org/mailman/listinfo/notmuch\r