comparison hgext/patchbomb.py @ 2200:9f43b6e24232

move mail sending code into core, so extensions can share it. document hgrc settings used.
author Vadim Gelfer <vadim.gelfer@gmail.com>
date Thu, 04 May 2006 12:23:01 -0700
parents 564034552f7f
children f15056b29472
comparison
equal deleted inserted replaced
2199:f1986a61ccff 2200:9f43b6e24232
28 # display each of the messages that it would send. 28 # display each of the messages that it would send.
29 # 29 #
30 # The "-m" (mbox) option will create an mbox file instead of sending 30 # The "-m" (mbox) option will create an mbox file instead of sending
31 # the messages directly. This can be reviewed e.g. with "mutt -R -f mbox", 31 # the messages directly. This can be reviewed e.g. with "mutt -R -f mbox",
32 # and finally sent with "formail -s sendmail -bm -t < mbox". 32 # and finally sent with "formail -s sendmail -bm -t < mbox".
33 #
34 # To configure a default mail host, add a section like this to your
35 # hgrc file:
36 #
37 # [smtp]
38 # host = my_mail_host
39 # port = 1025
40 # tls = yes # or omit if not needed
41 # username = user # if SMTP authentication required
42 # password = password # if SMTP authentication required - PLAINTEXT
43 # 33 #
44 # To configure other defaults, add a section like this to your hgrc 34 # To configure other defaults, add a section like this to your hgrc
45 # file: 35 # file:
46 # 36 #
47 # [email] 37 # [email]
50 # cc = cc1, cc2, ... 40 # cc = cc1, cc2, ...
51 41
52 from mercurial.demandload import * 42 from mercurial.demandload import *
53 demandload(globals(), '''email.MIMEMultipart email.MIMEText email.Utils 43 demandload(globals(), '''email.MIMEMultipart email.MIMEText email.Utils
54 mercurial:commands,hg,ui 44 mercurial:commands,hg,ui
55 os errno popen2 smtplib socket sys tempfile time''') 45 os errno popen2 socket sys tempfile time''')
56 from mercurial.i18n import gettext as _ 46 from mercurial.i18n import gettext as _
57 47
58 try: 48 try:
59 # readline gives raw_input editing capabilities, but is not 49 # readline gives raw_input editing capabilities, but is not
60 # present on windows 50 # present on windows
223 msgs.insert(0, msg) 213 msgs.insert(0, msg)
224 214
225 ui.write('\n') 215 ui.write('\n')
226 216
227 if not opts['test'] and not opts['mbox']: 217 if not opts['test'] and not opts['mbox']:
228 s = smtplib.SMTP() 218 mail = ui.sendmail()
229 s.connect(host = ui.config('smtp', 'host', 'mail'),
230 port = int(ui.config('smtp', 'port', 25)))
231 if ui.configbool('smtp', 'tls'):
232 s.ehlo()
233 s.starttls()
234 s.ehlo()
235 username = ui.config('smtp', 'username')
236 password = ui.config('smtp', 'password')
237 if username and password:
238 s.login(username, password)
239 parent = None 219 parent = None
240 tz = time.strftime('%z') 220 tz = time.strftime('%z')
241 sender_addr = email.Utils.parseaddr(sender)[1] 221 sender_addr = email.Utils.parseaddr(sender)[1]
242 for m in msgs: 222 for m in msgs:
243 try: 223 try:
271 fp.write(m.as_string(0)) 251 fp.write(m.as_string(0))
272 fp.write('\n\n') 252 fp.write('\n\n')
273 fp.close() 253 fp.close()
274 else: 254 else:
275 ui.status('Sending ', m['Subject'], ' ...\n') 255 ui.status('Sending ', m['Subject'], ' ...\n')
276 s.sendmail(sender, to + cc, m.as_string(0)) 256 mail.sendmail(sender, to + cc, m.as_string(0))
277 if not opts['test'] and not opts['mbox']: 257 if not opts['test'] and not opts['mbox']:
278 s.close() 258 mail.close()
279 259
280 cmdtable = { 260 cmdtable = {
281 'email': 261 'email':
282 (patchbomb, 262 (patchbomb,
283 [('c', 'cc', [], 'email addresses of copy recipients'), 263 [('c', 'cc', [], 'email addresses of copy recipients'),