Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Purge all messages from a given gmail label that are older than a given amount of days
branch: master

This branch is 15 commits behind tante:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.

gmaillabelpurge - delete old messages from GMail labels

gmaillabelpurge allows you to delete all messages from given gmail labels when they reach a certain age.

it uses GMail's IMAP interface, which means you have to enable IMAP on your account, and speaks Google's IMAP extensions.

At the time of writing, we have two scripts: one written in Python 2, that only requires its standard library, and a faster, version in Perl which requires a few dependencies:

  • Config::IniFiles;
  • Mail::IMAPClient;
  • IO::Socket::SSL;
  • DateTime.

The Python version is not compatible with Python 3 at the moment.

How to use

Open the file ~/.config/com.github.tante.gmaillabelpurge with your favourite text editor. Take this example as a template for what to put in:


The section DEFAULT has to exist, and contains username (put your full gmail username here) and password (your password).

After that you can add as many [sections] as you want, calling them however you want.

For each of them, maxage is the maximum age in days for a mail in order for it not to be moved to the trash folder. All mail sent maxage+1 days ago is then deleted. If you enter -1 it will move all your mail in that given label to the trash.

Finally labels is a comma-delimited list of the labels you want purged.

To run the scripts, you can either call them directly, if executable, or as python and perl Please note that the Python script will not work correctly if executed through a Python 3.x interpreter.

Both scripts respond to the -h option to get help on the parameters, and use -v or --verbose for printing more runtime details, and -p or --pretend to just run a dry-run before actually executing any operation.


If anything breaks, you find bugs, or have feature requests you can contact us.

For the Python script: Mail: jabber: GitHub:

For the Perl script: Mail: GitHub:

Something went wrong with that request. Please try again.