Created
August 8, 2014 17:22
-
-
Save jsilence/58e10d4bfc48d801bf30 to your computer and use it in GitHub Desktop.
tidy pop accounts with quota
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# A very simple housekeeping script for POP accounts. fetchmail and getmail unfortunately don't | |
# have the option to delete old mail. They either 'pop and keep' or 'pop and delete'. If you have a mail | |
# account with quota this might be annoying. You'd like to keep as many mails on your server as possible | |
# just in case, but would like to avoid running out of quota. | |
# Edit this tiny script, save it in ~/bin with restrictive file permissions, since it contains your | |
# mail account credentials, and put it in your personal crontab. | |
# It is not very smart and makes no guarantees about that reserved space of your quota. If you | |
# receive a mail with a large attachment it might have to run a couple of times, deleting one old mail | |
# at a time, to free up some space. | |
import poplib | |
QUOTA = 15 * 1024 * 1024 # 15Mb Quota | |
RESERVED = 2 * 1024 * 1024 # 2Mb to keep free | |
# POP Server | |
server = poplib.POP3_SSL('pop.yourmailserver.com') | |
server.user('user@yourdomain.com') | |
server.pass_('secret_password') | |
mailboxsize = server.stat()[1] | |
print("Mailboxsize: %s kB" % (mailboxsize / 1024,)) | |
if mailboxsize > (QUOTA - RESERVED): | |
server.dele(1) # message number 1 is always the oldest mail | |
print("deleting a mail to free up quota") | |
server.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment