X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=bin%2Fnewsletter.bounces.processor.py;h=8fc3c1a75531ef5edf3f4c0b74b6b3c5b1b98a72;hb=468c1813bdfc759bed5beba57325ea2e6df6aa2a;hp=e3e611a3103acde16f143ba332cd6fc4dbcc2815;hpb=aa6c6ed4cb8d69f8f552a4f3641ae5f8627933f3;p=platal.git diff --git a/bin/newsletter.bounces.processor.py b/bin/newsletter.bounces.processor.py index e3e611a..8fc3c1a 100755 --- a/bin/newsletter.bounces.processor.py +++ b/bin/newsletter.bounces.processor.py @@ -1,7 +1,7 @@ #!/usr/bin/env python2.5 # -*- coding: utf-8 -*- #*************************************************************************** -#* Copyright (C) 2004-2008 polytechnique.org * +#* Copyright (C) 2003-2010 Polytechnique.org * #* http://opensource.polytechnique.org/ * #* * #* This program is free software; you can redistribute it and/or modify * @@ -20,8 +20,6 @@ #* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * #*************************************************************************** -# Copyright (c) 2008 Aymeric Augustin - """ Process as automatically as possible bounces from the newsletter @@ -178,15 +176,24 @@ class DirectBouncesFilter(MboxFilter): if message['X-Spam-Flag'] is None: # During finalization, we will verifiy that all messages were processed self.seen += 1 + # Special case: ignore mailman notifications for the mailing-list + # on which the NL is forwarded + if message['From'] == 'polytechnique.org_newsletter-externes-bounces@listes.polytechnique.org': + print '! Dropping a notification from mailman for newsletter-externes@polytechnique.org, this should be OK.' + self.seen -= 1 + return True # Additionnal checks, just to be sure - if message['From'] != 'MAILER-DAEMON@polytechnique.org (Mail Delivery System)' \ + elif message['From'] != 'MAILER-DAEMON@polytechnique.org (Mail Delivery System)' \ or message['Subject'] != 'Undelivered Mail Returned to Sender': - return False - email = findAddressInBounce(message) - if email is not None: - self.emails.append(email) - self.mbox.add(message) - return True + print '! Not an usual direct bounce (From="%s", Subject="%s").' % (message['From'], message['Subject']) + else: + email = findAddressInBounce(message) + if email is not None: + self.emails.append(email) + self.mbox.add(message) + return True + else: + print '! No email found in direct bounce, this is really bad.' return False def finalize(self): @@ -213,7 +220,8 @@ class SpamFilter(MboxFilter): self.mbox.clear() def process(self, message): - if message['X-Spam-Flag'].startswith('Yes, tests=bogofilter'): + if message['X-Spam-Flag'] is not None \ + and message['X-Spam-Flag'].startswith('Yes, tests=bogofilter'): self.mbox.add(message) return True return False @@ -234,7 +242,8 @@ class UnsureFilter(MboxFilter): self.mbox.clear() def process(self, message): - if message['X-Spam-Flag'].startswith('Unsure, tests=bogofilter'): + if message['X-Spam-Flag'] is not None \ + and message['X-Spam-Flag'].startswith('Unsure, tests=bogofilter'): self.mbox.add(message) return True return False @@ -253,13 +262,14 @@ class CheckNonSpamFilter(MboxFilter): self.seen = 0 def process(self, message): - if not message['X-Spam-Flag'].startswith('No, tests=bogofilter'): + if message['X-Spam-Flag'] is None \ + or not message['X-Spam-Flag'].startswith('No, tests=bogofilter'): self.seen += 1 return False def finalize(self): if self.seen > 0: - print 'Encountered %d messages that were neither spam, nor unsure, nor non-spams.' % self.counter + print 'Encountered %d messages that were neither spam, nor unsure, nor non-spams.' % self.seen print 'Please investigate.' else: print 'All messages were either spam, or unsure, or non-spams. Good.'