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 4723A431FC9 for ; Wed, 16 Oct 2013 12:00:56 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" 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 4xnvVTdj44HF for ; Wed, 16 Oct 2013 12:00:50 -0700 (PDT) Received: from mail-ee0-f47.google.com (mail-ee0-f47.google.com [74.125.83.47]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 89CF6431FCB for ; Wed, 16 Oct 2013 12:00:32 -0700 (PDT) Received: by mail-ee0-f47.google.com with SMTP id d49so580916eek.34 for ; Wed, 16 Oct 2013 12:00:31 -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:in-reply-to :references:in-reply-to:references; bh=IH2SnVvGIXirOVHbhtKFi5hslXx4SV/xHhXd74UpFvw=; b=YT6uMPJLlKkalWG/pBb1nW+FcpqJZ+Kkmb5kWGEWuUCTtqzNt+YCvtJzN78vD818I/ d4LsM7VZjcYakb290At19+aTPBGc6POz8fjkC4Pp+yaPAT6HJoOEDaJUe4NH80hXlUYn 7smZCIP6q+81YqiS9PAuPs1pQGjZiBUPADxO5vp/tgjeFxpTwbwbf2uioihTx1hG0eti MsMEF9EM26DtYYlbT/pm4a3/O9m/zrpDcsOpbtnNIKxk7qdFW0GoqKRf1YJOYt1Y4bhg 1K5za0pRzGuKUav45u90UpEtqicxMHI1Kt5+4bs7YHgWMuoOUpvprsrXc2qr9Ifv5fbD pr+g== X-Gm-Message-State: ALoCoQnce8xInrJkX9gAilVZY8VijkrB49iW7IgcEFKIuSiQgeOWIQkL9x49RomZdCklShSqp0Rv X-Received: by 10.15.53.132 with SMTP id r4mr6878687eew.5.1381950031441; Wed, 16 Oct 2013 12:00:31 -0700 (PDT) Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi. [88.195.111.91]) by mx.google.com with ESMTPSA id m54sm182872688eex.2.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 16 Oct 2013 12:00:30 -0700 (PDT) From: Jani Nikula To: notmuch@notmuchmail.org Subject: [PATCH 5/6] lib: parse messages only once Date: Wed, 16 Oct 2013 22:00:12 +0300 Message-Id: X-Mailer: git-send-email 1.8.4.rc3 In-Reply-To: References: In-Reply-To: References: 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: Wed, 16 Oct 2013 19:00:56 -0000 Make the necessary changes to only do one gmime parse pass during indexing. --- lib/database.cc | 2 +- lib/index.cc | 70 +++++---------------------------------------------- lib/message-file.c | 9 +++++++ lib/notmuch-private.h | 15 +++++++++-- 4 files changed, 29 insertions(+), 67 deletions(-) diff --git a/lib/database.cc b/lib/database.cc index 45a3987..d097dda 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -1996,7 +1996,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch, date = notmuch_message_file_get_header (message_file, "date"); _notmuch_message_set_header_values (message, date, from, subject); - ret = _notmuch_message_index_file (message, filename); + ret = _notmuch_message_index_file (message, message_file); if (ret) goto DONE; } else { diff --git a/lib/index.cc b/lib/index.cc index 78c18cf..71397da 100644 --- a/lib/index.cc +++ b/lib/index.cc @@ -425,63 +425,15 @@ _index_mime_part (notmuch_message_t *message, notmuch_status_t _notmuch_message_index_file (notmuch_message_t *message, - const char *filename) + notmuch_message_file_t *message_file) { - GMimeStream *stream = NULL; - GMimeParser *parser = NULL; - GMimeMessage *mime_message = NULL; + GMimeMessage *mime_message; InternetAddressList *addresses; - FILE *file = NULL; const char *from, *subject; - notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS; - static int initialized = 0; - char from_buf[5]; - bool is_mbox = false; - static bool mbox_warning = false; - - if (! initialized) { - g_mime_init (GMIME_ENABLE_RFC2047_WORKAROUNDS); - initialized = 1; - } - - file = fopen (filename, "r"); - if (! file) { - fprintf (stderr, "Error opening %s: %s\n", filename, strerror (errno)); - ret = NOTMUCH_STATUS_FILE_ERROR; - goto DONE; - } - - /* Is this mbox? */ - if (fread (from_buf, sizeof (from_buf), 1, file) == 1 && - strncmp (from_buf, "From ", 5) == 0) - is_mbox = true; - rewind (file); - /* Evil GMime steals my FILE* here so I won't fclose it. */ - stream = g_mime_stream_file_new (file); - - parser = g_mime_parser_new_with_stream (stream); - g_mime_parser_set_scan_from (parser, is_mbox); - - mime_message = g_mime_parser_construct_message (parser); - - if (is_mbox) { - if (!g_mime_parser_eos (parser)) { - /* This is a multi-message mbox. */ - ret = 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. */ - 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", filename); - } - } + mime_message = notmuch_message_file_get_mime_message (message_file); + if (! mime_message) + return NOTMUCH_STATUS_FILE_NOT_EMAIL; /* more like internal error */ from = g_mime_message_get_sender (mime_message); @@ -502,15 +454,5 @@ mboxes is deprecated and may be removed in the future.\n", filename); _index_mime_part (message, g_mime_message_get_mime_part (mime_message)); - DONE: - if (mime_message) - g_object_unref (mime_message); - - if (parser) - g_object_unref (parser); - - if (stream) - g_object_unref (stream); - - return ret; + return NOTMUCH_STATUS_SUCCESS; } diff --git a/lib/message-file.c b/lib/message-file.c index 9d5a3b9..7ab9e9d 100644 --- a/lib/message-file.c +++ b/lib/message-file.c @@ -247,6 +247,15 @@ mboxes is deprecated and may be removed in the future.\n", message->filename); return NOTMUCH_STATUS_SUCCESS; } +GMimeMessage * +notmuch_message_file_get_mime_message (notmuch_message_file_t *message) +{ + if (! message->parsed) + return NULL; + + return message->message; +} + /* return NULL on errors, empty string for non-existing headers */ const char * notmuch_message_file_get_header (notmuch_message_file_t *message, diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h index 7277df1..048dd6c 100644 --- a/lib/notmuch-private.h +++ b/lib/notmuch-private.h @@ -46,6 +46,8 @@ NOTMUCH_BEGIN_DECLS #include +#include + #include "xutil.h" #include "error_util.h" @@ -320,9 +322,11 @@ notmuch_message_get_author (notmuch_message_t *message); /* index.cc */ +typedef struct _notmuch_message_file notmuch_message_file_t; + notmuch_status_t _notmuch_message_index_file (notmuch_message_t *message, - const char *filename); + notmuch_message_file_t *message_file); /* message-file.c */ @@ -330,7 +334,6 @@ _notmuch_message_index_file (notmuch_message_t *message, * into the public interface in notmuch.h */ -typedef struct _notmuch_message_file notmuch_message_file_t; /* Open a file containing a single email message. * @@ -377,6 +380,14 @@ void notmuch_message_file_restrict_headersv (notmuch_message_file_t *message, va_list va_headers); +/* + * get mime message. this is an ugly interface; maybe join index.cc + * and message-file.c, or move the top level indexing call to + * message-file.c with helpers in index.cc + */ +GMimeMessage * +notmuch_message_file_get_mime_message (notmuch_message_file_t *message); + /* Get the value of the specified header from the message as a UTF-8 string. * * The header name is case insensitive. -- 1.8.4.rc3