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.


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 ‘’.  The Windows executable was generated using py2exe.


  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.

Continue reading “Download the Results of a GMail Search Query, Including Chats!”