! interimap --debug || error

# double check the presence of 'LOGINDISABLED' in the preauth capability list
grep -oE -m1 '^remote: S: \* OK \[CAPABILITY IMAP4rev1( [^]]*)? AUTH=[^]]*\]' <"$STDERR" >"$TMPDIR/capability"

sed -ri 's/^remote: S: \* OK \[CAPABILITY (.*)\]$/\1/' "$TMPDIR/capability"
tr " " "\\n" <"$TMPDIR/capability" >"$TMPDIR/capabilities"
grep -Fx "IMAP4rev1"     <"$TMPDIR/capabilities" || error
grep -Fx "LOGINDISABLED" <"$TMPDIR/capabilities" || error
! grep -Fx "STARTTLS"    <"$TMPDIR/capabilities" || error # otherwise we'd try to upgrade the connectionn

# make sure we didn't send any credentials
grep -Fx "remote: ERROR: Logins are disabled."   <"$STDERR" || error
! grep -E "^remote: C: .* (AUTHENTICATE|LOGIN) " <"$STDERR" || error

# vim: set filetype=sh :