At one point it was possible to use scripts like libgmail and gmail.py (can\'t post more than one hyperlink) to export mail from Gmail accounts. Both of those seem to not w
As far as I know neither libgmail nor gmail.py are compatible with the current version of Gmail. I use IMAP to download mails from gmail. Python's imaplib module is quite useful for this.
This answer (disclaimer: my answer) to a related question might give you some clues.