summaryrefslogtreecommitdiff
path: root/service/pixelated/adapter/mailstore/leap_mailstore.py
diff options
context:
space:
mode:
authorJefferson Stachelski <jstachel@thoughtworks.com>2015-11-23 19:30:33 -0200
committerJefferson Stachelski <jstachel@thoughtworks.com>2015-11-24 15:37:39 -0200
commit005eceda8ca1185514aa19182fb179eecca735e2 (patch)
treea066ae017a1ec415e54aa69a6a6e636fd96d9cd9 /service/pixelated/adapter/mailstore/leap_mailstore.py
parent2c477f6045bd840d5794d6caff001ad8bdd8b760 (diff)
Issue #494 - Bruno/Jeff Fixed the encoding tests
Diffstat (limited to 'service/pixelated/adapter/mailstore/leap_mailstore.py')
-rw-r--r--service/pixelated/adapter/mailstore/leap_mailstore.py18
1 files changed, 10 insertions, 8 deletions
diff --git a/service/pixelated/adapter/mailstore/leap_mailstore.py b/service/pixelated/adapter/mailstore/leap_mailstore.py
index 3bf27bbf..90035d20 100644
--- a/service/pixelated/adapter/mailstore/leap_mailstore.py
+++ b/service/pixelated/adapter/mailstore/leap_mailstore.py
@@ -49,9 +49,8 @@ class LeapMail(Mail):
@property
def headers(self):
cpy = dict(self._headers)
-
for name in set(self._headers.keys()).intersection(['To', 'Cc', 'Bcc']):
- cpy[name] = self._headers[name].split(',') if self._headers[name] else []
+ cpy[name] = [address.strip() for address in (self._headers[name].split(',') if self._headers[name] else [])]
return cpy
@@ -146,17 +145,20 @@ class LeapMail(Mail):
if sender_mail is None:
sender_mail = InputMail.FROM_EMAIL_ADDRESS
- recipients = self._decoded_header_utf_8(self._reply_recipient('To'))
- if not self._parsed_mail_matches(sender_mail, InputMail.FROM_EMAIL_ADDRESS) or len(recipients) == 0:
- recipients.append(sender_mail)
+ recipients = self._reply_recipient('To')
+ recipients = self._decoded_header_utf_8(recipients)
+ recipients.append(sender_mail)
recipients = self.remove_duplicates(recipients)
ccs = self._decoded_header_utf_8(self._reply_recipient('Cc'))
result['single'] = sender_mail
- result['all']['to-field'] = recipients
- result['all']['cc-field'] = ccs
+ result['all']['to-field'] = self._remove_me(recipients) if len(recipients) > 1 else recipients
+ result['all']['cc-field'] = self._remove_me(ccs) if len(ccs) > 1 else ccs
return result
+ def _remove_me(self, recipients):
+ return [recipient for recipient in recipients if not self._parsed_mail_matches(recipient, InputMail.FROM_EMAIL_ADDRESS)]
+
def remove_duplicates(self, recipients):
return list(set(recipients))
@@ -170,7 +172,7 @@ class LeapMail(Mail):
def _parsed_mail_matches(self, to_parse, expected):
if InputMail.FROM_EMAIL_ADDRESS is None:
return False
- return parseaddr(self._decoded_header_utf_8(to_parse))[1] == expected
+ return parseaddr(to_parse)[1] == expected
@staticmethod
def from_dict(mail_dict):