diff options
author | mfrankie <mfrankie@eumfranckie.local> | 2016-05-19 13:29:49 +0200 |
---|---|---|
committer | mfrankie <mfrankie@eumfranckie.local> | 2016-05-19 13:30:18 +0200 |
commit | 65c2b6d4bcb48517ad7a2e55adf1b94bcc1129fa (patch) | |
tree | 3f8931e36c9ffcab3ed2ef82b095d7b8b181a652 /service/pixelated/adapter/services/mail_service.py | |
parent | 3fd43a0a3f45bfbb0ab6bde36ba7b353dbf535ef (diff) |
issue #685 remove duplicated email recipients
Diffstat (limited to 'service/pixelated/adapter/services/mail_service.py')
-rw-r--r-- | service/pixelated/adapter/services/mail_service.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/service/pixelated/adapter/services/mail_service.py b/service/pixelated/adapter/services/mail_service.py index a5ed0897..1dce51fe 100644 --- a/service/pixelated/adapter/services/mail_service.py +++ b/service/pixelated/adapter/services/mail_service.py @@ -98,11 +98,33 @@ class MailService(object): def send_mail(self, content_dict): mail = InputMail.from_dict(content_dict, self.account_email) draft_id = content_dict.get('ident') + self._deduplicate_recipients(mail) yield self.mail_sender.sendmail(mail) sent_mail = yield self.move_to_sent(draft_id, mail) defer.returnValue(sent_mail) + def _deduplicate_recipients(self, mail): + self._remove_canonical(mail) + self._remove_duplicates_form_cc_and_to(mail) + + def _remove_canonical(self, mail): + mail.headers['To'] = map(self._remove_canonical_recipient, mail.to) + mail.headers['Cc'] = map(self._remove_canonical_recipient, mail.cc) + mail.headers['Bcc'] = map(self._remove_canonical_recipient, mail.bcc) + + def _remove_duplicates_form_cc_and_to(self, mail): + mail.headers['To'] = list(set(self._remove_duplicates(mail.to)).difference(set(mail.bcc))) + mail.headers['Cc'] = list((set(self._remove_duplicates(mail.cc)).difference(set(mail.bcc)).difference(set(mail.to)))) + mail.headers['Bcc'] = self._remove_duplicates(mail.bcc) + + def _remove_duplicates(self, recipient): + return list(set(recipient)) + + # TODO removing canocical should, be added back later + def _remove_canonical_recipient(self, recipient): + return recipient.split('<')[1][0:-1] if '<' in recipient else recipient + @defer.inlineCallbacks def move_to_sent(self, last_draft_ident, mail): if last_draft_ident: |