211 msgfile = repo.opener('last-email.txt', 'wb') |
211 msgfile = repo.opener('last-email.txt', 'wb') |
212 msgfile.write(body) |
212 msgfile.write(body) |
213 msgfile.close() |
213 msgfile.close() |
214 return body |
214 return body |
215 |
215 |
|
216 def _getbundlemsgs(repo, sender, bundle, **opts): |
|
217 """Get the full email for sending a given bundle |
|
218 |
|
219 This function returns a list of "email" tuples (subject, content, None). |
|
220 The list is always one message long in that case. |
|
221 """ |
|
222 ui = repo.ui |
|
223 _charsets = mail._charsets(ui) |
|
224 subj = (opts.get('subject') |
|
225 or prompt(ui, 'Subject:', 'A bundle for your repository')) |
|
226 |
|
227 body = _getdescription(repo, '', sender, **opts) |
|
228 msg = email.MIMEMultipart.MIMEMultipart() |
|
229 if body: |
|
230 msg.attach(mail.mimeencode(ui, body, _charsets, opts.get('test'))) |
|
231 datapart = email.MIMEBase.MIMEBase('application', 'x-mercurial-bundle') |
|
232 datapart.set_payload(bundle) |
|
233 bundlename = '%s.hg' % opts.get('bundlename', 'bundle') |
|
234 datapart.add_header('Content-Disposition', 'attachment', |
|
235 filename=bundlename) |
|
236 email.Encoders.encode_base64(datapart) |
|
237 msg.attach(datapart) |
|
238 msg['Subject'] = mail.headencode(ui, subj, _charsets, opts.get('test')) |
|
239 return [(msg, subj, None)] |
|
240 |
216 emailopts = [ |
241 emailopts = [ |
217 ('', 'body', None, _('send patches as inline message text (default)')), |
242 ('', 'body', None, _('send patches as inline message text (default)')), |
218 ('a', 'attach', None, _('send patches as attachments')), |
243 ('a', 'attach', None, _('send patches as attachments')), |
219 ('i', 'inline', None, _('send patches as inline attachments')), |
244 ('i', 'inline', None, _('send patches as inline attachments')), |
220 ('', 'bcc', [], _('email addresses of blind carbon copy recipients')), |
245 ('', 'bcc', [], _('email addresses of blind carbon copy recipients')), |
441 msg = mail.mimeencode(ui, body, _charsets, opts.get('test')) |
466 msg = mail.mimeencode(ui, body, _charsets, opts.get('test')) |
442 msg['Subject'] = mail.headencode(ui, subj, _charsets, |
467 msg['Subject'] = mail.headencode(ui, subj, _charsets, |
443 opts.get('test')) |
468 opts.get('test')) |
444 return (msg, subj, diffstat) |
469 return (msg, subj, diffstat) |
445 |
470 |
446 def getbundlemsgs(bundle): |
|
447 subj = (opts.get('subject') |
|
448 or prompt(ui, 'Subject:', 'A bundle for your repository')) |
|
449 |
|
450 body = _getdescription(repo, '', sender, **opts) |
|
451 msg = email.MIMEMultipart.MIMEMultipart() |
|
452 if body: |
|
453 msg.attach(mail.mimeencode(ui, body, _charsets, opts.get('test'))) |
|
454 datapart = email.MIMEBase.MIMEBase('application', 'x-mercurial-bundle') |
|
455 datapart.set_payload(bundle) |
|
456 bundlename = '%s.hg' % opts.get('bundlename', 'bundle') |
|
457 datapart.add_header('Content-Disposition', 'attachment', |
|
458 filename=bundlename) |
|
459 email.Encoders.encode_base64(datapart) |
|
460 msg.attach(datapart) |
|
461 msg['Subject'] = mail.headencode(ui, subj, _charsets, opts.get('test')) |
|
462 return [(msg, subj, None)] |
|
463 |
|
464 sender = (opts.get('from') or ui.config('email', 'from') or |
471 sender = (opts.get('from') or ui.config('email', 'from') or |
465 ui.config('patchbomb', 'from') or |
472 ui.config('patchbomb', 'from') or |
466 prompt(ui, 'From', ui.username())) |
473 prompt(ui, 'From', ui.username())) |
467 |
474 |
468 if patches: |
475 if patches: |
469 msgs = getpatchmsgs(patches, opts.get('patchnames')) |
476 msgs = getpatchmsgs(patches, opts.get('patchnames')) |
470 elif bundle: |
477 elif bundle: |
471 msgs = getbundlemsgs(_getbundle(repo, dest, **opts)) |
478 bundledata = _getbundle(repo, dest, **opts) |
|
479 bundleopts = opts.copy() |
|
480 bundleopts.pop('bundle', None) # already processed |
|
481 msgs = _getbundlemsgs(repo, sender, bundledata, **bundleopts) |
472 else: |
482 else: |
473 msgs = getpatchmsgs(list(_getpatches(repo, revs, **opts))) |
483 msgs = getpatchmsgs(list(_getpatches(repo, revs, **opts))) |
474 |
484 |
475 showaddrs = [] |
485 showaddrs = [] |
476 |
486 |