From: Jani Nikula Date: Thu, 5 Jun 2014 06:34:09 +0000 (+0200) Subject: [PATCH] lib: resurrect support for single-message mbox files X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=067df13917b6a72c262fc30629ba8cd2ff2a7858;p=notmuch-archives.git [PATCH] lib: resurrect support for single-message mbox files --- diff --git a/15/9586743533b3d021bd447b0dfe337b9457cf79 b/15/9586743533b3d021bd447b0dfe337b9457cf79 new file mode 100644 index 000000000..c5bd62793 --- /dev/null +++ b/15/9586743533b3d021bd447b0dfe337b9457cf79 @@ -0,0 +1,204 @@ +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 75760431FBC + for ; Wed, 4 Jun 2014 23:34:09 -0700 (PDT) +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 k9LzwSGKY-Mu for ; + Wed, 4 Jun 2014 23:34:01 -0700 (PDT) +Received: from mail-we0-f172.google.com (mail-we0-f172.google.com + [74.125.82.172]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 5B88B431FB6 + for ; Wed, 4 Jun 2014 23:34:01 -0700 (PDT) +Received: by mail-we0-f172.google.com with SMTP id k48so532662wev.17 + for ; Wed, 04 Jun 2014 23:33:59 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:from:to:cc:subject:date:message-id; + bh=X02PNLURP2Abu/qUtRjTFSJkNCwLdcHDPXw7O1Es2kU=; + b=RbSFhrJPsBj03qOzPywOJavZzijxQa6WwNtc+cOWEAcsEpbk7VlvtEJwltLQV2QM+l + DQ80xGNTPwWfVxiu5BOnGgaXt/qT7sGsFEEOhWgY6h2M4jDTnQCGZ18i1p+a/N3NYSF0 + oH3eRMb2nWdnNk0kPUJXHNXiO5L4zVY+7iY+s6q0+1yUPcVZKlPyht5RJtG4SSvfcVVz + romAid6CpCz0bJNIgEQoKOZ0QXjCO1ciPRme7yDHBK/3NEasYiS5dkjCVk0j45uD/sy6 + dcLmdEa6v0tCIyA0p7ZrRcKuNmCJ8zmSl+vvgkOj0bf7SHR5CYIrLCAWiml1HJRE+JVw + SWHQ== +X-Gm-Message-State: + ALoCoQkQreoi/toksieDz2U+qzKwo52wz4DcrgLOoVImwI2rXhvvyKGY/LX1PM0V6EKxQ9wxpOOd +X-Received: by 10.194.81.98 with SMTP id z2mr79399580wjx.12.1401950038787; + Wed, 04 Jun 2014 23:33:58 -0700 (PDT) +Received: from localhost ([2001:4b98:dc0:43:216:3eff:fe1b:25f3]) + by mx.google.com with ESMTPSA id p15sm52305473wiv.8.2014.06.04.23.33.57 + for + (version=TLSv1.1 cipher=RC4-SHA bits=128/128); + Wed, 04 Jun 2014 23:33:58 -0700 (PDT) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [PATCH] lib: resurrect support for single-message mbox files +Date: Thu, 5 Jun 2014 08:34:09 +0200 +Message-Id: <1401950049-22351-1-git-send-email-jani@nikula.org> +X-Mailer: git-send-email 1.7.2.5 +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: Thu, 05 Jun 2014 06:34:09 -0000 + +This is effectively a revert of + +commit 6812136bf576d894591606d9e10096719054d1f9 +Author: Jani Nikula +Date: Mon Mar 31 00:21:48 2014 +0300 + + lib: drop support for single-message mbox files + +The intention was to drop support for indexing new single-message mbox +files (and whether that was a good idea in the first place is +arguable). However this inadvertently broke support for reading +headers from previously indexed single-message mbox files, which is +far worse. + +Distinguishing between the two cases would require more code than +simply bringing back support for single-message mbox files. +--- + lib/message-file.c | 30 +++++++++++++++++++++++++----- + test/T050-new.sh | 26 ++++++++++++++++---------- + 2 files changed, 41 insertions(+), 15 deletions(-) + +diff --git a/lib/message-file.c b/lib/message-file.c +index 6782882..483ba1e 100644 +--- a/lib/message-file.c ++++ b/lib/message-file.c +@@ -117,7 +117,7 @@ notmuch_message_file_close (notmuch_message_file_t *message) + } + + static notmuch_bool_t +-is_mbox (FILE *file) ++_is_mbox (FILE *file) + { + char from_buf[5]; + notmuch_bool_t ret = FALSE; +@@ -139,13 +139,12 @@ _notmuch_message_file_parse (notmuch_message_file_t *message) + GMimeParser *parser; + notmuch_status_t status = NOTMUCH_STATUS_SUCCESS; + static int initialized = 0; ++ notmuch_bool_t is_mbox; + + if (message->message) + return NOTMUCH_STATUS_SUCCESS; + +- /* We no longer support mboxes at all. */ +- if (is_mbox (message->file)) +- return NOTMUCH_STATUS_FILE_NOT_EMAIL; ++ is_mbox = _is_mbox (message->file); + + if (! initialized) { + g_mime_init (GMIME_ENABLE_RFC2047_WORKAROUNDS); +@@ -163,7 +162,7 @@ _notmuch_message_file_parse (notmuch_message_file_t *message) + g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream), FALSE); + + parser = g_mime_parser_new_with_stream (stream); +- g_mime_parser_set_scan_from (parser, FALSE); ++ g_mime_parser_set_scan_from (parser, is_mbox); + + message->message = g_mime_parser_construct_message (parser); + if (! message->message) { +@@ -171,6 +170,27 @@ _notmuch_message_file_parse (notmuch_message_file_t *message) + goto DONE; + } + ++ if (is_mbox) { ++ if (! g_mime_parser_eos (parser)) { ++ /* This is a multi-message mbox. */ ++ status = NOTMUCH_STATUS_FILE_NOT_EMAIL; ++ goto DONE; ++ } ++ /* ++ * For historical reasons, we support single-message mboxes, ++ * but this behavior is likely to change in the future, so ++ * warn. ++ */ ++ static notmuch_bool_t mbox_warning = FALSE; ++ if (! mbox_warning) { ++ mbox_warning = TRUE; ++ fprintf (stderr, "\ ++Warning: %s is an mbox containing a single message,\n\ ++likely caused by misconfigured mail delivery. Support for single-message\n\ ++mboxes is deprecated and may be removed in the future.\n", message->filename); ++ } ++ } ++ + DONE: + g_object_unref (stream); + g_object_unref (parser); +diff --git a/test/T050-new.sh b/test/T050-new.sh +index 3c31954..ad46ee6 100755 +--- a/test/T050-new.sh ++++ b/test/T050-new.sh +@@ -163,6 +163,22 @@ rm -rf "${MAIL_DIR}"/two + output=$(NOTMUCH_NEW) + test_expect_equal "$output" "No new mail. Removed 3 messages." + ++test_begin_subtest "Support single-message mbox (deprecated)" ++cat > "${MAIL_DIR}"/mbox_file1 < ++To: Notmuch Test Suite ++Subject: Test mbox message 1 ++ ++Body. ++EOF ++output=$(NOTMUCH_NEW 2>&1) ++test_expect_equal "$output" \ ++"Warning: ${MAIL_DIR}/mbox_file1 is an mbox containing a single message, ++likely caused by misconfigured mail delivery. Support for single-message ++mboxes is deprecated and may be removed in the future. ++Added 1 new message to the database." ++ + # This test requires that notmuch new has been run at least once. + test_begin_subtest "Skip and report non-mail files" + generate_message +@@ -184,24 +200,14 @@ Subject: Test mbox message 2 + + Body 2. + EOF +-cat > "${MAIL_DIR}"/mbox_file1 < +-To: Notmuch Test Suite +-Subject: Test mbox message 1 +- +-Body. +-EOF + output=$(NOTMUCH_NEW 2>&1) + test_expect_equal "$output" \ + "Note: Ignoring non-mail file: ${MAIL_DIR}/.git/config + Note: Ignoring non-mail file: ${MAIL_DIR}/.ignored_hidden_file + Note: Ignoring non-mail file: ${MAIL_DIR}/ignored_file + Note: Ignoring non-mail file: ${MAIL_DIR}/mbox_file +-Note: Ignoring non-mail file: ${MAIL_DIR}/mbox_file1 + Added 1 new message to the database." + rm "${MAIL_DIR}"/mbox_file +-rm "${MAIL_DIR}"/mbox_file1 + + test_begin_subtest "Ignore files and directories specified in new.ignore" + generate_message +-- +1.7.2.5 +