summaryrefslogtreecommitdiff
path: root/service/pixelated/adapter/model/mail.py
diff options
context:
space:
mode:
authorPatrick Maia <pmaia@thoughtworks.com>2015-02-13 19:00:41 -0300
committerPatrick Maia <pmaia@thoughtworks.com>2015-02-20 11:15:11 -0300
commitc5f29f136f293a51d2fd42fcfd8fc18a39f09cfa (patch)
tree5ba6fdc2a678533bf001088f5c56c2237603711f /service/pixelated/adapter/model/mail.py
parentbb723e2cd21339f82c63ede3151d33022c0f029f (diff)
Issue #174 - extracts bounced address from bounce message
Diffstat (limited to 'service/pixelated/adapter/model/mail.py')
-rw-r--r--service/pixelated/adapter/model/mail.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/service/pixelated/adapter/model/mail.py b/service/pixelated/adapter/model/mail.py
index b3d2e3a5..a8d752c5 100644
--- a/service/pixelated/adapter/model/mail.py
+++ b/service/pixelated/adapter/model/mail.py
@@ -382,8 +382,23 @@ class PixelatedMail(Mail):
@property
def bounced(self):
- content_type = self.hdoc.content["headers"].get("Content-Type", '')
- return re.compile('delivery-status').search(content_type)
+ content_type = self.hdoc.content["headers"].get("Content-Type", '')
+ if re.compile('delivery-status').search(content_type):
+ return self._extract_bounced_address(self.hdoc.content)
+
+ return False
+
+ def _extract_bounced_address(self, part):
+ part_header = dict(part.get('headers', {}))
+ if 'Final-Recipient' in part_header:
+ return part_header['Final-Recipient'].split(';')[1].strip()
+ elif 'part_map' in part:
+ for subpart in part['part_map'].values():
+ result = self._extract_bounced_address(subpart)
+ if result:
+ return result
+ else:
+ continue
def as_dict(self):
dict_mail = {'header': {k.lower(): v for k, v in self.headers.items()},