Skip to content

Commit dedc7e6

Browse files
committed
Modified the mailtrigger clean_duplicates to reduce email address list entries with the same address but different names to one instance, and use consistent unicode names for authors if known.
- Legacy-Id: 14122
1 parent f6e91e7 commit dedc7e6

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

ietf/mailtrigger/models.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,29 @@
55

66
from email.utils import parseaddr
77
from ietf.utils.mail import formataddr
8+
from ietf.person.models import Email
89

910
import debug # pyflakes:ignore
1011

1112
from ietf.group.models import Role
1213

1314
def clean_duplicates(addrlist):
14-
retval = set()
15+
address_info = {}
1516
for a in addrlist:
1617
(name,addr) = parseaddr(a)
18+
# This collapses duplicate addresses to one, using (arbitrarily) the
19+
# name from the last one:
20+
address_info[addr] = (name, a)
21+
addresses = []
22+
for addr, info in address_info.items():
23+
name, a = info
1724
if (name,addr)==('',''):
18-
retval.add(a)
25+
addresses.append(a)
1926
elif name:
20-
retval.add(formataddr((name,addr)))
27+
addresses.append(formataddr((name,addr)))
2128
else:
22-
retval.add(addr)
23-
return list(retval)
29+
addresses.append(addr)
30+
return addresses
2431

2532
class MailTrigger(models.Model):
2633
slug = models.CharField(max_length=32, primary_key=True)
@@ -223,8 +230,13 @@ def gather_submission_confirmers(self, **kwargs):
223230
if doc.stream_id and doc.stream_id not in ['ietf']:
224231
addrs.extend(Recipient.objects.get(slug='stream_managers').gather(**{'streams':[doc.stream_id]}))
225232
else:
226-
addrs.extend([formataddr((author["name"], author["email"])) for author in submission.authors if author.get("email")])
227-
if submission.submitter_parsed()["email"]:
233+
# This is a bit roundabout, but we do it to get consistent and unicode-compliant
234+
# email names for known persons, without relying on the name parsed from the
235+
# draft (which might be ascii, also for persons with non-ascii names)
236+
emails = [ Email.objects.filter(address=author['email']).first() or author for author in submission.authors if author.get('email') ]
237+
addrs.extend([ e.formatted_email() if isinstance(e, Email) else formataddr((e["name"], e["email"])) for e in emails ] )
238+
submitter_email = submission.submitter_parsed()["email"]
239+
if submitter_email and not submitter_email in [ parseaddr(a)[1] for a in addrs ]:
228240
addrs.append(submission.submitter)
229241
return addrs
230242

0 commit comments

Comments
 (0)