Show More
@@ -299,7 +299,7 b' def headencode(ui, s, charsets=None, dis' | |||
|
299 | 299 | def _addressencode(ui, name, addr, charsets=None): |
|
300 | 300 | name = headencode(ui, name, charsets) |
|
301 | 301 | try: |
|
302 | acc, dom = addr.split('@') | |
|
302 | acc, dom = addr.split(r'@') | |
|
303 | 303 | acc = acc.encode('ascii') |
|
304 | 304 | dom = dom.decode(encoding.encoding).encode('idna') |
|
305 | 305 | addr = '%s@%s' % (acc, dom) |
@@ -311,27 +311,31 b' def _addressencode(ui, name, addr, chars' | |||
|
311 | 311 | addr = addr.encode('ascii') |
|
312 | 312 | except UnicodeDecodeError: |
|
313 | 313 | raise error.Abort(_('invalid local address: %s') % addr) |
|
314 | return email.utils.formataddr((name, addr)) | |
|
314 | return pycompat.bytesurl( | |
|
315 | email.utils.formataddr((name, encoding.strfromlocal(addr)))) | |
|
315 | 316 | |
|
316 | 317 | def addressencode(ui, address, charsets=None, display=False): |
|
317 | 318 | '''Turns address into RFC-2047 compliant header.''' |
|
318 | 319 | if display or not address: |
|
319 | 320 | return address or '' |
|
320 | name, addr = email.utils.parseaddr(address) | |
|
321 | name, addr = email.utils.parseaddr(encoding.strfromlocal(address)) | |
|
321 | 322 | return _addressencode(ui, name, addr, charsets) |
|
322 | 323 | |
|
323 | 324 | def addrlistencode(ui, addrs, charsets=None, display=False): |
|
324 | 325 | '''Turns a list of addresses into a list of RFC-2047 compliant headers. |
|
325 | 326 | A single element of input list may contain multiple addresses, but output |
|
326 | 327 | always has one address per item''' |
|
328 | for a in addrs: | |
|
329 | assert isinstance(a, bytes), (r'%r unexpectedly not a bytestr' % a) | |
|
327 | 330 | if display: |
|
328 | 331 | return [a.strip() for a in addrs if a.strip()] |
|
329 | 332 | |
|
330 | 333 | result = [] |
|
331 |
for name, addr in email.utils.getaddresses( |
|
|
334 | for name, addr in email.utils.getaddresses( | |
|
335 | [encoding.strfromlocal(a) for a in addrs]): | |
|
332 | 336 | if name or addr: |
|
333 | 337 | result.append(_addressencode(ui, name, addr, charsets)) |
|
334 | return result | |
|
338 | return [pycompat.bytesurl(r) for r in result] | |
|
335 | 339 | |
|
336 | 340 | def mimeencode(ui, s, charsets=None, display=False): |
|
337 | 341 | '''creates mime text object, encodes it if needed, and sets |
General Comments 0
You need to be logged in to leave comments.
Login now