summaryrefslogtreecommitdiff
path: root/service/pixelated/adapter/mailstore/leap_mailstore.py
diff options
context:
space:
mode:
authorGiovane <giovaneliberato@gmail.com>2016-01-14 18:34:00 -0200
committerBruno Wagner <bwagner@riseup.net>2016-01-15 11:11:55 -0200
commitcd831d1dfc42c2a0d292fe5c1b7f497b2ca393eb (patch)
tree4069da65211b163f7718b8628349976748a6d0ee /service/pixelated/adapter/mailstore/leap_mailstore.py
parent36972dc55f64100f4e056130cc1d32a266785a41 (diff)
Removes InputMail.FROM_EMAIL_ADDRESS constant #578
- Created the replier component to generate the reply dict for the email. This was needed to decouple the InputMail from the need to know who is the logged user.
Diffstat (limited to 'service/pixelated/adapter/mailstore/leap_mailstore.py')
-rw-r--r--service/pixelated/adapter/mailstore/leap_mailstore.py40
1 files changed, 4 insertions, 36 deletions
diff --git a/service/pixelated/adapter/mailstore/leap_mailstore.py b/service/pixelated/adapter/mailstore/leap_mailstore.py
index c2912bbe..cf8c8ed1 100644
--- a/service/pixelated/adapter/mailstore/leap_mailstore.py
+++ b/service/pixelated/adapter/mailstore/leap_mailstore.py
@@ -121,6 +121,9 @@ class LeapMail(Mail):
return result
+ def remove_duplicates(self, values):
+ return list(set(values))
+
def _decoded_header_utf_8(self, header_value):
if isinstance(header_value, list):
return self.remove_duplicates([self._decoded_header_utf_8(v) for v in header_value])
@@ -143,47 +146,12 @@ class LeapMail(Mail):
'body': self._body,
'security_casing': self.security_casing,
'textPlainBody': self._body,
- 'replying': self._replying_dict(),
'mailbox': self._mailbox_name.lower(),
'attachments': [attachment.as_dict() for attachment in self._attachments]
}
- def _replying_dict(self):
- result = {'single': None, 'all': {'to-field': [], 'cc-field': []}}
-
- sender_mail = self._decoded_header_utf_8(self.headers.get('Reply-To', self.headers.get('From')))
- # Issue #215: Fix for existing mails without any from address.
- if sender_mail is None:
- sender_mail = InputMail.FROM_EMAIL_ADDRESS
-
- 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'] = 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))
-
def _reply_recipient(self, kind):
- recipients = self.headers.get(kind, [])
- if not recipients:
- recipients = []
-
- return recipients
-
- def _parsed_mail_matches(self, to_parse, expected):
- if InputMail.FROM_EMAIL_ADDRESS is None:
- return False
- return parseaddr(to_parse)[1] == expected
+ return self.headers.get(kind, [])
@staticmethod
def from_dict(mail_dict):