move mail sending code into core, so extensions can share it.

document hgrc settings used.
This commit is contained in:
Vadim Gelfer 2006-05-04 12:23:01 -07:00
parent c40534f466
commit f906ed16e7
3 changed files with 43 additions and 25 deletions

View File

@ -130,6 +130,12 @@ decode/encode::
# them to the working dir
**.txt = tempfile: unix2dos -n INFILE OUTFILE
email::
Settings for extensions that send email messages.
from;;
Optional. Email address to use in "From" header and SMTP envelope
of outgoing messages.
hooks::
Commands or Python functions that get automatically executed by
various actions such as starting or finishing a commit. Multiple
@ -240,6 +246,24 @@ http_proxy::
user;;
Optional. User name to authenticate with at the proxy server.
smtp::
Configuration for extensions that need to send email messages.
host;;
Optional. Host name of mail server. Default: "mail".
port;;
Optional. Port to connect to on mail server. Default: 25.
tls;;
Optional. Whether to connect to mail server using TLS. True or
False. Default: False.
username;;
Optional. User name to authenticate to SMTP server with.
If username is specified, password must also be specified.
Default: none.
password;;
Optional. Password to authenticate to SMTP server with.
If username is specified, password must also be specified.
Default: none.
paths::
Assigns symbolic names to repositories. The left side is the
symbolic name, and the right gives the directory or URL that is the

View File

@ -31,16 +31,6 @@
# the messages directly. This can be reviewed e.g. with "mutt -R -f mbox",
# and finally sent with "formail -s sendmail -bm -t < mbox".
#
# To configure a default mail host, add a section like this to your
# hgrc file:
#
# [smtp]
# host = my_mail_host
# port = 1025
# tls = yes # or omit if not needed
# username = user # if SMTP authentication required
# password = password # if SMTP authentication required - PLAINTEXT
#
# To configure other defaults, add a section like this to your hgrc
# file:
#
@ -52,7 +42,7 @@
from mercurial.demandload import *
demandload(globals(), '''email.MIMEMultipart email.MIMEText email.Utils
mercurial:commands,hg,ui
os errno popen2 smtplib socket sys tempfile time''')
os errno popen2 socket sys tempfile time''')
from mercurial.i18n import gettext as _
try:
@ -225,17 +215,7 @@ def patchbomb(ui, repo, *revs, **opts):
ui.write('\n')
if not opts['test'] and not opts['mbox']:
s = smtplib.SMTP()
s.connect(host = ui.config('smtp', 'host', 'mail'),
port = int(ui.config('smtp', 'port', 25)))
if ui.configbool('smtp', 'tls'):
s.ehlo()
s.starttls()
s.ehlo()
username = ui.config('smtp', 'username')
password = ui.config('smtp', 'password')
if username and password:
s.login(username, password)
mail = ui.sendmail()
parent = None
tz = time.strftime('%z')
sender_addr = email.Utils.parseaddr(sender)[1]
@ -273,9 +253,9 @@ def patchbomb(ui, repo, *revs, **opts):
fp.close()
else:
ui.status('Sending ', m['Subject'], ' ...\n')
s.sendmail(sender, to + cc, m.as_string(0))
mail.sendmail(sender, to + cc, m.as_string(0))
if not opts['test'] and not opts['mbox']:
s.close()
mail.close()
cmdtable = {
'email':

View File

@ -8,7 +8,7 @@
import ConfigParser
from i18n import gettext as _
from demandload import *
demandload(globals(), "errno os re socket sys tempfile util")
demandload(globals(), "errno os re smtplib socket sys tempfile util")
class ui(object):
def __init__(self, verbose=False, debug=False, quiet=False,
@ -264,3 +264,17 @@ class ui(object):
os.unlink(name)
return t
def sendmail(self):
s = smtplib.SMTP()
s.connect(host = self.config('smtp', 'host', 'mail'),
port = int(self.config('smtp', 'port', 25)))
if self.configbool('smtp', 'tls'):
s.ehlo()
s.starttls()
s.ehlo()
username = self.config('smtp', 'username')
password = self.config('smtp', 'password')
if username and password:
s.login(username, password)
return s