]> git.notmuchmail.org Git - notmuch/blob - test/maildir-sync
tags_to_maildir_flags: Fix to preserve existing, unsupported flags
[notmuch] / test / maildir-sync
1 #!/bin/bash
2
3 test_description="maildir synchronization"
4
5 . ./test-lib.sh
6
7 # Much easier to examine differences if the "notmuch show
8 # --format=json" output includes some newlines. Also, need to avoid
9 # including the local value of MAIL_DIR in the result.
10 filter_show_json() {
11     sed -e 's/, /,\n/g'  | sed -e "s|${MAIL_DIR}/|MAIL_DIR/|"
12     echo
13 }
14
15 # Create the expected maildir structure
16 mkdir $MAIL_DIR/cur
17 mkdir $MAIL_DIR/new
18 mkdir $MAIL_DIR/tmp
19
20 test_begin_subtest "Adding 'S' flag to existing filename removes 'unread' tag"
21 add_message [subject]='"Adding S flag"' [filename]='adding-s-flag:2,' [dir]=cur
22 output=$(notmuch search subject:"Adding S flag" | notmuch_search_sanitize)
23 output+="
24 "
25 mv "${gen_msg_filename}" "${gen_msg_filename}S"
26 increment_mtime "$(dirname "${gen_msg_filename}")"
27 output+=$(NOTMUCH_NEW)
28 output+="
29 "
30 output+=$(notmuch search subject:"Adding S flag" | notmuch_search_sanitize)
31 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Adding S flag (inbox unread)
32 No new mail. Detected 1 file rename.
33 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Adding S flag (inbox)"
34
35 test_begin_subtest "Adding message with 'S' flag prevents 'unread' tag"
36 add_message [subject]='"Adding message with S"' [filename]='adding-with-s-flag:2,S' [dir]=cur
37 output=$(notmuch search subject:"Adding message with S" | notmuch_search_sanitize)
38 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Adding message with S (inbox)"
39
40 test_begin_subtest "Adding 'replied' tag adds 'R' flag to filename"
41 add_message [subject]='"Adding replied tag"' [filename]='adding-replied-tag:2,S' [dir]=cur
42 notmuch tag +replied subject:"Adding replied tag"
43 output=$(cd ${MAIL_DIR}/cur; ls -1 adding-replied*)
44 test_expect_equal "$output" "adding-replied-tag:2,RS"
45
46 test_begin_subtest "notmuch show works with renamed file (without notmuch new)"
47 output=$(notmuch show --format=json id:${gen_msg_id} | filter_show_json)
48 test_expect_equal "$output" '[[[{"id": "adding-replied-tag@notmuch-test-suite",
49 "match": true,
50 "filename": "MAIL_DIR/cur/adding-replied-tag:2,RS",
51 "timestamp": 978709437,
52 "date_relative": "2001-01-05",
53 "tags": ["inbox","replied"],
54 "headers": {"Subject": "Adding replied tag",
55 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
56 "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
57 "Cc": "",
58 "Bcc": "",
59 "Date": "Tue,
60 05 Jan 2001 15:43:57 -0000"},
61 "body": [{"id": 1,
62 "content-type": "text/plain",
63 "content": "This is just a test message (#3)\n"}]},
64 []]]]'
65
66 test_expect_success 'notmuch reply works with renamed file (without notmuch new)' 'notmuch reply id:${gen_msg_id}'
67
68 test_begin_subtest "notmuch new detects no file rename after tag->flag synchronization"
69 increment_mtime "$(dirname ${gen_msg_filename})"
70 output=$(NOTMUCH_NEW)
71 test_expect_equal "$output" "No new mail."
72
73 test_begin_subtest "When read, message moved from new to cur"
74 add_message [subject]='"Message to move to cur"' [date]='"Sat, 01 Jan 2000 12:00:00 -0000"' [filename]='message-to-move-to-cur' [dir]=new
75 notmuch tag -unread subject:"Message to move to cur"
76 output=$(cd "$MAIL_DIR/cur"; ls message-to-move*)
77 test_expect_equal "$output" "message-to-move-to-cur:2,S"
78
79 test_begin_subtest "No rename should be detected by notmuch new"
80 increment_mtime "$MAIL_DIR/cur"
81 output=$(NOTMUCH_NEW)
82 test_expect_equal "$output" "No new mail."
83 # (*) If notmuch new was not run we've got "Processed 1 file in almost
84 # no time" here. The reason is that removing unread tag in a previous
85 # test created directory document in the database but this document
86 # was not linked as subdirectory of $MAIL_DIR. Therefore notmuch new
87 # could not reach the cur/ directory and its files in it during
88 # recurive traversal.
89 #
90 # XXX: The above sounds like a bug that should be fixed. If notmuch is
91 # creating new directories in the mail store, then it should be
92 # creating all necessary database state for those directories.
93
94 test_begin_subtest "Removing 'S' flag from existing filename adds 'unread' tag"
95 add_message [subject]='"Removing S flag"' [filename]='removing-s-flag:2,S' [dir]=cur
96 output=$(notmuch search subject:"Removing S flag" | notmuch_search_sanitize)
97 output+="
98 "
99 mv "${gen_msg_filename}" "${gen_msg_filename%S}"
100 increment_mtime "$(dirname "${gen_msg_filename}")"
101 output+=$(NOTMUCH_NEW)
102 output+="
103 "
104 output+=$(notmuch search subject:"Removing S flag" | notmuch_search_sanitize)
105 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Removing S flag (inbox)
106 No new mail. Detected 1 file rename.
107 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Removing S flag (inbox unread)"
108
109 test_begin_subtest "Removing info from filename leaves tags unchanged"
110 add_message [subject]='"Message to lose maildir info"' [filename]='message-to-lose-maildir-info' [dir]=cur
111 notmuch tag -unread subject:"Message to lose maildir info"
112 mv "$MAIL_DIR/cur/message-to-lose-maildir-info:2,S" "$MAIL_DIR/cur/message-without-maildir-info"
113 increment_mtime "$MAIL_DIR/cur"
114 output=$(NOTMUCH_NEW)
115 output+="
116 "
117 output+=$(notmuch search subject:"Message to lose maildir info" | notmuch_search_sanitize)
118 test_expect_equal "$output" "No new mail. Detected 1 file rename.
119 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Message to lose maildir info (inbox)"
120
121 add_message [subject]='"Non-maildir message"' [dir]=notmaildir [filename]='non-maildir-message'
122 expected=$(notmuch search --output=files subject:"Non-maildir message")
123 test_expect_success "Can remove unread tag from message in non-maildir directory" 'notmuch tag -unread subject:"Non-maildir message"'
124
125 test_begin_subtest "Message in non-maildir directory does not get renamed"
126 output=$(notmuch search --output=files subject:"Non-maildir message")
127 test_expect_equal "$output" "$expected"
128
129 test_begin_subtest "notmuch dump/restore re-synchronizes maildir tags with flags"
130 # Capture current filename state
131 expected=$(ls $MAIL_DIR/cur)
132 # Add/remove some flags from filenames
133 mv $MAIL_DIR/cur/adding-replied-tag:2,RS $MAIL_DIR/cur/adding-replied-tag:2,S
134 mv $MAIL_DIR/cur/adding-s-flag:2,S $MAIL_DIR/cur/adding-s-flag:2,
135 mv $MAIL_DIR/cur/adding-with-s-flag:2,S $MAIL_DIR/cur/adding-with-s-flag:2,RS
136 mv $MAIL_DIR/cur/message-to-move-to-cur:2,S $MAIL_DIR/cur/message-to-move-to-cur:2,DS
137 increment_mtime $MAIL_DIR/cur
138 notmuch dump dump.txt
139 NOTMUCH_NEW >/dev/null
140 notmuch restore dump.txt
141 output=$(ls $MAIL_DIR/cur)
142 test_expect_equal "$output" "$expected"
143
144 test_begin_subtest 'Adding flags to duplicate message tags the mail'
145 add_message [subject]='"Duplicated message"' [dir]=cur [filename]='duplicated-message:2,'
146 cp "$MAIL_DIR/cur/duplicated-message:2," "$MAIL_DIR/cur/duplicated-message-copy:2,RS"
147 increment_mtime $MAIL_DIR/cur
148 NOTMUCH_NEW > output
149 notmuch search subject:"Duplicated message" | notmuch_search_sanitize >> output
150 test_expect_equal "$(< output)" "No new mail.
151 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Duplicated message (inbox replied)"
152
153 test_begin_subtest "Adding duplicate message without flags does not remove tags"
154 cp "$MAIL_DIR/cur/duplicated-message-copy:2,RS" "$MAIL_DIR/cur/duplicated-message-another-copy:2,"
155 increment_mtime $MAIL_DIR/cur
156 NOTMUCH_NEW > output
157 notmuch search subject:"Duplicated message" | notmuch_search_sanitize >> output
158 test_expect_equal "$(< output)" "No new mail.
159 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Duplicated message (inbox replied)"
160
161 test_begin_subtest "Tag changes modify flags of multiple files"
162 notmuch tag -replied subject:"Duplicated message"
163 (cd $MAIL_DIR/cur/; ls duplicated*) > actual
164 test_expect_equal "$(< actual)"  "duplicated-message-another-copy:2,S
165 duplicated-message-copy:2,S
166 duplicated-message:2,S"
167
168 test_begin_subtest "Synchronizing tag changes preserves unsupported maildir flags"
169 add_message [subject]='"Unsupported maildir flags"' [dir]=cur [filename]='unsupported-maildir-flags:2,FSZxyz'
170 notmuch tag +unread +draft -flagged subject:"Unsupported maildir flags"
171 test_expect_equal "$(cd $MAIL_DIR/cur/; ls unsupported*)" "unsupported-maildir-flags:2,DZxyz"
172
173 test_begin_subtest "A file with non-compliant maildir info will not be renamed"
174 add_message [subject]='"Non-compliant maildir info"' [dir]=cur [filename]='non-compliant-maildir-info:2,These-are-not-flags-in-ASCII-order-donottouch'
175 notmuch tag +unread +draft -flagged subject:"Non-compliant maildir info"
176 test_expect_equal "$(cd $MAIL_DIR/cur/; ls non-compliant*)" "non-compliant-maildir-info:2,These-are-not-flags-in-ASCII-order-donottouch"
177
178 test_done