diff options
author | mfrankie <mfrankie@eumfranckie.local> | 2016-05-17 16:56:55 +0200 |
---|---|---|
committer | mfrankie <mfrankie@eumfranckie.local> | 2016-05-19 13:30:18 +0200 |
commit | 3fd43a0a3f45bfbb0ab6bde36ba7b353dbf535ef (patch) | |
tree | 1b6bd18bcbde7a6bca00f362c0502f7ce2d901d0 /service/pixelated/adapter/services | |
parent | 053d51e8c6484f95b43c7b45e5b42fcb3e89784c (diff) |
remove duplicated mails, wip
Diffstat (limited to 'service/pixelated/adapter/services')
-rw-r--r-- | service/pixelated/adapter/services/mail_sender.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/service/pixelated/adapter/services/mail_sender.py b/service/pixelated/adapter/services/mail_sender.py index 4499adbd..08e81872 100644 --- a/service/pixelated/adapter/services/mail_sender.py +++ b/service/pixelated/adapter/services/mail_sender.py @@ -63,6 +63,9 @@ class MailSender(object): bccs = mail.bcc deferreds = [] + recipients = self._remove_canonical(mail, recipients) + self._remove_duplicates_form_cc_and_to(mail) + for recipient in recipients: self._define_bcc_field(mail, recipient, bccs) smtp_recipient = self._create_twisted_smtp_recipient(recipient) @@ -70,6 +73,20 @@ class MailSender(object): return defer.DeferredList(deferreds, fireOnOneErrback=False, consumeErrors=True) + 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)))) + + def _remove_canonical(self, mail, recipients): + mail.headers['To'] = self._remove_duplicates(map(self._remove_canonical_recipient, mail.to)) + mail.headers['Cc'] = self._remove_duplicates(map(self._remove_canonical_recipient, mail.cc)) + mail.headers['Bcc'] = self._remove_duplicates(map(self._remove_canonical_recipient, mail.bcc)) + + return self._remove_duplicates(map(self._remove_canonical_recipient, recipients)) + + def _remove_duplicates(self, recipient): + return list(set(recipient)) + def _define_bcc_field(self, mail, recipient, bccs): if recipient in bccs: mail.headers['Bcc'] = [recipient] @@ -92,7 +109,6 @@ class MailSender(object): def _create_twisted_smtp_recipient(self, recipient): # TODO: Better is fix Twisted instead - recipient = self._remove_canonical_recipient(recipient) return User(str(recipient), NOT_NEEDED, NOT_NEEDED, NOT_NEEDED) def _remove_canonical_recipient(self, recipient): |