sort email addresses and remove doubled ones before sending the email 3.1
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Thu, 15 Jan 2009 10:13:25 +0100
branch3.1
changeset 1371 a81d3babb582
parent 423 5269bfc6813f
child 1374 9d61b146f505
child 2027 85eae6a79f75
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:13:25 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: