Article

Download the Results of a GMail Search Query, Including Chats!

This program lets you download all the results of a Gmail search query. Download the source here. Download the windows executable here. About: One of the things I love about Gmail and Gchat is the logging. Every chat I make using Gchat is stored in my archives just like an email. Unfortunately, though you can download and archive all your regular emails through Gmail’s POP interface using regular email backup tools, for some reason they don’t allow access to the chat logs this way. Another thing I love about Gmail is the powerful search feature. Google writes search software well, ’nuff said. Unfortunately, you can’t really download emails through a standard POP-based program based on a Gmail search query (if there’s a tool that does this let me know!). So I hacked together a small program that addresses all of these issues. GmailDownloader is a command line program through which you can:
  • Log into your Gmail account
  • Run a Gmail search
  • Download the results (including chat logs!)
It runs on the Gmail web interface, so it bypasses the restrictions of POP access.  There are limitations to this program:
  • If you download too many messages in too short a time, Gmail could detect this as unusual activity and lock you out of your account. I’ve successfully downloaded 1100 messages in one query without being locked out.  I’ve been locked out several times though when trying to download much more all at once.  The lock was released several hours after filling out the unlock captcha each time.
  • Since the Gmail web interface is not a standard like POP, it could change at any time and make this program stop working.  Let me know if that happens and I’ll try to update it.
This program uses pythonlibgmail, a hack to libgmail from this awesome guy, mechanize, ClientForm and ClientCookie.  It is based on the libgmail example program ‘archive.py’.  The Windows executable was generated using py2exe. Howto:
    1. Download and unzip the executable (or the source code… it should run out of box if you satisfy its dependencies)
    2. Run the executable.
  1. Enter your login credentials.
  2. Enter the search term for which you want to download the results.  You may want to experiment with searches in the Gmail web interface to get your search right, searches with many results take longer through the program take longer because the program runs through every page of the results before displaying anything.
  3. The program will tell you the number of hits the search term brought and show you the first few results.  Confirm that this is what you want and hit ‘y’ and enter.  If it’s not what you want hit ‘n’ and enter and return to step 4.
  4. Sit back and watch the emails roll in.  They will be dumped in a timestamped file in the same directory as the executable.
Enjoy!  

2 Comments

Leave a Comment

Your email address will not be published. Required fields are marked *

Subscribe to our newsletter
GoogleSidebar Office365Sidebar DellSidebar MicrosoftSidebar auth