aboutsummaryrefslogtreecommitdiffstats
path: root/tests/list-mailbox/t
blob: a1168a64ca621e6d2b5c4ed0572dd7787465c0d9 (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
# create and populate some mailboxes locally
declare -a MAILBOXES=( "foo" "foo bar" "f\\\"o!o.bar" "f.o.o" )
doveadm -u "local" mailbox create -- "${MAILBOXES[@]}" "foobad" "baz" "INBOX"
for ((i = 0; i < 32; i++)); do
    m="$(shuf -n1 -e -- "${MAILBOXES[@]}" "foobad" "baz" "INBOX")"
    sample_message | deliver -u "local" -- -m "$m"
done

interimap_init
for m in "${MAILBOXES[@]}"; do
    grep -Fx "remote: Created mailbox ${m//./?}" <"$STDERR" || error "${m//./?}"
    grep -Fx "database: Created mailbox $m" <"$STDERR" || error
done

# also check inferiors in the list, but exclude "foobad" and "baz"
check_mailbox_list     "${MAILBOXES[@]}" "INBOX" "f\\\"o!o" "f" "f.o"
check_mailboxes_status "${MAILBOXES[@]}" || error

# double check that "foobad" and "baz" weren't created
! doveadm -u "remote" mailbox status uidvalidity "foobad" || error
! doveadm -u "remote" mailbox status uidvalidity "baz"    || error

# check that "foobad" and "INBOX" aren't in the database
sqlite3 "$XDG_DATA_HOME/interimap/remote.db" >"$TMPDIR/count" <<-EOF
    SELECT COUNT(*)
	  FROM mailboxes
	 WHERE mailbox = x'$(printf "%s" "foobad" | xxd -u -ps)'
	    OR mailbox = x'$(printf "%s" "INBOX"  | xxd -u -ps)'
	    OR mailbox = x'$(printf "%s" "baz"    | xxd -u -ps)'
EOF
[ $(< "$TMPDIR/count") -eq 0 ] || error


# mailbox given on the command line overrides list-mailbox
sample_message | deliver -u "local" -- -m "foobad"
sample_message | deliver -u "local" -- -m "foo"
interimap "foobad" || error
! grep -F "remote(foo): Added 1 UID(s)" <"$STDERR" || error
check_mailbox_list "foobad"
check_mailbox_status "foobad"

interimap "foo" || error
grep -F "remote(foo): Added 1 UID(s)" <"$STDERR" || error
check_mailbox_status "foo"
! check_mailbox_list "baz"


# finally, try a bunch of invalid 'list-mailbox' values to test the parser:
# empty string, missing space between values, unterminated string
for v in '""' '"f o o""bar"' '"f o o" "bar" "baz\" x'; do
    sed -ri "s/^(list-mailbox\\s*=\\s*).*/\\1${v//\\/\\\\}/" \
            "$XDG_CONFIG_HOME/interimap/config"
    ! interimap || error
    grep -xF "Invalid value for list-mailbox: $v" <"$STDERR"
done

# vim: set filetype=bash :