--- /dev/null
+Return-Path: <lrilling@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 1C224431FD0\r
+ for <notmuch@notmuchmail.org>; Thu, 23 Jun 2011 08:37:25 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.699\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001,\r
+ RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id 78MAjsbCvvoy for <notmuch@notmuchmail.org>;\r
+ Thu, 23 Jun 2011 08:37:23 -0700 (PDT)\r
+Received: from mail-fx0-f53.google.com (mail-fx0-f53.google.com\r
+ [209.85.161.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 4B0B5431FB6\r
+ for <notmuch@notmuchmail.org>; Thu, 23 Jun 2011 08:37:23 -0700 (PDT)\r
+Received: by fxm8 with SMTP id 8so1484027fxm.26\r
+ for <notmuch@notmuchmail.org>; Thu, 23 Jun 2011 08:37:22 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
+ h=domainkey-signature:sender:from:to:cc:subject:date:message-id\r
+ :x-mailer; bh=eMh2YnbNM6yeFEniYwoEgO4LejWIO+5cpUDBvFh4BO4=;\r
+ b=HejZiBach1msEKYeuv2yGYej4EAJKIadVNPMy29zuXejrIgL+zjf2n34Xb3ngVymhk\r
+ IeUXdP9Qp2pV8Pf1v8sF8bpy5346BUsgRpRbyrZV59az6wtouedTArqqJBJQiMzalCI3\r
+ 14AR0S6zL0UxX2R35Fg+Spw1yn3/eI1ktFERQ=\r
+DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma;\r
+ h=sender:from:to:cc:subject:date:message-id:x-mailer;\r
+ b=tT1Jhi1aFknLiU8JuYIBQzHEssBEXuLjTJ4oaI1jBGY0vrVB528tWHYkx3RJ+t3yc3\r
+ kmT7PeCyhNak9snToPqNy0m8fsZxGzeCjHMTHBcjSHp+AjSnbycwzolYe3Ug50+Wrwgf\r
+ SYOYdyaOZ1oX8T6SO7x4xbDmlRCBNs0M5WyFQ=\r
+Received: by 10.223.60.7 with SMTP id n7mr2890621fah.51.1308843441873;\r
+ Thu, 23 Jun 2011 08:37:21 -0700 (PDT)\r
+Received: from osdor.le-roi-du-couscous.fr ([78.222.14.116])\r
+ by mx.google.com with ESMTPS id w15sm1058499faj.47.2011.06.23.08.37.21\r
+ (version=SSLv3 cipher=OTHER); Thu, 23 Jun 2011 08:37:21 -0700 (PDT)\r
+Sender: Louis Rilling <lrilling@gmail.com>\r
+From: Louis Rilling <l.rilling@av7.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [RFC][PATCH] tags_to_maildir_flags: Add option to not move messages\r
+ from "new/" to "cur/"\r
+Date: Thu, 23 Jun 2011 17:36:06 +0200\r
+Message-Id: <1308843366-6159-1-git-send-email-l.rilling@av7.net>\r
+X-Mailer: git-send-email 1.7.2.5\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 23 Jun 2011 15:37:25 -0000\r
+\r
+notmuch_message_tags_to_maildir_flags() moves messages from maildir directory\r
+"new/" to maildir directory "cur/", which makes messages lose their "new" status\r
+in the MUA. However some users want to keep this "new" status after, for\r
+instance, an auto-tagging of new messages.\r
+\r
+This patch introduces notmuch_message_tags_to_maildir_flags_preserve(), which\r
+does the same job as notmuch_message_tags_to_maildir_flags() except moving\r
+from "maildir "new/" to maildir "cur/". A new option "preserve_new" is\r
+introduced in "[maildir]" section of .notmuch-config, so that users can\r
+configure whether commands "notmuch tag" and "notmuch restore" preserve the\r
+"new" status or not.\r
+\r
+Signed-off-by: Louis Rilling <l.rilling@av7.net>\r
+---\r
+Hi,\r
+\r
+I'm in the process of using notmuch, but the issue "addressed" by this patch\r
+would make me change my habits a bit too fast. I use the "new" status for\r
+quickly checking (often without reading) which emails I just received,\r
+implementing some kind of context/mood/daytime-dependent quick filtering. I'd\r
+also like to run a pre-tagging script automatically when synchronizing\r
+periodically (and automatically too) my mailboxes. But the current behavior of\r
+"notmuch tag" makes me lose my quick filtering ability.\r
+\r
+This patch is mostly written for discussion. It is certainly not polished (API,\r
+ABI, bindings) and not tested at all. In particular, I know that there are some\r
+plans to customize flags synchronization, but I don't know how the library API\r
+could/should be impacted.\r
+\r
+Thanks for your comments!\r
+\r
+Louis\r
+\r
+\r
+ lib/message.cc | 33 +++++++++++++++++++++++++--------\r
+ lib/notmuch.h | 7 +++++++\r
+ notmuch-client.h | 7 +++++++\r
+ notmuch-config.c | 35 ++++++++++++++++++++++++++++++++++-\r
+ notmuch-restore.c | 10 ++++++++--\r
+ notmuch-tag.c | 10 ++++++++--\r
+ 6 files changed, 89 insertions(+), 13 deletions(-)\r
+\r
+diff --git a/lib/message.cc b/lib/message.cc\r
+index 4b59fa9..c6c4160 100644\r
+--- a/lib/message.cc\r
++++ b/lib/message.cc\r
+@@ -1130,7 +1130,8 @@ static char*\r
+ _new_maildir_filename (void *ctx,\r
+ const char *filename,\r
+ const char *flags_to_set,\r
+- const char *flags_to_clear)\r
++ const char *flags_to_clear,\r
++ bool preserve_new)\r
+ {\r
+ const char *info, *flags;\r
+ unsigned int flag, last_flag;\r
+@@ -1211,16 +1212,19 @@ _new_maildir_filename (void *ctx,\r
+ }\r
+ *s = '\0';\r
+ \r
+- /* If message is in new/ move it under cur/. */\r
+- dir = (char *) _filename_is_in_maildir (filename_new);\r
+- if (dir && STRNCMP_LITERAL (dir, "new/") == 0)\r
+- memcpy (dir, "cur/", 4);\r
++ if (!preserve_new) {\r
++ /* If message is in new/ move it under cur/. */\r
++ dir = (char *) _filename_is_in_maildir (filename_new);\r
++ if (dir && STRNCMP_LITERAL (dir, "new/") == 0)\r
++ memcpy (dir, "cur/", 4);\r
++ }\r
+ \r
+ return filename_new;\r
+ }\r
+ \r
+-notmuch_status_t\r
+-notmuch_message_tags_to_maildir_flags (notmuch_message_t *message)\r
++static notmuch_status_t\r
++_notmuch_message_tags_to_maildir_flags (notmuch_message_t *message,\r
++ bool preserve_new)\r
+ {\r
+ notmuch_filenames_t *filenames;\r
+ const char *filename;\r
+@@ -1240,7 +1244,8 @@ notmuch_message_tags_to_maildir_flags (notmuch_message_t *message)\r
+ continue;\r
+ \r
+ filename_new = _new_maildir_filename (message, filename,\r
+- to_set, to_clear);\r
++ to_set, to_clear,\r
++ preserve_new);\r
+ if (filename_new == NULL)\r
+ continue;\r
+ \r
+@@ -1281,6 +1286,18 @@ notmuch_message_tags_to_maildir_flags (notmuch_message_t *message)\r
+ }\r
+ \r
+ notmuch_status_t\r
++notmuch_message_tags_to_maildir_flags (notmuch_message_t *message)\r
++{\r
++ _notmuch_message_tags_to_maildir_flags(message, false);\r
++}\r
++\r
++notmuch_status_t\r
++notmuch_message_tags_to_maildir_flags_preserve (notmuch_message_t *message)\r
++{\r
++ _notmuch_message_tags_to_maildir_flags(message, true);\r
++}\r
++\r
++notmuch_status_t\r
+ notmuch_message_remove_all_tags (notmuch_message_t *message)\r
+ {\r
+ notmuch_private_status_t private_status;\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index e508309..eeddc17 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -978,6 +978,13 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message);\r
+ */\r
+ notmuch_status_t\r
+ notmuch_message_tags_to_maildir_flags (notmuch_message_t *message);\r
++/* Rename message filename(s) to encode tags as maildir flags, without moving from new/ to cur/\r
++ *\r
++ * Same as notmuch_message_tags_to_maildir_flags, but messages living in\r
++ * directory "new" are not moved to neighboring directory "cur".\r
++ */\r
++notmuch_status_t\r
++notmuch_message_tags_to_maildir_flags_preserve (notmuch_message_t *message);\r
+ \r
+ /* Freeze the current state of 'message' within the database.\r
+ *\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index 63be337..2372fe6 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -235,6 +235,13 @@ notmuch_config_set_maildir_synchronize_flags (notmuch_config_t *config,\r
+ notmuch_bool_t synchronize_flags);\r
+ \r
+ notmuch_bool_t\r
++notmuch_config_get_maildir_preserve_new (notmuch_config_t *config);\r
++\r
++void\r
++notmuch_config_set_maildir_preserve_new (notmuch_config_t *config,\r
++ notmuch_bool_t preserve_new);\r
++\r
++notmuch_bool_t\r
+ debugger_is_active (void);\r
+ \r
+ #endif\r
+diff --git a/notmuch-config.c b/notmuch-config.c\r
+index 6e4c5c4..5ef5f44 100644\r
+--- a/notmuch-config.c\r
++++ b/notmuch-config.c\r
+@@ -81,7 +81,14 @@ static const char maildir_config_comment[] =\r
+ "\n"\r
+ "\tThe \"notmuch new\" command will notice flag changes in filenames\n"\r
+ "\tand update tags, while the \"notmuch tag\" and \"notmuch restore\"\n"\r
+- "\tcommands will notice tag changes and update flags in filenames\n";\r
++ "\tcommands will notice tag changes and update flags in filenames\n"\r
++ "\n"\r
++ "\tpreserve_new Valid values are true and false.\n"\r
++ "\n"\r
++ "\tThis setting has only effects if synchronize_flags is set to true.\n"\r
++ "\tIf true, the \"notmuch tag\" and \"notmuch restore\" commands will\n"\r
++ "\tpreserve the maildir \"new\" status of messages. If false, all updated\n"\r
++ "\tmessages lose their \"new\" status.\n";\r
+ \r
+ struct _notmuch_config {\r
+ char *filename;\r
+@@ -95,6 +102,7 @@ struct _notmuch_config {\r
+ const char **new_tags;\r
+ size_t new_tags_length;\r
+ notmuch_bool_t maildir_synchronize_flags;\r
++ notmuch_bool_t maildir_preserve_new;\r
+ };\r
+ \r
+ static int\r
+@@ -251,6 +259,7 @@ notmuch_config_open (void *ctx,\r
+ config->new_tags = NULL;\r
+ config->new_tags_length = 0;\r
+ config->maildir_synchronize_flags = TRUE;\r
++ config->maildir_preserve_new = FALSE;\r
+ \r
+ if (! g_key_file_load_from_file (config->key_file,\r
+ config->filename,\r
+@@ -353,6 +362,15 @@ notmuch_config_open (void *ctx,\r
+ g_error_free (error);\r
+ }\r
+ \r
++ error = NULL;\r
++ config->maildir_preserve_new =\r
++ g_key_file_get_boolean (config->key_file,\r
++ "maildir", "preserve_new", &error);\r
++ if (error) {\r
++ notmuch_config_set_maildir_preserve_new (config, FALSE);\r
++ g_error_free (error);\r
++ }\r
++\r
+ /* Whenever we know of configuration sections that don't appear in\r
+ * the configuration file, we add some comments to help the user\r
+ * understand what can be done. */\r
+@@ -764,3 +782,18 @@ notmuch_config_set_maildir_synchronize_flags (notmuch_config_t *config,\r
+ "maildir", "synchronize_flags", synchronize_flags);\r
+ config->maildir_synchronize_flags = synchronize_flags;\r
+ }\r
++\r
++notmuch_bool_t\r
++notmuch_config_get_maildir_preserve_new (notmuch_config_t *config)\r
++{\r
++ return config->maildir_preserve_new;\r
++}\r
++\r
++void\r
++notmuch_config_set_maildir_preserve_new (notmuch_config_t *config,\r
++ notmuch_bool_t preserve_new)\r
++{\r
++ g_key_file_set_boolean (config->key_file,\r
++ "maildir", "preserve_new", preserve_new);\r
++ config->maildir_preserve_new = preserve_new;\r
++}\r
+diff --git a/notmuch-restore.c b/notmuch-restore.c\r
+index f095f64..620a1f2 100644\r
+--- a/notmuch-restore.c\r
++++ b/notmuch-restore.c\r
+@@ -26,6 +26,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
+ notmuch_config_t *config;\r
+ notmuch_database_t *notmuch;\r
+ notmuch_bool_t synchronize_flags;\r
++ notmuch_bool_t preserve_new;\r
+ FILE *input;\r
+ char *line = NULL;\r
+ size_t line_size;\r
+@@ -43,6 +44,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
+ return 1;\r
+ \r
+ synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
++ preserve_new = notmuch_config_get_maildir_preserve_new (config);\r
+ \r
+ if (argc) {\r
+ input = fopen (argv[0], "r");\r
+@@ -134,8 +136,12 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
+ \r
+ notmuch_message_thaw (message);\r
+ \r
+- if (synchronize_flags)\r
+- notmuch_message_tags_to_maildir_flags (message);\r
++ if (synchronize_flags) {\r
++ if (preserve_new)\r
++ notmuch_message_tags_to_maildir_flags_preserve (message);\r
++ else\r
++ notmuch_message_tags_to_maildir_flags (message);\r
++ }\r
+ \r
+ NEXT_LINE:\r
+ if (message)\r
+diff --git a/notmuch-tag.c b/notmuch-tag.c\r
+index 6204ae3..c36c3c9 100644\r
+--- a/notmuch-tag.c\r
++++ b/notmuch-tag.c\r
+@@ -44,6 +44,7 @@ notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+ notmuch_message_t *message;\r
+ struct sigaction action;\r
+ notmuch_bool_t synchronize_flags;\r
++ notmuch_bool_t preserve_new;\r
+ int i;\r
+ \r
+ /* Setup our handler for SIGINT */\r
+@@ -101,6 +102,7 @@ notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+ return 1;\r
+ \r
+ synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
++ preserve_new = notmuch_config_get_maildir_preserve_new (config);\r
+ \r
+ query = notmuch_query_create (notmuch, query_string);\r
+ if (query == NULL) {\r
+@@ -128,8 +130,12 @@ notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+ \r
+ notmuch_message_thaw (message);\r
+ \r
+- if (synchronize_flags)\r
+- notmuch_message_tags_to_maildir_flags (message);\r
++ if (synchronize_flags) {\r
++ if (preserve_new)\r
++ notmuch_message_tags_to_maildir_flags_preserve (message);\r
++ else\r
++ notmuch_message_tags_to_maildir_flags (message);\r
++ }\r
+ \r
+ notmuch_message_destroy (message);\r
+ }\r
+-- \r
+1.7.2.5\r
+\r