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 529E0429E29 for ; Sat, 19 Jan 2013 16:51:07 -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 AunlE-0+pQqC for ; Sat, 19 Jan 2013 16:51:06 -0800 (PST) Received: from mail-pb0-f48.google.com (mail-pb0-f48.google.com [209.85.160.48]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 8C7AE431FDE for ; Sat, 19 Jan 2013 16:50:58 -0800 (PST) Received: by mail-pb0-f48.google.com with SMTP id wy12so1317990pbc.7 for ; Sat, 19 Jan 2013 16:50:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=Bzx58UkTThN5g0PYx2nrUbbkWjWhx6/7oCLg5+dn2T8=; b=dO5F4futU6W1Yot/SOIm2WBgWgx80vld61YLjWhvAE/zMJTfp/y34FJw05uq8pdkzg B6c4hJivfgn7eGVK6TauqW7sec6rKzN/FrMkqBgdROd5tToITNM9Kb+DCRfikI54G0aS 8L7w8C80/u0OqFCFeAlonYpj/s9P+Zy7I1PaUnPmmM83wD+SUWNF3iEs3bGMIstrdqma WynF51cT8W1hF3M8Lac7UebEFhHGmJjJAdZDLfPnzwgKaVhtYv1tjXdXoe3ycnJBB3JL BVveJ0RJNaAgipsFuhHDt7Z2x9QmV5+EzKqjWoStR0MQUiRJXT97i779l5yPEWyYcejx LYxg== X-Received: by 10.68.190.227 with SMTP id gt3mr18619897pbc.5.1358643057683; Sat, 19 Jan 2013 16:50:57 -0800 (PST) Received: from localhost (215.42.233.220.static.exetel.com.au. [220.233.42.215]) by mx.google.com with ESMTPS id oi3sm5811059pbb.1.2013.01.19.16.50.55 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 19 Jan 2013 16:50:57 -0800 (PST) From: Peter Wang To: notmuch@notmuchmail.org Subject: [PATCH v3 05/20] insert: add new message to database Date: Sun, 20 Jan 2013 11:49:49 +1100 Message-Id: <1358643004-14522-6-git-send-email-novalazy@gmail.com> X-Mailer: git-send-email 1.7.12.1 In-Reply-To: <1358643004-14522-1-git-send-email-novalazy@gmail.com> References: <1358643004-14522-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, 20 Jan 2013 00:51:08 -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 c0289d9..498421d 100644 --- a/notmuch-insert.c +++ b/notmuch-insert.c @@ -153,6 +153,44 @@ copy_stdin (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