LMTP/POP/SIEVE: cleanup bailout sequence

use the same pattern and logic as proven for imap
IMAP: use slightly faster query for counting

thanks to Pavlo Lavrenenko