in reply to Downloading attachments from IMAP using Perl
It's a collection of C utilities that would be easy to script, or you could borrow their code to make an XS api: http://www.washington.edu/imap/