Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 35476431FAF for ; Fri, 20 Jan 2012 14:00:32 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id g6862dLp+x3l for ; Fri, 20 Jan 2012 14:00:31 -0800 (PST) Received: from dmz-mailsec-scanner-3.mit.edu (DMZ-MAILSEC-SCANNER-3.MIT.EDU [18.9.25.14]) by olra.theworths.org (Postfix) with ESMTP id 57D6E431FAE for ; Fri, 20 Jan 2012 14:00:31 -0800 (PST) X-AuditID: 1209190e-b7f7c6d0000008c3-ce-4f19e3fe5698 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP id A8.7C.02243.EF3E91F4; Fri, 20 Jan 2012 17:00:30 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q0KM0UiT008003; Fri, 20 Jan 2012 17:00:30 -0500 Received: from drake.mit.edu (26-4-166.dynamic.csail.mit.edu [18.26.4.166]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q0KM0Sbp019875 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Fri, 20 Jan 2012 17:00:29 -0500 (EST) Received: from amthrax by drake.mit.edu with local (Exim 4.77) (envelope-from ) id 1RoMVY-0001Zu-Ox; Fri, 20 Jan 2012 17:00:28 -0500 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH] lib: Save filenames for files detected as "not an email file" in the database. Date: Fri, 20 Jan 2012 17:00:27 -0500 Message-Id: <1327096827-5760-1-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.7.3 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprFIsWRmVeSWpSXmKPExsUixG6nrvvvsaS/weTdZhbXb85kdmD0eLbq FnMAYxSXTUpqTmZZapG+XQJXxpzpK5gK1qlWzJ17lbmBsU+ui5GTQ0LARGLW9EXsELaYxIV7 69m6GLk4hAT2MUq86l7PBOFsYJS49uYUE0iVkMBxJokVD7khEvMZJe5d2MYCkmAT0JDYtn85 I4gtIiAtsfPubNYuRg4OZgE1iT9dKiBhYYF4iV+L34FtYxFQlXj8cRWYzStgL3Hs8QUmiCsU JM6tPsc+gZF3ASPDKkbZlNwq3dzEzJzi1GTd4uTEvLzUIl1jvdzMEr3UlNJNjKAg4JTk28H4 9aDSIUYBDkYlHt7EfZL+QqyJZcWVuYcYJTmYlER51R8BhfiS8lMqMxKLM+KLSnNSiw8xSnAw K4nwlnUB5XhTEiurUovyYVLSHCxK4rxqWu/8hATSE0tSs1NTC1KLYLIyHBxKErx2wGAXEixK TU+tSMvMKUFIM3FwggznARpeAVLDW1yQmFucmQ6RP8WoKCXOGwCSEABJZJTmwfXCovQVozjQ K8K8wSBVPMAIh+t+BTSYCWiwR5MYyOCSRISUVANjt4hcFedc0+uPTPpN6ovVd+d+ul2nU/Ng T/NmvuqOV/Mv7FrIn8lv82XyihrligAr5Q6VpOlHmTVucutN2VW92T/TlWnKe/WtK6zs1t3x qC0XSQ480Cq8+Oz6i9On+FYVLAi1Vl/HwLxj/QvmRxE7/+Y5T7de8PLX7mTfe1UVr13+pKc+ iJqkxFKckWioxVxUnAgA8jibYq0CAAA= X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Jan 2012 22:00:32 -0000 Later runs of "notmuch new" won't scan these files again and won't print warnings. Various programs (Dovecot, in my case) store indexes and caches and such in the maildir. Without this, notmuch persistently complains about such files. --- Every time I run notmuch new I get a slew of these warnings. It was starting to get on my nerves, so I implemented the solution suggested by the TODO file. devel/TODO | 9 +++------ lib/database.cc | 41 +++++++++++++++++++++++++++++++++++++++++ test/new | 23 +++++++++++++++++++++++ 3 files changed, 67 insertions(+), 6 deletions(-) diff --git a/devel/TODO b/devel/TODO index 4dda6f4..b64a26e 100644 --- a/devel/TODO +++ b/devel/TODO @@ -260,12 +260,9 @@ existing messages at the next database upgrade). Add support for the user to specify custom headers to be indexed (and re-index these for existing messages at the next database upgrade). -Save filenames for files detected as "not an email file" in the -database. This would allow for two things: 1. Optimizing "notmuch new" -to not have to look at these files again (since they are potentially -large so the detection could be potentially slow). 2. A "notmuch -search" syntax could be added to allow the user to find these files, -(and perhaps delete them or move them away as appropriate). +Add a "notmuch search" syntax to allow uses to find files recorded as +non-emails in the database (and perhaps delete them or move them away +as appropriate). Fix filesystem/notmuch-new race condition by not updating database mtime for a directory if it is the same as the current mtime. diff --git a/lib/database.cc b/lib/database.cc index 8103bd9..fd1ec6e 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -1618,6 +1618,43 @@ _notmuch_database_link_message (notmuch_database_t *notmuch, return NOTMUCH_STATUS_SUCCESS; } +static notmuch_status_t +_notmuch_database_add_nonemail (notmuch_database_t *notmuch, + const char *filename) +{ + notmuch_status_t status = NOTMUCH_STATUS_SUCCESS; + void *local = talloc_new (notmuch); + char *term, *direntry; + Xapian::docid id; + + if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY) + INTERNAL_ERROR ("Failure to ensure database is writable"); + + Xapian::WritableDatabase *db = + static_cast (notmuch->xapian_db); + + /* Create a document to record the non-email */ + Xapian::Document nonemail; + term = talloc_asprintf (local, "%s%s", _find_prefix ("type"), "nonemail"); + nonemail.add_term (term, 0); + + status = _notmuch_database_filename_to_direntry (local, notmuch, + filename, &direntry); + if (status) + goto DONE; + term = talloc_asprintf (local, "%s%s", _find_prefix ("file-direntry"), + direntry); + nonemail.add_term (term, 0); + + /* Add it to the database */ + id = _notmuch_database_generate_doc_id (notmuch); + db->replace_document (id, nonemail); + + DONE: + talloc_free (local); + return status; +} + notmuch_status_t notmuch_database_add_message (notmuch_database_t *notmuch, const char *filename, @@ -1673,6 +1710,10 @@ notmuch_database_add_message (notmuch_database_t *notmuch, (subject == NULL || *subject == '\0') && (to == NULL || *to == '\0')) { + /* The file is not an email. Record it so we don't + * reconsider this file in the future, which prevents + * potentially expensive scans and annoying warnings. */ + _notmuch_database_add_nonemail (notmuch, filename); ret = NOTMUCH_STATUS_FILE_NOT_EMAIL; goto DONE; } diff --git a/test/new b/test/new index 49f390d..346d453 100755 --- a/test/new +++ b/test/new @@ -153,4 +153,27 @@ rm -rf "${MAIL_DIR}"/two output=$(NOTMUCH_NEW) test_expect_equal "$output" "No new mail. Removed 3 messages." + +test_begin_subtest "Skips non-email" +PRE_COUNT=$(notmuch search '*' | wc -l) +echo "I am not an email" > "${MAIL_DIR}"/nonemail +output=$(NOTMUCH_NEW 2>&1 | sed -n '/^Note:/p;$p' | sed 's/\(file:\) .*/\1 XXX/') +test_expect_equal "$output" "Note: Ignoring non-mail file: XXX +No new mail." + +test_begin_subtest "Non-email files are not indexed" +POST_COUNT=$(notmuch search '*' | wc -l) +test_expect_equal "$PRE_COUNT" "$POST_COUNT" + +test_begin_subtest "Ignores non-email on second pass" +touch "${MAIL_DIR}" +output=$(NOTMUCH_NEW 2>&1 | sed -n '/^Note:/p;$p' | sed 's/\(file:\) .*/\1 XXX/') +test_expect_equal "$output" "No new mail." + +test_begin_subtest "Detects deletion of non-email" +rm "${MAIL_DIR}"/nonemail +output=$(NOTMUCH_NEW) +test_expect_equal "$output" "No new mail. Removed 1 message." + + test_done -- 1.7.7.3