Skip to content

Instantly share code, notes, and snippets.

@mekuls
Created June 1, 2012 10:21
Show Gist options
  • Save mekuls/2850998 to your computer and use it in GitHub Desktop.
Save mekuls/2850998 to your computer and use it in GitHub Desktop.
Retrieve a list of postfix greylisted emails that didn't retry
import glob
fileNames = glob.glob("/var/log/mail*")
recipient = "username@example.com"
greylistEntries = []
for fileName in fileNames:
for line in open(fileName).xreadlines():
if recipient in line and "action=greylist, reason=new" in line:
datePart = line[:14]
tokens = line.partition("sender=")
senderAddress = tokens[2].partition(",")[0]
greylistEntries.append([datePart, senderAddress])
print "adding greylist item " , senderAddress
y = len(greylistEntries)
x = 1
while x < y:
if greylistEntries[x][1] in line and "action=pass" in line:
print "removing greylist item " , greylistEntries[x]
greylistEntries.remove(greylistEntries[x])
y = y - 1
x = x + 1
if len(greylistEntries) == 0:
print "All greylisted entries retried Successfully"
else:
print "Failed Emails:"
for listEntry in greylistEntries:
print listEntry[0], " - ",listEntry[1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment