# HG changeset patch # User Vadim Gelfer # Date 1146770581 25200 # Node ID 9f43b6e242322df8e7f06a54f9432a6f14a8f3f1 # Parent f1986a61ccff2385a53cb0a6ad3b3ab15750eac1 move mail sending code into core, so extensions can share it. document hgrc settings used. diff -r f1986a61ccff -r 9f43b6e24232 doc/hgrc.5.txt --- a/doc/hgrc.5.txt Thu May 04 12:02:32 2006 -0700 +++ b/doc/hgrc.5.txt Thu May 04 12:23:01 2006 -0700 @@ -130,6 +130,12 @@ # 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 @@ 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 diff -r f1986a61ccff -r 9f43b6e24232 hgext/patchbomb.py --- a/hgext/patchbomb.py Thu May 04 12:02:32 2006 -0700 +++ b/hgext/patchbomb.py Thu May 04 12:23:01 2006 -0700 @@ -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 @@ 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 @@ 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': diff -r f1986a61ccff -r 9f43b6e24232 mercurial/ui.py --- a/mercurial/ui.py Thu May 04 12:02:32 2006 -0700 +++ b/mercurial/ui.py Thu May 04 12:23:01 2006 -0700 @@ -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 @@ 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