NL bounces: Some MTA don't set Final-Recipient in their bounces but use Remote-Recipi...
authorNicolas Iooss <nicolas.iooss_git@polytechnique.org>
Fri, 10 Jan 2014 18:14:26 +0000 (19:14 +0100)
committerNicolas Iooss <nicolas.iooss_git@polytechnique.org>
Mon, 3 Feb 2014 20:08:42 +0000 (21:08 +0100)
relay.supermarchesmatch.fr is such MTA

Signed-off-by: Nicolas Iooss <nicolas.iooss_git@polytechnique.org>
bin/newsletter.bounces.processor.py

index 3206ef7..b75580d 100755 (executable)
@@ -165,10 +165,18 @@ def findAddressInBounce(bounce):
         print('! Not a valid bounce (expected text/plain, found %s).' % content.get_content_type())
         return None
     # Extract the faulty email address
-    recipient_match = _recipient_re.search(content['Final-Recipient'])
+    # Some MTA don't set Final-Recipient but use Remote-Recipient instead
+    if 'Final-Recipient' in content:
+        final_recipient = content['Final-Recipient']
+    elif 'Remote-Recipient' in content:
+        final_recipient = content['Remote-Recipient']
+    else:
+        print('! Not a valid bounce (no Final-Recipient).')
+        return None
+    recipient_match = _recipient_re.search(final_recipient)
     if recipient_match is None:
         # Be nice, test another regexp
-        recipient_match = _recipient_re2.search(content['Final-Recipient'])
+        recipient_match = _recipient_re2.search(final_recipient)
         if recipient_match is None:
             print('! Missing final recipient.')
             return None