mercurial/mail.py
changeset 52365 bff68b6e5999
parent 51859 f4733654f144
child 52639 9db77d46de79
equal deleted inserted replaced
52364:7ac7d5f20cb0 52365:bff68b6e5999
    26     Tuple,
    26     Tuple,
    27     Union,
    27     Union,
    28 )
    28 )
    29 
    29 
    30 from .i18n import _
    30 from .i18n import _
    31 from .pycompat import (
       
    32     open,
       
    33 )
       
    34 from . import (
    31 from . import (
    35     encoding,
    32     encoding,
    36     error,
    33     error,
    37     pycompat,
    34     pycompat,
    38     sslutil,
    35     sslutil,
   219 
   216 
   220 
   217 
   221 def _mbox(mbox, sender, recipients, msg):
   218 def _mbox(mbox, sender, recipients, msg):
   222     '''write mails to mbox'''
   219     '''write mails to mbox'''
   223     # TODO: use python mbox library for proper locking
   220     # TODO: use python mbox library for proper locking
   224     with open(mbox, b'ab+') as fp:
   221     with open(mbox, 'ab+') as fp:
   225         # Should be time.asctime(), but Windows prints 2-characters day
   222         # Should be time.asctime(), but Windows prints 2-characters day
   226         # of month instead of one. Make them print the same thing.
   223         # of month instead of one. Make them print the same thing.
   227         date = time.strftime('%a %b %d %H:%M:%S %Y', time.localtime())
   224         date = time.strftime('%a %b %d %H:%M:%S %Y', time.localtime())
   228         fp.write(
   225         fp.write(
   229             b'From %s %s\n'
   226             b'From %s %s\n'
   235 
   232 
   236 def connect(ui, mbox=None):
   233 def connect(ui, mbox=None):
   237     """make a mail connection. return a function to send mail.
   234     """make a mail connection. return a function to send mail.
   238     call as sendmail(sender, list-of-recipients, msg)."""
   235     call as sendmail(sender, list-of-recipients, msg)."""
   239     if mbox:
   236     if mbox:
   240         open(mbox, b'wb').close()
   237         open(mbox, 'wb').close()
   241         return lambda s, r, m: _mbox(mbox, s, r, m)
   238         return lambda s, r, m: _mbox(mbox, s, r, m)
   242     if ui.config(b'email', b'method') == b'smtp':
   239     if ui.config(b'email', b'method') == b'smtp':
   243         return _smtp(ui)
   240         return _smtp(ui)
   244     return lambda s, r, m: _sendmail(ui, s, r, m)
   241     return lambda s, r, m: _sendmail(ui, s, r, m)
   245 
   242