From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id E846C431FAF for ; Sat, 24 Nov 2012 17:17:44 -0800 (PST) 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 rjM1vO6zlpzJ for ; Sat, 24 Nov 2012 17:17:44 -0800 (PST) Received: from mail-pb0-f53.google.com (mail-pb0-f53.google.com [209.85.160.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 71815431FAE for ; Sat, 24 Nov 2012 17:17:44 -0800 (PST) Received: by mail-pb0-f53.google.com with SMTP id jt11so7944513pbb.26 for ; Sat, 24 Nov 2012 17:17:44 -0800 (PST) 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=DjRhK8c6I2lRNYLToT7tBwQ7ZlHd5+xKAmGaPXHfU3g=; b=ePz181Op+HdwzmTVDtH2pAYDsy+IQk9n25XHMj8y0tkGTuaIOnfIvIUBHRjFS/C15M ZHuLqb8s0XAaTB/uxaR1uiGL0otu2sdZqojIcIBgYyn+KxQ1oh7eTxVq6Hm8TbHl1zPU LJ01e91Xh48sHdZ/KFkLxJH4E1OiOkJC5dldqMf2Bu6umufLyc2HaY3DbQAfOyC9sIR2 4/oe5Oce71unkSpvuQgzWM8cDbZqd+upwGxk2CU3PKimsgQ/AdDJfvlBuXvdqnxbs/OS df+zjSvUkCXg9VWz0kZG7VziYb/l6X8SzoBVNHWOO9K0a+V6Z4iNHXa/LQrsiiVqhAtV Ntvg== Received: by 10.68.233.201 with SMTP id ty9mr26941590pbc.14.1353806264193; Sat, 24 Nov 2012 17:17:44 -0800 (PST) Received: from localhost (215.42.233.220.static.exetel.com.au. [220.233.42.215]) by mx.google.com with ESMTPS id ay5sm6176944pab.1.2012.11.24.17.17.41 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 24 Nov 2012 17:17:43 -0800 (PST) From: Peter Wang To: notmuch@notmuchmail.org Subject: [PATCH v2 07/20] insert: add new message to database Date: Sun, 25 Nov 2012 12:16:33 +1100 Message-Id: <1353806206-29133-8-git-send-email-novalazy@gmail.com> X-Mailer: git-send-email 1.7.12.1 In-Reply-To: <1353806206-29133-1-git-send-email-novalazy@gmail.com> References: <1353806206-29133-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: Sun, 25 Nov 2012 01:17:45 -0000 Add the new message to the notmuch database, renaming the file to encode notmuch tags as maildir flags. --- notmuch-insert.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/notmuch-insert.c b/notmuch-insert.c index 63a04dc..020dc29 100644 --- a/notmuch-insert.c +++ b/notmuch-insert.c @@ -153,6 +153,44 @@ copy_fd_data (int fdin, int fdout) return TRUE; } +/* Add the specified message file to the notmuch database. + * The file is renamed to encode notmuch tags as maildir flags. */ +static notmuch_bool_t +add_file_to_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) @@ -173,8 +211,17 @@ insert_message (void *ctx, notmuch_database_t *notmuch, int fdin, } if (!ret) { unlink (tmppath); + return FALSE; } - return ret; + + ret = add_file_to_database (notmuch, newpath); + if (!ret) { + /* XXX maybe there should be an option to keep the file in maildir? */ + unlink (newpath); + return FALSE; + } + + return TRUE; } int -- 1.7.12.1