Implemented a better workaround for a GMail IMAP bug

Fixes issue #59 (thanks to Anton Gordienko)