hgext/patchbomb.py
changeset 2679 f1de91be1d87
parent 2443 bd9c39e8f38b
child 2705 030d0abdf91b
equal deleted inserted replaced
2678:a781df9b5faa 2679:f1de91be1d87
    36 #
    36 #
    37 # [email]
    37 # [email]
    38 # from = My Name <my@email>
    38 # from = My Name <my@email>
    39 # to = recipient1, recipient2, ...
    39 # to = recipient1, recipient2, ...
    40 # cc = cc1, cc2, ...
    40 # cc = cc1, cc2, ...
       
    41 # bcc = bcc1, bcc2, ...
    41 
    42 
    42 from mercurial.demandload import *
    43 from mercurial.demandload import *
    43 demandload(globals(), '''email.MIMEMultipart email.MIMEText email.Utils
    44 demandload(globals(), '''email.MIMEMultipart email.MIMEText email.Utils
    44                          mercurial:commands,hg,ui
    45                          mercurial:commands,hg,ui
    45                          os errno popen2 socket sys tempfile time''')
    46                          os errno popen2 socket sys tempfile time''')
   183                               prompt(prpt, default = default)).split(',')
   184                               prompt(prpt, default = default)).split(',')
   184         return [a.strip() for a in addrs if a.strip()]
   185         return [a.strip() for a in addrs if a.strip()]
   185     to = getaddrs('to', 'To')
   186     to = getaddrs('to', 'To')
   186     cc = getaddrs('cc', 'Cc', '')
   187     cc = getaddrs('cc', 'Cc', '')
   187 
   188 
       
   189     bcc = opts['bcc'] or (ui.config('email', 'bcc') or
       
   190                           ui.config('patchbomb', 'bcc') or '').split(',')
       
   191     bcc = [a.strip() for a in bcc if a.strip()]
       
   192 
   188     if len(patches) > 1:
   193     if len(patches) > 1:
   189         ui.write(_('\nWrite the introductory message for the patch series.\n\n'))
   194         ui.write(_('\nWrite the introductory message for the patch series.\n\n'))
   190 
   195 
   191         msg = email.MIMEMultipart.MIMEMultipart()
   196         msg = email.MIMEMultipart.MIMEMultipart()
   192         msg['Subject'] = '[PATCH 0 of %d] %s' % (
   197         msg['Subject'] = '[PATCH 0 of %d] %s' % (
   238         m['Date'] = time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(start_time)) + ' ' + offset
   243         m['Date'] = time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(start_time)) + ' ' + offset
   239 
   244 
   240         start_time += 1
   245         start_time += 1
   241         m['From'] = sender
   246         m['From'] = sender
   242         m['To'] = ', '.join(to)
   247         m['To'] = ', '.join(to)
   243         if cc: m['Cc'] = ', '.join(cc)
   248         if cc: m['Cc']  = ', '.join(cc)
       
   249         if bcc: m['Bcc'] = ', '.join(bcc)
   244         if opts['test']:
   250         if opts['test']:
   245             ui.status('Displaying ', m['Subject'], ' ...\n')
   251             ui.status('Displaying ', m['Subject'], ' ...\n')
   246             fp = os.popen(os.getenv('PAGER', 'more'), 'w')
   252             fp = os.popen(os.getenv('PAGER', 'more'), 'w')
   247             try:
   253             try:
   248                 fp.write(m.as_string(0))
   254                 fp.write(m.as_string(0))
   259             fp.write(m.as_string(0))
   265             fp.write(m.as_string(0))
   260             fp.write('\n\n')
   266             fp.write('\n\n')
   261             fp.close()
   267             fp.close()
   262         else:
   268         else:
   263             ui.status('Sending ', m['Subject'], ' ...\n')
   269             ui.status('Sending ', m['Subject'], ' ...\n')
   264             mail.sendmail(sender, to + cc, m.as_string(0))
   270             mail.sendmail(sender, to + bcc + cc, m.as_string(0))
   265 
   271 
   266 cmdtable = {
   272 cmdtable = {
   267     'email':
   273     'email':
   268     (patchbomb,
   274     (patchbomb,
   269      [('c', 'cc', [], 'email addresses of copy recipients'),
   275      [('', 'bcc', [], 'email addresses of blind copy recipients'),
       
   276       ('c', 'cc', [], 'email addresses of copy recipients'),
   270       ('d', 'diffstat', None, 'add diffstat output to messages'),
   277       ('d', 'diffstat', None, 'add diffstat output to messages'),
   271       ('f', 'from', '', 'email address of sender'),
   278       ('f', 'from', '', 'email address of sender'),
   272       ('', 'plain', None, 'omit hg patch header'),
   279       ('', 'plain', None, 'omit hg patch header'),
   273       ('n', 'test', None, 'print messages that would be sent'),
   280       ('n', 'test', None, 'print messages that would be sent'),
   274       ('m', 'mbox', '', 'write messages to mbox file instead of sending them'),
   281       ('m', 'mbox', '', 'write messages to mbox file instead of sending them'),