From 13995f3544916d9aab22ed5611857c2f2dd6f940 Mon Sep 17 00:00:00 2001 From: Peter Wang Date: Wed, 25 Jul 2012 23:42:35 +1000 Subject: [PATCH] [PATCH 06/18] insert: add new message to database --- bf/817f46e22e3648b95664b5528344fa9a436249 | 133 ++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 bf/817f46e22e3648b95664b5528344fa9a436249 diff --git a/bf/817f46e22e3648b95664b5528344fa9a436249 b/bf/817f46e22e3648b95664b5528344fa9a436249 new file mode 100644 index 000000000..b5a45a6e6 --- /dev/null +++ b/bf/817f46e22e3648b95664b5528344fa9a436249 @@ -0,0 +1,133 @@ +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 6F9D7431FD8 + for ; Wed, 25 Jul 2012 06:43:56 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.799 +X-Spam-Level: +X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + FREEMAIL_FROM=0.001, 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 yE77LJAtnGW4 for ; + Wed, 25 Jul 2012 06:43:55 -0700 (PDT) +Received: from mail-yx0-f181.google.com (mail-yx0-f181.google.com + [209.85.213.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 8EFAB431FC2 + for ; Wed, 25 Jul 2012 06:43:45 -0700 (PDT) +Received: by yenl3 with SMTP id l3so889862yen.26 + for ; Wed, 25 Jul 2012 06:43:44 -0700 (PDT) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; + bh=5gUAsbjGjHAAUr5DeMqRKBb/VKH3tLLghlf8sVfp5uQ=; + b=cAaYqSyysxg10DY/uS17kHW4r6Y459U0jv8k8ynVK4DNR6xTi8F4CLeNH7DS6UaMyX + h9qb0QDnYIqkngoJL1u56Cy5+gS4XAac/P1Crmi3FNvqX+mYAnYSPxrY8bWy0tWmWz4O + 8GQt/Q/oWadlRe2/XQBKMqtWrOA6oQ4cocBVQM7jKG9ZdgAtofWTIJI9vXD9W5Iiz9pv + jGYwcJ80GXMPSq+8oYJsXxjdQ7jeVpaJ5I/Hwm6D56BcLEDw4Ps5wVm5UHyfop2MZoUK + 8XdalU74FX661tSHgcE7tT/wdKBbHD7ss8JB6YTMVNx3YLbiz22uN852AoVj0G3K7eF3 + 02uA== +Received: by 10.66.76.170 with SMTP id l10mr12812852paw.57.1343223824578; + Wed, 25 Jul 2012 06:43:44 -0700 (PDT) +Received: from localhost (215.42.233.220.static.exetel.com.au. + [220.233.42.215]) + by mx.google.com with ESMTPS id ng8sm14418478pbc.13.2012.07.25.06.43.41 + (version=TLSv1/SSLv3 cipher=OTHER); + Wed, 25 Jul 2012 06:43:43 -0700 (PDT) +From: Peter Wang +To: notmuch@notmuchmail.org +Subject: [PATCH 06/18] insert: add new message to database +Date: Wed, 25 Jul 2012 23:42:35 +1000 +Message-Id: <1343223767-9812-6-git-send-email-novalazy@gmail.com> +X-Mailer: git-send-email 1.7.4.4 +In-Reply-To: <1343223767-9812-1-git-send-email-novalazy@gmail.com> +References: <1343223767-9812-1-git-send-email-novalazy@gmail.com> +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, 25 Jul 2012 13:43:56 -0000 + +Add the new message to the notmuch database, renaming the file to encode +notmuch tags as maildir flags. +--- + notmuch-insert.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ + 1 files changed, 44 insertions(+), 0 deletions(-) + +diff --git a/notmuch-insert.c b/notmuch-insert.c +index bab1fed..dd449bc 100644 +--- a/notmuch-insert.c ++++ b/notmuch-insert.c +@@ -129,6 +129,42 @@ copy_fd_data (int fdin, int fdout) + } + + static notmuch_bool_t ++save_database (notmuch_database_t *notmuch, const char *path) ++{ ++ notmuch_message_t *message; ++ notmuch_status_t status; ++ ++ status = notmuch_database_add_message (notmuch, path, &message); ++ switch (status) { ++ case NOTMUCH_STATUS_SUCCESS: ++ break; ++ case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: ++ fprintf (stderr, "Warning: duplicate message.\n"); ++ break; ++ default: ++ case NOTMUCH_STATUS_FILE_NOT_EMAIL: ++ case NOTMUCH_STATUS_READ_ONLY_DATABASE: ++ case NOTMUCH_STATUS_XAPIAN_EXCEPTION: ++ case NOTMUCH_STATUS_OUT_OF_MEMORY: ++ case NOTMUCH_STATUS_FILE_ERROR: ++ case NOTMUCH_STATUS_NULL_POINTER: ++ case NOTMUCH_STATUS_TAG_TOO_LONG: ++ case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW: ++ case NOTMUCH_STATUS_UNBALANCED_ATOMIC: ++ case NOTMUCH_STATUS_LAST_STATUS: ++ fprintf (stderr, "Error: failed to add `%s' to notmuch database: %s\n", ++ path, notmuch_status_to_string (status)); ++ return FALSE; ++ } ++ ++ notmuch_message_tags_to_maildir_flags (message); ++ ++ notmuch_message_destroy (message); ++ ++ return TRUE; ++} ++ ++static notmuch_bool_t + insert_message (void *ctx, notmuch_database_t *notmuch, int fdin, + const char *dir) + { +@@ -152,6 +188,14 @@ insert_message (void *ctx, notmuch_database_t *notmuch, int fdin, + + if (!ret) { + unlink (tmppath); ++ return FALSE; ++ } ++ ++ ret = save_database (notmuch, newpath); ++ ++ if (!ret) { ++ /* XXX maybe there should be an option to keep the file in maildir? */ ++ unlink (newpath); + } + + return ret; +-- +1.7.4.4 + -- 2.26.2