Originally requested by pejakm here.
Can this be more flexible? e.g. make this to work with IMAP servers, too.
Will it maybe possible to use some code from here: https://github.com/katropine/gmailsniffer