More general work on this thing - mainly for imap protocol stuff