From: Léo Gaspard <notmuchmail.org@leo.gaspard.io> When two maildir flags have different flags, currently the behavior is to take the union of the all the flags. For unread, this means that if an email has duplicate files, that it is read, and that then on eg. a mobile device one of the files is marked as unread (but not the other), then notmuch won't catch this and keep the message as read. This patch makes notmuch consider that when a message has both a file marked read and a file marked unread from maildir, then it will be treated as unread for notmuch. --- lib/message.cc | 18 +++++++++++++++++- test/T340-maildir-sync.sh | 29 +++++++++++++++++++---------- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/lib/message.cc b/lib/message.cc index 6f2f6345..90bbb32a 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -1,6 +1,7 @@ /* message.cc - Results of message-based searches from a notmuch database * * Copyright © 2009 Carl Worth + * Copyright © 2018 Leo Gaspard * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,7 +16,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see https://www.gnu.org/licenses/ . * - * Author: Carl Worth <cworth@cworth.org> + * Authors: Carl Worth <cworth@cworth.org> + * Leo Gaspard <leo@gaspard.io> */ #include "notmuch-private.h" @@ -1682,6 +1684,7 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message) { notmuch_status_t status; unsigned i; + int num_read_flags; _ensure_maildir_flags (message, true); /* If none of the filenames have any maildir info field (not even @@ -1695,6 +1698,8 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message) return status; for (i = 0; i < ARRAY_SIZE(flag2tag); i++) { + if (flag2tag[i].flag == 'S') + continue; if ((strchr (message->maildir_flags, flag2tag[i].flag) != NULL) ^ flag2tag[i].inverse) @@ -1706,6 +1711,17 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message) if (status) return status; } + num_read_flags = 0; + for (i = 0; message->maildir_flags[i] != '\0'; ++i) + if (message->maildir_flags[i] == 'S') + ++num_read_flags; + if (notmuch_message_count_files (message) == num_read_flags) + status = notmuch_message_remove_tag (message, "unread"); + else + status = notmuch_message_add_tag (message, "unread"); + if (status) + return status; + status = notmuch_message_thaw (message); return status; diff --git a/test/T340-maildir-sync.sh b/test/T340-maildir-sync.sh index 7fece5f2..88acab3b 100755 --- a/test/T340-maildir-sync.sh +++ b/test/T340-maildir-sync.sh @@ -121,16 +121,16 @@ test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; R No new mail. Detected 1 file rename. thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Removing S flag (inbox unread)" -test_begin_subtest "Removing info from filename leaves tags unchanged" +test_begin_subtest "Removing info from filename leaves tags unchanged (but re-adds unread)" add_message [subject]='"Message to lose maildir info"' [filename]='message-to-lose-maildir-info' [dir]=cur -notmuch tag -unread subject:"Message to lose maildir info" -mv "$MAIL_DIR/cur/message-to-lose-maildir-info:2,S" "$MAIL_DIR/cur/message-without-maildir-info" +notmuch tag -unread +replied subject:"Message to lose maildir info" +mv "$MAIL_DIR/cur/message-to-lose-maildir-info:2,RS" "$MAIL_DIR/cur/message-without-maildir-info" output=$(NOTMUCH_NEW) output+=" " output+=$(notmuch search subject:"Message to lose maildir info" | notmuch_search_sanitize) test_expect_equal "$output" "No new mail. Detected 1 file rename. -thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Message to lose maildir info (inbox)" +thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Message to lose maildir info (inbox replied unread)" test_begin_subtest "Can remove unread tag from message in non-maildir directory" add_message [subject]='"Non-maildir message"' [dir]=notmaildir [filename]='non-maildir-message' @@ -155,27 +155,36 @@ notmuch restore --input=dump.txt output=$(ls $MAIL_DIR/cur) test_expect_equal "$output" "$expected" -test_begin_subtest 'Adding flags to duplicate message tags the mail' +test_begin_subtest 'Adding flags to duplicate message tags the mail (except for unread)' add_message [subject]='"Duplicated message"' [dir]=cur [filename]='duplicated-message:2,' cp "$MAIL_DIR/cur/duplicated-message:2," "$MAIL_DIR/cur/duplicated-message-copy:2,RS" NOTMUCH_NEW > output notmuch search subject:"Duplicated message" | notmuch_search_sanitize >> output test_expect_equal "$(< output)" "No new mail. +thread:XXX 2001-01-05 [1/1(2)] Notmuch Test Suite; Duplicated message (inbox replied unread)" + +test_begin_subtest 'Adding flags to all duplicate messages tags the mail' +add_message [subject]='"Duplicated message"' [dir]=cur [filename]='duplicated-message:2,' +cp "$MAIL_DIR/cur/duplicated-message:2," "$MAIL_DIR/cur/duplicated-message-copy:2,RS" +mv "$MAIL_DIR/cur/duplicated-message:2," "$MAIL_DIR/cur/duplicated-message:2,S" +NOTMUCH_NEW > output +notmuch search subject:"Duplicated message" | notmuch_search_sanitize >> output +test_expect_equal "$(< output)" "No new mail. Detected 1 file rename. thread:XXX 2001-01-05 [1/1(2)] Notmuch Test Suite; Duplicated message (inbox replied)" -test_begin_subtest "Adding duplicate message without flags does not remove tags" +test_begin_subtest "Adding duplicate message without flags does not remove tags (but adds unread)" cp "$MAIL_DIR/cur/duplicated-message-copy:2,RS" "$MAIL_DIR/cur/duplicated-message-another-copy:2," NOTMUCH_NEW > output notmuch search subject:"Duplicated message" | notmuch_search_sanitize >> output test_expect_equal "$(< output)" "No new mail. -thread:XXX 2001-01-05 [1/1(3)] Notmuch Test Suite; Duplicated message (inbox replied)" +thread:XXX 2001-01-05 [1/1(3)] Notmuch Test Suite; Duplicated message (inbox replied unread)" test_begin_subtest "Tag changes modify flags of multiple files" notmuch tag -replied subject:"Duplicated message" (cd $MAIL_DIR/cur/; ls duplicated*) > actual -test_expect_equal "$(< actual)" "duplicated-message-another-copy:2,S -duplicated-message-copy:2,S -duplicated-message:2,S" +test_expect_equal "$(< actual)" "duplicated-message-another-copy:2, +duplicated-message-copy:2, +duplicated-message:2," test_begin_subtest "Synchronizing tag changes preserves unsupported maildir flags" add_message [subject]='"Unsupported maildir flags"' [dir]=cur [filename]='unsupported-maildir-flags:2,FSZxyz' -- 2.18.1 _______________________________________________ notmuch mailing list notmuch@notmuchmail.org https://notmuchmail.org/mailman/listinfo/notmuch