Being somewhat lame, I always forget the IMAP protocol. Here's a basic command sequence.
1 login user password 1 list "" "*" 1 select inbox 1 fetch 1 All 1 logout
A collection of useful facts by Joel Williams. Contact me by email at joel at this domain.