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