You could configure gmail to allow pop3 access and then either write a pop client in php or download the emails to a computer using a normal pop client.
To allow POP access, go to "settings" (top right corner), then click on "forwarding and pop/imap." In the "POP Download" section click on "Enable POP for all mail " (first radio button) and save your changes.
Get the configuration instructions:
Supported POP client list - Gmail Help
If you're writing your own mail client, you'll need to connect to the pop server, authenticate and download- the commands are
telnet to server, port 110 and wait for "ok"
enter "user (username)"
enter "pass (password)"
list (get a list of messages)
retr (number corresponding to message) (download the message, just prints it out)
dele (number corresponding to message)
quit
All that's kind of a hassle. So I'd use a client or other pre-written script to get the mail to my local system and then work on it from there.
Sounds like a fun project
