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:
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
[DEFAULT] email@example.com password=MYPASSWORD [30days] maxage=30 labels=LABEL1,LABEL2 [aaaa] maxage=15 labels=LABEL3,LABEL4
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.
labels is a comma-delimited list of the labels you want
To run the scripts, you can either call them directly, if executable,
python gmaillabelpurge.py and
perl gmaillabelpurge.pl. 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,
--verbose for printing more runtime details, and
--pretend to just run a dry-run before actually executing
If anything breaks, you find bugs, or have feature requests you can contact us.