Net::IMAP::Simple::Gmail might be helpful.
In reply to Re: imap problem with gmail by RonW in thread imap problem with gmail by morgon