sort email addresses and remove doubled ones before sending the email
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Thu, 15 Jan 2009 10:50:45 +0100
changeset 425 cc9e8986d55e
parent 423 5269bfc6813f
child 437 5d8dc9678707
sort email addresses and remove doubled ones before sending the email
common/mail.py
--- a/common/mail.py	Thu Jan 15 08:47:18 2009 +0100
+++ b/common/mail.py	Thu Jan 15 10:50:45 2009 +0100
@@ -56,9 +56,10 @@
         msg['Reply-to'] = msg['From']
     if config is not None:
         msg['X-CW'] = config.appid
-    msg['To'] = ', '.join(addrheader(addr) for addr in to_addrs if addr is not None)
+    unique_addrs = lambda addrs: sorted(set(addr for addr in addrs if addr is not None))
+    msg['To'] = ', '.join(addrheader(addr) for addr in unique_addrs(to_addrs))
     if cc_addrs:
-        msg['Cc'] = ', '.join(addrheader(addr) for addr in cc_addrs if addr is not None)
+        msg['Cc'] = ', '.join(addrheader(addr) for addr in unique_addrs(cc_addrs))
     if msgid:
         msg['Message-id'] = msgid
     if references: