blob: a281ef3eda78bcafcfba346803efe80991d8576d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# create and populate a bunch of mailboxes
doveadm -u "local" mailbox create "foo" "foo.bar" "baz"
for ((i = 0; i < 8; i++)); do
sample_message | deliver -u "local" -- -m "foo"
sample_message | deliver -u "local" -- -m "foo.bar"
sample_message | deliver -u "local" -- -m "INBOX"
done
interimap_init
check_mailbox_list
check_mailboxes_status "foo" "foo.bar" "baz" "INBOX"
# spoof UIDNEXT in the database
set_uidnext() {
local imap="$1" mailbox="$2" uidnext="$3"
sqlite3 "$XDG_DATA_HOME/interimap/remote.db" <<-EOF
UPDATE $imap
SET UIDNEXT = $uidnext
WHERE idx = (
SELECT idx
FROM mailboxes
WHERE mailbox = x'$mailbox'
);
EOF
}
# spoof "foo"'s UIDVALIDITY and UIDNEXT values
uidvalidity="$(doveadm -u "local" -f flow mailbox status uidvalidity "foo" | sed 's/.*=//')"
[ $uidvalidity -eq 4294967295 ] && uidvalidity2=1 || uidvalidity2=$((uidvalidity+1))
doveadm -u "local" mailbox update --uid-validity "$uidvalidity2" "foo"
set_uidnext "local" "$(printf "%s" "foo" | xxd -ps)" 1
# verify that interimap chokes on the UIDVALIDITY change without doing any changes
sqlite3 "$XDG_DATA_HOME/interimap/remote.db" >"$TMPDIR/dump.sql" <<-EOF
.dump
EOF
doveadm -u "local" mailbox status "all" "foo" >"$TMPDIR/foo.local"
doveadm -u "remote" mailbox status "all" "foo" >"$TMPDIR/foo.remote"
! interimap || error
grep -Fx "Resuming interrupted sync for foo" <"$STDERR"
grep -Fx "local(foo): ERROR: UIDVALIDITY changed! ($uidvalidity2 != $uidvalidity) Need to invalidate the UID cache for foo." <"$STDERR"
sqlite3 "$XDG_DATA_HOME/interimap/remote.db" >"$TMPDIR/dump2.sql" <<-EOF
.dump
EOF
doveadm -u "local" mailbox status "all" "foo" >"$TMPDIR/foo.local2"
doveadm -u "remote" mailbox status "all" "foo" >"$TMPDIR/foo.remote2"
diff -u --label="a/dump.sql" --label="b/dump.sql" "$TMPDIR/dump2.sql" "$TMPDIR/dump.sql"
diff -u --label="a/foo.local" --label="b/foo.remote" "$TMPDIR/foo.local" "$TMPDIR/foo.local2"
diff -u --label="a/foo.local" --label="b/foo.remote" "$TMPDIR/foo.remote" "$TMPDIR/foo.remote2"
# spoof UIDNEXT values for INBOX (local+remote) and foo.bar (remote)
set_uidnext "local" "$(printf "%s" "INBOX" | xxd -ps)" 2
set_uidnext "remote" "$(printf "%s" "INBOX" | xxd -ps)" 2
set_uidnext "remote" "$(printf "%s\\0%s" "foo" "bar" | xxd -ps)" 0
# set some flags and remove some messages for UIDs >2
doveadm -u "local" flags add "\\Seen" mailbox "INBOX" 6,7
doveadm -u "remote" flags add "\\Deleted" mailbox "INBOX" 6,8
doveadm -u "local" expunge mailbox "INBOX" 4,5
doveadm -u "remote" expunge mailbox "INBOX" 3,4
doveadm -u "remote" expunge mailbox "foo~bar" 5
# add new messages
sample_message | deliver -u "local" -- -m "foo.bar"
sample_message | deliver -u "remote" -- -m "foo~bar"
sample_message | deliver -u "local" -- -m "baz"
interimap "foo.bar" "InBoX" "baz" # ignore "foo"
grep -Fx "Resuming interrupted sync for foo.bar" <"$STDERR"
grep -Fx "Resuming interrupted sync for INBOX" <"$STDERR"
check_mailbox_list
check_mailboxes_status "foo.bar" "INBOX" "baz" # ignore "foo"
# count entries in the mapping table
sqlite3 "$XDG_DATA_HOME/interimap/remote.db" >"$TMPDIR/count" <<-EOF
SELECT COUNT(*)
FROM mapping NATURAL JOIN mailboxes
WHERE mailbox != x'$(printf "%s" "foo" | xxd -ps)'
GROUP BY idx
ORDER BY mailbox;
EOF
# count messages:
# INBOX: 8-2-1 = 5
# baz: 1
# foo.bar: 8-1+1+1 = 9
diff -u --label="a/count" --label="b/count" "$TMPDIR/count" - <<-EOF
5
1
9
EOF
# vim: set filetype=sh :
|