unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Michal Sojka <sojkam1@fel.cvut.cz>
To: notmuch@notmuchmail.org
Subject: [PATCH 3/3] tags_to_maildir_flags: Don't rename if no flags change
Date: Wed, 19 Dec 2012 22:32:27 +0100	[thread overview]
Message-ID: <1355952747-27350-4-git-send-email-sojkam1@fel.cvut.cz> (raw)
In-Reply-To: <1355952747-27350-1-git-send-email-sojkam1@fel.cvut.cz>

From: Louis Rilling <l.rilling@av7.net>

notmuch_message_tags_to_maildir_flags() unconditionally moves messages from
maildir directory "new/" to maildir directory "cur/", which makes messages lose
their "new" status in the MUA. However some users want to keep this "new"
status after, for instance, an auto-tagging of new messages.

However, as Austin mentioned and according to the maildir specification,
messages living in "new/" are not allowed to have flags, even if mutt allows it
to happen. For this reason, this patch prevents moving messages from "new/" to
"cur/", only if no flags have to be changed. It's hopefully enough to satisfy
mutt (and maybe other MUAs showing the "new" status) users checking the "new"
status.

Changelog:
* v2: Fix bool type as well as NULL returned despite having no errors (Austin
      Clements)
* v4: Tag the related test (contributed by Michal Sojka) as working

Signed-off-by: Louis Rilling <l.rilling@av7.net>

[Condition for keeping messages in new/ was extended to satisfy all
 tests from the previous patch. -Michal Sojka]
---
 lib/message.cc    |   13 ++++++++++++-
 test/maildir-sync |    1 -
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/lib/message.cc b/lib/message.cc
index 320901f..87369bb 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -1195,7 +1195,9 @@ _get_maildir_flag_actions (notmuch_message_t *message,
  * compute the new maildir filename.
  *
  * If the existing filename is in the directory "new", the new
- * filename will be in the directory "cur".
+ * filename will be in the directory "cur", except for the case when
+ * no flags are changed and the existing filename does not contain
+ * maildir info (starting with ",2:").
  *
  * After a sequence of ":2," in the filename, any subsequent
  * single-character flags will be added or removed according to the
@@ -1218,6 +1220,7 @@ _new_maildir_filename (void *ctx,
     char *filename_new, *dir;
     char flag_map[128];
     int flags_in_map = 0;
+    notmuch_bool_t flags_changed = FALSE;
     unsigned int i;
     char *s;
 
@@ -1258,6 +1261,7 @@ _new_maildir_filename (void *ctx,
 	if (flag_map[flag] == 0) {
 	    flag_map[flag] = 1;
 	    flags_in_map++;
+	    flags_changed = TRUE;
 	}
     }
 
@@ -1266,9 +1270,16 @@ _new_maildir_filename (void *ctx,
 	if (flag_map[flag]) {
 	    flag_map[flag] = 0;
 	    flags_in_map--;
+	    flags_changed = TRUE;
 	}
     }
 
+    /* Messages in new/ without maildir info can be kept in new/ if no
+     * flags have changed. */
+    dir = (char *) _filename_is_in_maildir (filename);
+    if (dir && STRNCMP_LITERAL (dir, "new/") == 0 && !*info && !flags_changed)
+	return talloc_strdup (ctx, filename);
+
     filename_new = (char *) talloc_size (ctx,
 					 info - filename +
 					 strlen (":2,") + flags_in_map + 1);
diff --git a/test/maildir-sync b/test/maildir-sync
index b2ac89f..33d2c58 100755
--- a/test/maildir-sync
+++ b/test/maildir-sync
@@ -84,7 +84,6 @@ test_expect_equal "$output" "No new mail."
 # creating all necessary database state for those directories.
 
 test_begin_subtest "Adding non-maildir tags does not move message from new to cur"
-test_subtest_known_broken
 add_message [subject]='"Message to stay in new"' \
     [date]='"Sat, 01 Jan 2000 12:00:00 -0000"' \
     [filename]='message-to-stay-in-new' [dir]=new
-- 
1.7.10.4

  parent reply	other threads:[~2012-12-19 21:32 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-19 21:32 [PATCH 0/3] Adding non-maildir tags does not move message from new to cur Michal Sojka
2012-12-19 21:32 ` [PATCH 1/3] test: " Michal Sojka
2013-09-03 23:56   ` David Bremner
2012-12-19 21:32 ` [PATCH 2/3] test: Add some missing maildir synchronization tests Michal Sojka
2012-12-19 21:32 ` Michal Sojka [this message]
2013-09-03  1:10   ` [PATCH] test: update insert tests for new maildir synchronization rules david
2013-09-03  5:19     ` [PATCH 1/2] test: add more maildir flag syncing related tests to insert Jani Nikula
2013-09-03  5:19       ` [PATCH 2/2] test: improve insert test reliability by checking message-id instead of count Jani Nikula
2013-09-03  9:26       ` [PATCH 1/2] test: add more maildir flag syncing related tests to insert David Bremner
2013-09-03 12:11         ` Jani Nikula
2013-09-03  5:22     ` [PATCH] test: update insert tests for new maildir synchronization rules Jani Nikula
2013-09-02 17:56 ` [PATCH 0/3] Adding non-maildir tags does not move message from new to cur Jani Nikula
  -- strict thread matches above, loose matches on Subject: below --
2011-07-12 13:59 [PATCH 0/3 v3] lib: Maildir flags synchronization fixes Louis Rilling
2011-07-12 13:59 ` [PATCH 3/3] tags_to_maildir_flags: Don't rename if no flags change Louis Rilling

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1355952747-27350-4-git-send-email-sojkam1@fel.cvut.cz \
    --to=sojkam1@fel.cvut.cz \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).