A few improvements for imap.py