mercurial/mail.py
changeset 43506 9f70512ae2cf
parent 43498 3b31ee5388f3
child 43575 67b4439c09b2
equal deleted inserted replaced
43505:47fac1692ede 43506:9f70512ae2cf
    92             self.keyfile,
    92             self.keyfile,
    93             self.certfile,
    93             self.certfile,
    94             ui=self._ui,
    94             ui=self._ui,
    95             serverhostname=self._host,
    95             serverhostname=self._host,
    96         )
    96         )
    97         self.file = new_socket.makefile(r'rb')
    97         self.file = new_socket.makefile('rb')
    98         return new_socket
    98         return new_socket
    99 
    99 
   100 
   100 
   101 def _pyhastls():
   101 def _pyhastls():
   102     """Returns true iff Python has TLS support, false otherwise."""
   102     """Returns true iff Python has TLS support, false otherwise."""
   199 def _mbox(mbox, sender, recipients, msg):
   199 def _mbox(mbox, sender, recipients, msg):
   200     '''write mails to mbox'''
   200     '''write mails to mbox'''
   201     fp = open(mbox, b'ab+')
   201     fp = open(mbox, b'ab+')
   202     # Should be time.asctime(), but Windows prints 2-characters day
   202     # Should be time.asctime(), but Windows prints 2-characters day
   203     # of month instead of one. Make them print the same thing.
   203     # of month instead of one. Make them print the same thing.
   204     date = time.strftime(r'%a %b %d %H:%M:%S %Y', time.localtime())
   204     date = time.strftime('%a %b %d %H:%M:%S %Y', time.localtime())
   205     fp.write(
   205     fp.write(
   206         b'From %s %s\n'
   206         b'From %s %s\n'
   207         % (encoding.strtolocal(sender), encoding.strtolocal(date))
   207         % (encoding.strtolocal(sender), encoding.strtolocal(date))
   208     )
   208     )
   209     fp.write(msg)
   209     fp.write(msg)
   401 def addrlistencode(ui, addrs, charsets=None, display=False):
   401 def addrlistencode(ui, addrs, charsets=None, display=False):
   402     '''Turns a list of addresses into a list of RFC-2047 compliant headers.
   402     '''Turns a list of addresses into a list of RFC-2047 compliant headers.
   403     A single element of input list may contain multiple addresses, but output
   403     A single element of input list may contain multiple addresses, but output
   404     always has one address per item'''
   404     always has one address per item'''
   405     for a in addrs:
   405     for a in addrs:
   406         assert isinstance(a, bytes), r'%r unexpectedly not a bytestr' % a
   406         assert isinstance(a, bytes), '%r unexpectedly not a bytestr' % a
   407     if display:
   407     if display:
   408         return [a.strip() for a in addrs if a.strip()]
   408         return [a.strip() for a in addrs if a.strip()]
   409 
   409 
   410     result = []
   410     result = []
   411     for name, addr in email.utils.getaddresses(
   411     for name, addr in email.utils.getaddresses(
   434         ep = email.parser.Parser()
   434         ep = email.parser.Parser()
   435         # disable the "universal newlines" mode, which isn't binary safe.
   435         # disable the "universal newlines" mode, which isn't binary safe.
   436         # I have no idea if ascii/surrogateescape is correct, but that's
   436         # I have no idea if ascii/surrogateescape is correct, but that's
   437         # what the standard Python email parser does.
   437         # what the standard Python email parser does.
   438         fp = io.TextIOWrapper(
   438         fp = io.TextIOWrapper(
   439             fp, encoding=r'ascii', errors=r'surrogateescape', newline=chr(10)
   439             fp, encoding='ascii', errors='surrogateescape', newline=chr(10)
   440         )
   440         )
   441         try:
   441         try:
   442             return ep.parse(fp)
   442             return ep.parse(fp)
   443         finally:
   443         finally:
   444             fp.detach()
   444             fp.detach()