NL bounces: accept final-recipient starting with LOCAL; in findAddressInBounce
authorNicolas Iooss <nicolas.iooss_git@polytechnique.org>
Tue, 20 Aug 2013 11:47:46 +0000 (13:47 +0200)
committerNicolas Iooss <nicolas.iooss_git@polytechnique.org>
Sat, 21 Sep 2013 15:20:14 +0000 (17:20 +0200)
Signed-off-by: Nicolas Iooss <nicolas.iooss_git@polytechnique.org>
bin/newsletter.bounces.processor.py

index 18f0cc7..b17d945 100755 (executable)
@@ -123,6 +123,8 @@ def findSubject(message):
 
 
 _recipient_re = re.compile(r'^rfc822; ?(.+)$', re.I | re.U)
+# Some MTA set the Final-Recipient with "LOCAL;" instead of "rfc822;"
+_recipient_re2 = re.compile(r'^local; ?(.+)$', re.I | re.U)
 
 
 def findAddressInBounce(bounce):
@@ -156,8 +158,11 @@ def findAddressInBounce(bounce):
     # Extract the faulty email address
     recipient_match = _recipient_re.search(content['Final-Recipient'])
     if recipient_match is None:
-        print('! Missing final recipient.')
-        return None
+        # Be nice, test another regexp
+        recipient_match = _recipient_re2.search(content['Final-Recipient'])
+        if recipient_match is None:
+            print('! Missing final recipient.')
+            return None
     email = recipient_match.group(1)
     # Check the action field
     if content['Action'].lower() != 'failed':