Maybe you could install a local mail client like Thunderbird and connect it to your Gmail via POP3? POP will download the mails and delete them from the server. Then you’ll just have to figure out how to export the mails from Thunderbird/your client of choice.
EDIT: This article contains relevant information.
EDIT 2: Alternativly you could just use IMAP instead of POP to download everything and then delete the mails from the server manually.
I don’t understand - you want a layer to hide database internals but also a web app that “is only the db itself”?