The following groovy code example shows how get email messages from an IMAP server and transform the message structure and data into XML. It took me a ridiculously long time to get this working, so I thought it would be a good idea to share the code with others. ;-) Processing complex messages with javax.mail API is no fun and there is a lot in StreamingMarkupBuilder (and groovy) which simply seems to get over my head.
The code below has been structured so that the IMAP client implementation is nicely separated from the markup building code using something, which to me looks a lot like the old school call-back mechanism used in the C language. Now, how groovy is that?
Any comments are welcome, of course!