--- /dev/null
+Return-Path: <sojkam1@fel.cvut.cz>\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 69532431FB6\r
+ for <notmuch@notmuchmail.org>; Wed, 19 Dec 2012 13:32:57 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.3\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_MED=-2.3] 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 QQ-jiFiGDWw4 for <notmuch@notmuchmail.org>;\r
+ Wed, 19 Dec 2012 13:32:55 -0800 (PST)\r
+Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])\r
+ by olra.theworths.org (Postfix) with ESMTP id 4F2BD431FAF\r
+ for <notmuch@notmuchmail.org>; Wed, 19 Dec 2012 13:32:55 -0800 (PST)\r
+Received: from localhost (unknown [192.168.200.7])\r
+ by max.feld.cvut.cz (Postfix) with ESMTP id B014F3CFE85;\r
+ Wed, 19 Dec 2012 22:32:54 +0100 (CET)\r
+X-Virus-Scanned: IMAP STYX AMAVIS\r
+Received: from max.feld.cvut.cz ([192.168.200.1])\r
+ by localhost (styx.feld.cvut.cz [192.168.200.7]) (amavisd-new,\r
+ port 10044)\r
+ with ESMTP id idgEcp8umzzX; Wed, 19 Dec 2012 22:32:53 +0100 (CET)\r
+Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])\r
+ by max.feld.cvut.cz (Postfix) with ESMTP id 87C483CFE86;\r
+ Wed, 19 Dec 2012 22:32:52 +0100 (CET)\r
+Received: from steelpick.2x.cz (unknown [213.29.198.144])\r
+ (Authenticated sender: sojkam1)\r
+ by imap.feld.cvut.cz (Postfix) with ESMTPSA id 2FD5566096A;\r
+ Wed, 19 Dec 2012 22:32:52 +0100 (CET)\r
+Received: from wsh by steelpick.2x.cz with local (Exim 4.80)\r
+ (envelope-from <sojkam1@fel.cvut.cz>)\r
+ id 1TlRFu-00077w-SC; Wed, 19 Dec 2012 22:32:46 +0100\r
+From: Michal Sojka <sojkam1@fel.cvut.cz>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 3/3] tags_to_maildir_flags: Don't rename if no flags change\r
+Date: Wed, 19 Dec 2012 22:32:27 +0100\r
+Message-Id: <1355952747-27350-4-git-send-email-sojkam1@fel.cvut.cz>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1355952747-27350-1-git-send-email-sojkam1@fel.cvut.cz>\r
+References: <1355952747-27350-1-git-send-email-sojkam1@fel.cvut.cz>\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: Wed, 19 Dec 2012 21:32:57 -0000\r
+\r
+From: Louis Rilling <l.rilling@av7.net>\r
+\r
+notmuch_message_tags_to_maildir_flags() unconditionally moves messages from\r
+maildir directory "new/" to maildir directory "cur/", which makes messages lose\r
+their "new" status in the MUA. However some users want to keep this "new"\r
+status after, for instance, an auto-tagging of new messages.\r
+\r
+However, as Austin mentioned and according to the maildir specification,\r
+messages living in "new/" are not allowed to have flags, even if mutt allows it\r
+to happen. For this reason, this patch prevents moving messages from "new/" to\r
+"cur/", only if no flags have to be changed. It's hopefully enough to satisfy\r
+mutt (and maybe other MUAs showing the "new" status) users checking the "new"\r
+status.\r
+\r
+Changelog:\r
+* v2: Fix bool type as well as NULL returned despite having no errors (Austin\r
+ Clements)\r
+* v4: Tag the related test (contributed by Michal Sojka) as working\r
+\r
+Signed-off-by: Louis Rilling <l.rilling@av7.net>\r
+\r
+[Condition for keeping messages in new/ was extended to satisfy all\r
+ tests from the previous patch. -Michal Sojka]\r
+---\r
+ lib/message.cc | 13 ++++++++++++-\r
+ test/maildir-sync | 1 -\r
+ 2 files changed, 12 insertions(+), 2 deletions(-)\r
+\r
+diff --git a/lib/message.cc b/lib/message.cc\r
+index 320901f..87369bb 100644\r
+--- a/lib/message.cc\r
++++ b/lib/message.cc\r
+@@ -1195,7 +1195,9 @@ _get_maildir_flag_actions (notmuch_message_t *message,\r
+ * compute the new maildir filename.\r
+ *\r
+ * If the existing filename is in the directory "new", the new\r
+- * filename will be in the directory "cur".\r
++ * filename will be in the directory "cur", except for the case when\r
++ * no flags are changed and the existing filename does not contain\r
++ * maildir info (starting with ",2:").\r
+ *\r
+ * After a sequence of ":2," in the filename, any subsequent\r
+ * single-character flags will be added or removed according to the\r
+@@ -1218,6 +1220,7 @@ _new_maildir_filename (void *ctx,\r
+ char *filename_new, *dir;\r
+ char flag_map[128];\r
+ int flags_in_map = 0;\r
++ notmuch_bool_t flags_changed = FALSE;\r
+ unsigned int i;\r
+ char *s;\r
+ \r
+@@ -1258,6 +1261,7 @@ _new_maildir_filename (void *ctx,\r
+ if (flag_map[flag] == 0) {\r
+ flag_map[flag] = 1;\r
+ flags_in_map++;\r
++ flags_changed = TRUE;\r
+ }\r
+ }\r
+ \r
+@@ -1266,9 +1270,16 @@ _new_maildir_filename (void *ctx,\r
+ if (flag_map[flag]) {\r
+ flag_map[flag] = 0;\r
+ flags_in_map--;\r
++ flags_changed = TRUE;\r
+ }\r
+ }\r
+ \r
++ /* Messages in new/ without maildir info can be kept in new/ if no\r
++ * flags have changed. */\r
++ dir = (char *) _filename_is_in_maildir (filename);\r
++ if (dir && STRNCMP_LITERAL (dir, "new/") == 0 && !*info && !flags_changed)\r
++ return talloc_strdup (ctx, filename);\r
++\r
+ filename_new = (char *) talloc_size (ctx,\r
+ info - filename +\r
+ strlen (":2,") + flags_in_map + 1);\r
+diff --git a/test/maildir-sync b/test/maildir-sync\r
+index b2ac89f..33d2c58 100755\r
+--- a/test/maildir-sync\r
++++ b/test/maildir-sync\r
+@@ -84,7 +84,6 @@ test_expect_equal "$output" "No new mail."\r
+ # creating all necessary database state for those directories.\r
+ \r
+ test_begin_subtest "Adding non-maildir tags does not move message from new to cur"\r
+-test_subtest_known_broken\r
+ add_message [subject]='"Message to stay in new"' \\r
+ [date]='"Sat, 01 Jan 2000 12:00:00 -0000"' \\r
+ [filename]='message-to-stay-in-new' [dir]=new\r
+-- \r
+1.7.10.4\r
+\r