aboutsummaryrefslogtreecommitdiffstats
path: root/tests/01-rename/run
blob: 6541c5c38e751eb48adfa0b0f6804c5d683a0331 (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
doveadm -u "local"  mailbox create "root.from" "root.from.child" "root.from.child2" "root.from.child.grandchild"
doveadm -u "remote" mailbox create "root^sibbling" "root^sibbling^grandchild" "root2"

for m in "root.from" "root.from.child" "root.from.child2" "root.from.child.grandchild" "INBOX"; do
    sample_message | deliver -u "local" -- -m "$m"
done
for m in "root^sibbling" "root^sibbling^grandchild" "root2" "INBOX"; do
    sample_message | deliver -u "remote" -- -m "$m"
done

interimap
check_mailboxes_status "root.from" "root.from.child" "root.from.child2" "root.from.child.grandchild" \
    "root.sibbling" "root.sibbling.grandchild" "root2" "INBOX"
sqlite3 "$XDG_DATA_HOME/interimap/remote.db" >"$TMPDIR/mailboxes.csv" <<-EOF
	.mode csv
	SELECT idx, hex(mailbox)
	  FROM mailboxes
	 ORDER BY idx
EOF

# renaming a non-existent mailbox doesn't yield an error
interimap --rename "nonexistent" "nonexistent2"
check_mailbox_list

# renaming to an existing name yields an error
! interimap --rename "root2" "root"
xgrep -E "^local: ERROR: Couldn't rename mailbox root2: NO \[ALREADYEXISTS\] .*" <"$STDERR"

# rename 'root.from' to 'from.root', including inferiors
interimap --rename "root.from" "from.root"
xgrep -Fx 'local: Renamed mailbox root.from to from.root' <"$STDERR"
xgrep -Fx 'remote: Renamed mailbox root^from to from^root' <"$STDERR"
xgrep -Fx 'database: Renamed mailbox root.from to from.root' <"$STDERR"

check_mailbox_list
check_mailboxes_status "from.root" "from.root.child" "from.root.child2" "from.root.child.grandchild" \
    "root.sibbling" "root.sibbling.grandchild" "root2" "INBOX"

before="$(printf "%s\\0%s" "root" "from" | xxd -u -ps)"
after="$(printf "%s\\0%s" "from" "root" | xxd -ps)"
sqlite3 "$XDG_DATA_HOME/interimap/remote.db" >"$TMPDIR/mailboxes2.csv" <<-EOF
	.mode csv
    SELECT idx,
           CASE
             WHEN mailbox = x'$after' OR hex(mailbox) LIKE '${after}00%'
               THEN '$before' || SUBSTR(hex(mailbox), $((${#after}+1)))
             ELSE hex(mailbox)
           END
	  FROM mailboxes
	 ORDER BY idx
EOF
diff -u --label="a/mailboxes.csv" --label="b/mailboxes.csv" \
    "$TMPDIR/mailboxes.csv" "$TMPDIR/mailboxes2.csv"


# Try to rename \NonExistent root and check that its children move
interimap --rename "root" "newroot"
xgrep -Fq 'local: Renamed mailbox root to newroot' <"$STDERR"
xgrep -Fq 'remote: Renamed mailbox root to newroot' <"$STDERR"
xgrep -Fq 'database: Renamed mailbox root to newroot' <"$STDERR"

check_mailbox_list
check_mailboxes_status "from.root" "from.root.child" "from.root.child2" "from.root.child.grandchild" \
    "newroot.sibbling" "newroot.sibbling.grandchild" "root2" "INBOX"

before2="$(printf "%s" "root" | xxd -u -ps)"
after2="$(printf "%s" "newroot" | xxd -ps)"
sqlite3 "$XDG_DATA_HOME/interimap/remote.db" >"$TMPDIR/mailboxes3.csv" <<-EOF
	.mode csv
    SELECT idx,
           CASE
             WHEN mailbox = x'$after' OR hex(mailbox) LIKE '${after}00%'
               THEN '$before' || SUBSTR(hex(mailbox), $((${#after}+1)))
             WHEN hex(mailbox) LIKE '${after2}00%'
               THEN '$before2' || SUBSTR(hex(mailbox), $((${#after2}+1)))
             ELSE hex(mailbox)
           END
	  FROM mailboxes
	 ORDER BY idx
EOF
diff -u --label="a/mailboxes.csv" --label="b/mailboxes.csv" \
    "$TMPDIR/mailboxes2.csv" "$TMPDIR/mailboxes3.csv"

# vim: set filetype=sh :