initial commit
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*~
|
||||
19
README.md
Normal file
19
README.md
Normal file
@@ -0,0 +1,19 @@
|
||||
promo_cleanup
|
||||
=============
|
||||
|
||||
This script enumerates all subfolders under a folder named "Promotions" on
|
||||
your IMAP server and deletes everything more than a week old. Use it
|
||||
against mailers who aren't exactly sending spam but that you don't want
|
||||
cluttering your main inbox by using something like procmail or sieve to sort
|
||||
them into Promotions subfolders. This can be set to run as a daily cronjob
|
||||
to keep things from getting out of control.
|
||||
|
||||
Configure with the following environment variables, which should be
|
||||
self-explanatory:
|
||||
|
||||
```IMAP_SERVER```
|
||||
```IMAP_USER```
|
||||
```IMAP_PASSWD```
|
||||
|
||||
The script assumes you have SSL enabled on port 993 on your IMAP server. If
|
||||
you don't, you're doing it wrong.
|
||||
15
promo_cleanup.py
Executable file
15
promo_cleanup.py
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import imaplib
|
||||
from datetime import datetime, timedelta
|
||||
from os import environ
|
||||
|
||||
with imaplib.IMAP4_SSL(environ["IMAP_SERVER"]) as M:
|
||||
M.login(environ["IMAP_USER"], environ["IMAP_PASSWD"])
|
||||
for i in M.list(pattern="Promotions.*")[1]:
|
||||
M.select(i.decode().split(' "." ')[1])
|
||||
typ, data=M.search(None, '(BEFORE "'+(datetime.now()-timedelta(days=7)).strftime("%d-%b-%Y")+'")')
|
||||
for j in data[0].split():
|
||||
M.store(j, "+FLAGS", "\\Deleted")
|
||||
M.expunge()
|
||||
|
||||
Reference in New Issue
Block a user