diff options
author | simnyatsanga <simnyatsanga@gmail.com> | 2015-01-29 12:12:42 -0200 |
---|---|---|
committer | Jefferson Stachelski <jstachel@thoughtworks.com> | 2015-01-30 19:20:53 -0200 |
commit | 169855137edf126e22300c1beac9939ee59a6129 (patch) | |
tree | 035340afcf66b4635b702c79f1a672f667cf17f8 /service/pixelated | |
parent | 26f554f47b29434cac394ce8daa1508cfba30b38 (diff) |
Removing duplicate email address
Diffstat (limited to 'service/pixelated')
-rw-r--r-- | service/pixelated/adapter/services/mail_sender.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/service/pixelated/adapter/services/mail_sender.py b/service/pixelated/adapter/services/mail_sender.py index 1c2d7ce1..f4954514 100644 --- a/service/pixelated/adapter/services/mail_sender.py +++ b/service/pixelated/adapter/services/mail_sender.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. from StringIO import StringIO +import re from twisted.internet.defer import Deferred from twisted.mail.smtp import SMTPSenderFactory @@ -25,13 +26,26 @@ class MailSender(): def __init__(self, account_email_address, smtp_client=None): self.account_email_address = account_email_address + def recepients_normalizer(self, mail_list): + return set(mail_list) + + def get_email_addresses(self, mail_list): + clean_mail_list = [] + for mail_address in mail_list: + if "<" in mail_address: + match = re.search(r'<(.*)', mail_address) + clean_mail_list.append(match.group(1).strip('>')) + else: + clean_mail_list.append(mail_address) + return self.recepients_normalizer(clean_mail_list) + def sendmail(self, mail): recipients = flatten([mail.to, mail.cc, mail.bcc]) - + normalized_recepients = get_email_addresses(recipients) resultDeferred = Deferred() senderFactory = SMTPSenderFactory( fromEmail=self.account_email_address, - toEmail=recipients, + toEmail=normalized_recipients, file=StringIO(mail.to_smtp_format()), deferred=resultDeferred) |