##// END OF EJS Templates
fix typo in mail.py
Alexis S. L. Carvalho -
r2964:26c8d374 default
parent child Browse files
Show More
@@ -1,68 +1,68 b''
1 1 # mail.py - mail sending bits for mercurial
2 2 #
3 3 # Copyright 2006 Matt Mackall <mpm@selenic.com>
4 4 #
5 5 # This software may be used and distributed according to the terms
6 6 # of the GNU General Public License, incorporated herein by reference.
7 7
8 8 from i18n import gettext as _
9 9 from demandload import *
10 10 demandload(globals(), "os re smtplib templater util")
11 11
12 12 def _smtp(ui):
13 13 '''send mail using smtp.'''
14 14
15 15 local_hostname = ui.config('smtp', 'local_hostname')
16 16 s = smtplib.SMTP(local_hostname=local_hostname)
17 17 mailhost = ui.config('smtp', 'host')
18 18 if not mailhost:
19 19 raise util.Abort(_('no [smtp]host in hgrc - cannot send mail'))
20 20 mailport = int(ui.config('smtp', 'port', 25))
21 self.note(_('sending mail: smtp host %s, port %s\n') %
22 (mailhost, mailport))
21 ui.note(_('sending mail: smtp host %s, port %s\n') %
22 (mailhost, mailport))
23 23 s.connect(host=mailhost, port=mailport)
24 24 if ui.configbool('smtp', 'tls'):
25 25 ui.note(_('(using tls)\n'))
26 26 s.ehlo()
27 27 s.starttls()
28 28 s.ehlo()
29 29 username = ui.config('smtp', 'username')
30 30 password = ui.config('smtp', 'password')
31 31 if username and password:
32 32 ui.note(_('(authenticating to mail server as %s)\n') %
33 33 (username))
34 34 s.login(username, password)
35 35 return s
36 36
37 37 class _sendmail(object):
38 38 '''send mail using sendmail.'''
39 39
40 40 def __init__(self, ui, program):
41 41 self.ui = ui
42 42 self.program = program
43 43
44 44 def sendmail(self, sender, recipients, msg):
45 45 cmdline = '%s -f %s %s' % (
46 46 self.program, templater.email(sender),
47 47 ' '.join(map(templater.email, recipients)))
48 48 self.ui.note(_('sending mail: %s\n') % cmdline)
49 49 fp = os.popen(cmdline, 'w')
50 50 fp.write(msg)
51 51 ret = fp.close()
52 52 if ret:
53 53 raise util.Abort('%s %s' % (
54 54 os.path.basename(self.program.split(None, 1)[0]),
55 55 util.explain_exit(ret)[0]))
56 56
57 57 def connect(ui):
58 58 '''make a mail connection. object returned has one method, sendmail.
59 59 call as sendmail(sender, list-of-recipients, msg).'''
60 60
61 61 method = ui.config('email', 'method', 'smtp')
62 62 if method == 'smtp':
63 63 return _smtp(ui)
64 64
65 65 return _sendmail(ui, method)
66 66
67 67 def sendmail(ui, sender, recipients, msg):
68 68 return connect(ui).sendmail(sender, recipients, msg)
General Comments 0
You need to be logged in to leave comments. Login now