Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 275DA6DE19A0 for ; Wed, 25 Nov 2015 18:17:16 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.705 X-Spam-Level: X-Spam-Status: No, score=-0.705 tagged_above=-999 required=5 tests=[AWL=0.096, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yaO4D-L94-rr for ; Wed, 25 Nov 2015 18:17:14 -0800 (PST) Received: from mail-qg0-f46.google.com (mail-qg0-f46.google.com [209.85.192.46]) by arlo.cworth.org (Postfix) with ESMTPS id CE9316DE1989 for ; Wed, 25 Nov 2015 18:16:55 -0800 (PST) Received: by qgcc31 with SMTP id c31so45657815qgc.3 for ; Wed, 25 Nov 2015 18:16:54 -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:in-reply-to:references; bh=2ZT7nQ5OyGT646RI+kkwMsxiIBYqBcNG34q48V+odqY=; b=pquWHaOBIyvrPo6qK3Vc/B1xgaoyqQ2mSu3obJhPEJQ+0QbvHDwPnEwbNAgvnwIczD Dbi6qXihmIOL3775xsNbc/k03MowV+E1JwbpxE3rkos79bNJv3RaoT5rpqNgoLLZ9DPf VvXNI9tHzry/W7smSFW2N+zUl96ZWapIaALROtXfhNHX+bWBGK/3kx7f/vYUOyT9pINM evHt+RgSQRQ08/q5rsozGtoSWVpDF6VsJY+t6IrkGXpNIXt7Y+/i+Y/r7q6+bHQ/dwGq KGeo/kEfDoprxGze6T0DZVIv5IwR/Y9iqoc3P3nCVttVAORUOxptvD2PUrW8PoGKl5Bq RGZA== X-Received: by 10.140.31.161 with SMTP id f30mr42861846qgf.95.1448504214817; Wed, 25 Nov 2015 18:16:54 -0800 (PST) Received: from arch-laptop.localdomain ([200.195.16.216]) by smtp.gmail.com with ESMTPSA id h206sm1566011qhc.43.2015.11.25.18.16.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Nov 2015 18:16:53 -0800 (PST) From: Igor Almeida To: notmuch@notmuchmail.org Subject: [PATCH/RFC 3/3] notmuch new: sync maildir custom flag user configuration Date: Wed, 25 Nov 2015 23:16:31 -0300 Message-Id: <1448504191-30974-4-git-send-email-igor.contato@gmail.com> X-Mailer: git-send-email 2.5.3 In-Reply-To: <1448504191-30974-1-git-send-email-igor.contato@gmail.com> References: <1448504191-30974-1-git-send-email-igor.contato@gmail.com> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.20 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: Thu, 26 Nov 2015 02:17:16 -0000 This allows the user to specify in the config file how maildir custom flags translate to notmuch tags (this mapping is stored in the db metadata). Command 'notmuch new' will pick up changes in the config and update the database metadata, but will not retag the messages. Example config: [maildir] synchronize_flags=true customflag_j = todo customflag_e = important Signed-off-by: Igor Almeida --- notmuch-client.h | 4 ++++ notmuch-config.c | 24 +++++++++++++++++++++++- notmuch-new.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 1 deletion(-) diff --git a/notmuch-client.h b/notmuch-client.h index 3bd2903..9f5bb8f 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -324,6 +324,10 @@ void notmuch_config_set_maildir_synchronize_flags (notmuch_config_t *config, notmuch_bool_t synchronize_flags); +const char * +notmuch_config_get_maildir_customflag_map (notmuch_config_t *config, + const char maildir_custom_flag); + const char ** notmuch_config_get_search_exclude_tags (notmuch_config_t *config, size_t *length); diff --git a/notmuch-config.c b/notmuch-config.c index d252bb2..f2a25b1 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -72,7 +72,7 @@ static const char user_config_comment[] = static const char maildir_config_comment[] = " Maildir compatibility configuration\n" "\n" - " The following option is supported here:\n" + " The following options are supported here:\n" "\n" "\tsynchronize_flags Valid values are true and false.\n" "\n" @@ -87,6 +87,11 @@ static const char maildir_config_comment[] = "\t\tR replied\n" "\t\tS unread (added when 'S' flag is not present)\n" "\n" + "\tIf true, then the following option is also considered, and messages\n" + "\twill be tagged based on the lower-case letters in the maildir flags:\n" + "\n" + "\tcustomflag_[a-z] Valid values are tag names.\n" + "\n" "\tThe \"notmuch new\" command will notice flag changes in filenames\n" "\tand update tags, while the \"notmuch tag\" and \"notmuch restore\"\n" "\tcommands will notice tag changes and update flags in filenames\n"; @@ -127,6 +132,8 @@ struct _notmuch_config { notmuch_bool_t maildir_synchronize_flags; const char **search_exclude_tags; size_t search_exclude_tags_length; + + char *customflag_map[26 /* 'a' to 'z' */]; }; static int @@ -931,3 +938,18 @@ notmuch_config_set_maildir_synchronize_flags (notmuch_config_t *config, "maildir", "synchronize_flags", synchronize_flags); config->maildir_synchronize_flags = synchronize_flags; } + +const char * +notmuch_config_get_maildir_customflag_map (notmuch_config_t *config, + const char maildir_customflag) +{ + char key[] = "customflag_a"; + key[sizeof(key) - 2] = maildir_customflag; + + int index = maildir_customflag - 'a'; + + return _config_get ( + config, + &config->customflag_map[index], + "maildir", key); +} diff --git a/notmuch-new.c b/notmuch-new.c index d45d0af..d4bb6c7 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -923,6 +923,50 @@ print_results (const add_files_state_t *state) printf ("\n"); } +static void +_sync_config_and_database_customflag_mapping (notmuch_config_t *config, + notmuch_database_t *notmuch) +{ + char c; + const char *config_customflag; + const char *db_customflag; + + notmuch_status_t status; + int index; + + /* Compare the config mapping and the db mapping, warn the user and + * overwrite the db if they differ + */ + for (c = 'a'; c <= 'z'; c++) { + index = c - 'a'; + config_customflag = notmuch_config_get_maildir_customflag_map (config, c); + + if (config_customflag != NULL) { + status = notmuch_database_get_maildir_keyword ( + notmuch, index, &db_customflag); + if (status) { + /* TODO what now? break and let 'notmuch new' fail later? */ + } else { + if (db_customflag != NULL && + strcmp(config_customflag, db_customflag)) { + printf ("Your configuration for maildir custom flags has " + "changed.\n" + "I will overwrite the mapping in the db metadata, " + "but you will have to retag the messages " + "yourself, with something like this:\n" + "\tnotmuch tag +%s tag:%s\n" + "\tnotmuch tag -%s tag:%s\n", + config_customflag, db_customflag, + db_customflag, config_customflag); + } + + notmuch_database_set_maildir_keyword ( + notmuch, index, config_customflag); + } + } + } +} + int notmuch_new_command (notmuch_config_t *config, int argc, char *argv[]) { @@ -1068,6 +1112,11 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[]) if (notmuch == NULL) return EXIT_FAILURE; + /* Make sure our database's maildir customflag mapping matches the config, + * warn the user if not + */ + _sync_config_and_database_customflag_mapping (config, notmuch); + /* Set up our handler for SIGINT. We do this after having * potentially done a database upgrade we this interrupt handler * won't support. */ -- 2.5.3