|
5 | 5 |
|
6 | 6 | from email.utils import parseaddr |
7 | 7 | from ietf.utils.mail import formataddr |
| 8 | +from ietf.person.models import Email |
8 | 9 |
|
9 | 10 | import debug # pyflakes:ignore |
10 | 11 |
|
11 | 12 | from ietf.group.models import Role |
12 | 13 |
|
13 | 14 | def clean_duplicates(addrlist): |
14 | | - retval = set() |
| 15 | + address_info = {} |
15 | 16 | for a in addrlist: |
16 | 17 | (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 |
17 | 24 | if (name,addr)==('',''): |
18 | | - retval.add(a) |
| 25 | + addresses.append(a) |
19 | 26 | elif name: |
20 | | - retval.add(formataddr((name,addr))) |
| 27 | + addresses.append(formataddr((name,addr))) |
21 | 28 | else: |
22 | | - retval.add(addr) |
23 | | - return list(retval) |
| 29 | + addresses.append(addr) |
| 30 | + return addresses |
24 | 31 |
|
25 | 32 | class MailTrigger(models.Model): |
26 | 33 | slug = models.CharField(max_length=32, primary_key=True) |
@@ -223,8 +230,13 @@ def gather_submission_confirmers(self, **kwargs): |
223 | 230 | if doc.stream_id and doc.stream_id not in ['ietf']: |
224 | 231 | addrs.extend(Recipient.objects.get(slug='stream_managers').gather(**{'streams':[doc.stream_id]})) |
225 | 232 | 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 ]: |
228 | 240 | addrs.append(submission.submitter) |
229 | 241 | return addrs |
230 | 242 |
|
|
0 commit comments