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