##// END OF EJS Templates
patchbomb: mime-encode headers and parts not containing patches...
Christian Ebert -
r7115:c5c2d43b default
parent child Browse files
Show More
@@ -111,6 +111,8 def patchbomb(ui, repo, *revs, **opts):
111 111 See the [email] section in hgrc(5) for details.
112 112 '''
113 113
114 _charsets = mail._charsets(ui)
115
114 116 def prompt(prompt, default = None, rest = ': ', empty_ok = False):
115 117 if not ui.interactive:
116 118 return default
@@ -176,7 +178,8 def patchbomb(ui, repo, *revs, **opts):
176 178 if opts.get('attach') or opts.get('inline'):
177 179 msg = email.MIMEMultipart.MIMEMultipart()
178 180 if body:
179 msg.attach(email.MIMEText.MIMEText(body, 'plain'))
181 msg.attach(mail.mimeencode(ui, body, _charsets,
182 opts.get('test')))
180 183 p = email.MIMEText.MIMEText('\n'.join(patch), 'x-patch')
181 184 binnode = bin(node)
182 185 # if node is mq patch, it will have patch file name as tag
@@ -204,9 +207,9 def patchbomb(ui, repo, *revs, **opts):
204 207 else:
205 208 tlen = len(str(total))
206 209 subj = '[PATCH %0*d of %d] %s' % (tlen, idx, total, subj)
207 msg['Subject'] = subj
210 msg['Subject'] = mail.headencode(ui, subj, _charsets, opts.get('test'))
208 211 msg['X-Mercurial-Node'] = node
209 return msg
212 return msg, subj
210 213
211 214 def outgoing(dest, revs):
212 215 '''Return the revisions present locally but not in dest'''
@@ -328,10 +331,11 def patchbomb(ui, repo, *revs, **opts):
328 331 body = '\n' + d
329 332
330 333 body = getdescription(body, sender)
331 msg = email.MIMEText.MIMEText(body)
332 msg['Subject'] = subj
334 msg = mail.mimeencode(ui, body, _charsets, opts.get('test'))
335 msg['Subject'] = mail.headencode(ui, subj, _charsets,
336 opts.get('test'))
333 337
334 msgs.insert(0, msg)
338 msgs.insert(0, (msg, subj))
335 339 return msgs
336 340
337 341 def getbundlemsgs(bundle):
@@ -341,15 +345,15 def patchbomb(ui, repo, *revs, **opts):
341 345 body = getdescription('', sender)
342 346 msg = email.MIMEMultipart.MIMEMultipart()
343 347 if body:
344 msg.attach(email.MIMEText.MIMEText(body, 'plain'))
348 msg.attach(mail.mimeencode(ui, body, _charsets, opts.get('test')))
345 349 datapart = email.MIMEBase.MIMEBase('application', 'x-mercurial-bundle')
346 350 datapart.set_payload(bundle)
347 351 datapart.add_header('Content-Disposition', 'attachment',
348 352 filename='bundle.hg')
349 353 email.Encoders.encode_base64(datapart)
350 354 msg.attach(datapart)
351 msg['Subject'] = subj
352 return [msg]
355 msg['Subject'] = mail.headencode(ui, subj, _charsets, opts.get('test'))
356 return [(msg, subj)]
353 357
354 358 sender = (opts.get('from') or ui.config('email', 'from') or
355 359 ui.config('patchbomb', 'from') or
@@ -364,22 +368,25 def patchbomb(ui, repo, *revs, **opts):
364 368 addrs = opts.get(opt) or (ui.config('email', opt) or
365 369 ui.config('patchbomb', opt) or
366 370 prompt(prpt, default = default)).split(',')
367 return [a.strip() for a in addrs if a.strip()]
371 return [mail.addressencode(ui, a.strip(), _charsets, opts.get('test'))
372 for a in addrs if a.strip()]
368 373
369 374 to = getaddrs('to', 'To')
370 375 cc = getaddrs('cc', 'Cc', '')
371 376
372 377 bcc = opts.get('bcc') or (ui.config('email', 'bcc') or
373 378 ui.config('patchbomb', 'bcc') or '').split(',')
374 bcc = [a.strip() for a in bcc if a.strip()]
379 bcc = [mail.addressencode(ui, a.strip(), _charsets, opts.get('test'))
380 for a in bcc if a.strip()]
375 381
376 382 ui.write('\n')
377 383
378 384 parent = None
379 385
380 386 sender_addr = email.Utils.parseaddr(sender)[1]
387 sender = mail.addressencode(ui, sender, _charsets, opts.get('test'))
381 388 sendmail = None
382 for m in msgs:
389 for m, subj in msgs:
383 390 try:
384 391 m['Message-Id'] = genmsgid(m['X-Mercurial-Node'])
385 392 except TypeError:
@@ -398,7 +405,7 def patchbomb(ui, repo, *revs, **opts):
398 405 if bcc:
399 406 m['Bcc'] = ', '.join(bcc)
400 407 if opts.get('test'):
401 ui.status(_('Displaying '), m['Subject'], ' ...\n')
408 ui.status(_('Displaying '), subj, ' ...\n')
402 409 ui.flush()
403 410 if 'PAGER' in os.environ:
404 411 fp = util.popen(os.environ['PAGER'], 'w')
@@ -414,7 +421,7 def patchbomb(ui, repo, *revs, **opts):
414 421 if fp is not ui:
415 422 fp.close()
416 423 elif opts.get('mbox'):
417 ui.status(_('Writing '), m['Subject'], ' ...\n')
424 ui.status(_('Writing '), subj, ' ...\n')
418 425 fp = open(opts.get('mbox'), 'In-Reply-To' in m and 'ab+' or 'wb+')
419 426 generator = email.Generator.Generator(fp, mangle_from_=True)
420 427 date = util.datestr(start_time, '%a %b %d %H:%M:%S %Y')
@@ -425,7 +432,7 def patchbomb(ui, repo, *revs, **opts):
425 432 else:
426 433 if not sendmail:
427 434 sendmail = mail.connect(ui)
428 ui.status(_('Sending '), m['Subject'], ' ...\n')
435 ui.status(_('Sending '), subj, ' ...\n')
429 436 # Exim does not remove the Bcc field
430 437 del m['Bcc']
431 438 fp = cStringIO.StringIO()
General Comments 0
You need to be logged in to leave comments. Login now