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 338E9431FC2 for ; Wed, 25 Jul 2012 06:44:04 -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 akMMZ0lKHMGL for ; Wed, 25 Jul 2012 06:44:03 -0700 (PDT) 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 5E8BE431FAE for ; Wed, 25 Jul 2012 06:44:03 -0700 (PDT) Received: by mail-pb0-f53.google.com with SMTP id rr13so1767731pbb.26 for ; Wed, 25 Jul 2012 06:44:03 -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=bNNuP4P8lhanPTTFOlvGDB5KvUQsfrN03C6SvE3x15k=; b=lppGPsH5x16fzrRM5DgGjJyZ2pQ5TGbWuQ6B0kIZJPJ3mtFVpvPmubUGbs1DsDoepO uSjpghVruxsYiWvfgfzqbBxVVqISPTWfpvwqpzIkQTDS90dUUgZRVBHaU7F9rSDUs5gb cBqDiN8GidygzizQCVRptrBqcdY//YSVW8Zm1YVExQ34oaUZ/pQaLt2OO92g1s6c3fVP urxj0TuPTRHcfNjB557wRZavprIbEoQJF6m42GvQw/TCrBwz/2xuIexBwF6VgxDyAolH M6+IK8imH5X2ucaYKYUdjKswC+lK0l17AerenhGUkMfJQcDec28DXPOwfA7INBScAkGo jLyg== Received: by 10.68.220.163 with SMTP id px3mr54578208pbc.167.1343223843181; Wed, 25 Jul 2012 06:44:03 -0700 (PDT) Received: from localhost (215.42.233.220.static.exetel.com.au. [220.233.42.215]) by mx.google.com with ESMTPS id wi6sm14414134pbc.35.2012.07.25.06.44.00 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 25 Jul 2012 06:44:02 -0700 (PDT) From: Peter Wang To: notmuch@notmuchmail.org Subject: [PATCH 09/18] insert: apply default tags to new message Date: Wed, 25 Jul 2012 23:42:38 +1000 Message-Id: <1343223767-9812-9-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:44:04 -0000 Apply the new.tags to messages added by 'insert'. This mirrors the behaviour if the message were delivered by a separate tool followed by 'notmuch new'. --- notmuch-insert.c | 21 +++++++++++++++++---- 1 files changed, 17 insertions(+), 4 deletions(-) diff --git a/notmuch-insert.c b/notmuch-insert.c index ee51a87..4fb3ea3 100644 --- a/notmuch-insert.c +++ b/notmuch-insert.c @@ -145,10 +145,12 @@ copy_fd_data (int fdin, int fdout) } static notmuch_bool_t -save_database (notmuch_database_t *notmuch, const char *path) +save_database (notmuch_database_t *notmuch, const char *path, + const char **new_tags) { notmuch_message_t *message; notmuch_status_t status; + int i; status = notmuch_database_add_message (notmuch, path, &message); switch (status) { @@ -173,6 +175,14 @@ save_database (notmuch_database_t *notmuch, const char *path) return FALSE; } + notmuch_message_freeze (message); + + for (i = 0; new_tags[i]; i++) { + notmuch_message_add_tag (message, new_tags[i]); + } + + notmuch_message_thaw (message); + notmuch_message_tags_to_maildir_flags (message); notmuch_message_destroy (message); @@ -182,7 +192,7 @@ save_database (notmuch_database_t *notmuch, const char *path) static notmuch_bool_t insert_message (void *ctx, notmuch_database_t *notmuch, int fdin, - const char *dir) + const char *dir, const char **new_tags) { char *tmppath; char *newpath; @@ -207,7 +217,7 @@ insert_message (void *ctx, notmuch_database_t *notmuch, int fdin, return FALSE; } - ret = save_database (notmuch, newpath); + ret = save_database (notmuch, newpath, new_tags); if (!ret) { /* XXX maybe there should be an option to keep the file in maildir? */ @@ -223,6 +233,8 @@ notmuch_insert_command (void *ctx, int argc, char *argv[]) notmuch_config_t *config; notmuch_database_t *notmuch; const char *db_path; + const char **new_tags; + size_t new_tags_length; const char *folder = NULL; char *maildir; int opt_index; @@ -246,6 +258,7 @@ notmuch_insert_command (void *ctx, int argc, char *argv[]) return 1; db_path = notmuch_config_get_database_path (config); + new_tags = notmuch_config_get_new_tags (config, &new_tags_length); if (folder != NULL) { if (! check_folder_name (folder)) { @@ -261,7 +274,7 @@ notmuch_insert_command (void *ctx, int argc, char *argv[]) NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much)) return 1; - ret = insert_message (ctx, notmuch, STDIN_FILENO, maildir); + ret = insert_message (ctx, notmuch, STDIN_FILENO, maildir, new_tags); notmuch_database_destroy (notmuch); -- 1.7.4.4