hgext/patchbomb.py
changeset 4027 2601ac9c54f0
parent 3468 0e68608bd11d
child 4029 9210fba03d16
child 4141 49d7a035235b
equal deleted inserted replaced
4026:8520a773a141 4027:2601ac9c54f0
    63 #
    63 #
    64 # That should be all.  Now your patchbomb is on its way out.
    64 # That should be all.  Now your patchbomb is on its way out.
    65 
    65 
    66 from mercurial.demandload import *
    66 from mercurial.demandload import *
    67 demandload(globals(), '''email.MIMEMultipart email.MIMEText email.Utils
    67 demandload(globals(), '''email.MIMEMultipart email.MIMEText email.Utils
    68                          mercurial:cmdutil,commands,hg,mail,ui,patch
    68                          mercurial:cmdutil,commands,hg,mail,ui,patch,util
    69                          os errno popen2 socket sys tempfile time''')
    69                          os errno popen2 socket sys tempfile''')
    70 from mercurial.i18n import gettext as _
    70 from mercurial.i18n import gettext as _
    71 from mercurial.node import *
    71 from mercurial.node import *
    72 
    72 
    73 try:
    73 try:
    74     # readline gives raw_input editing capabilities, but is not
    74     # readline gives raw_input editing capabilities, but is not
   163         if subj.endswith('.'): subj = subj[:-1]
   163         if subj.endswith('.'): subj = subj[:-1]
   164         msg['Subject'] = subj
   164         msg['Subject'] = subj
   165         msg['X-Mercurial-Node'] = node
   165         msg['X-Mercurial-Node'] = node
   166         return msg
   166         return msg
   167 
   167 
   168     start_time = int(time.time())
   168     start_time = util.makedate()
   169 
   169 
   170     def genmsgid(id):
   170     def genmsgid(id):
   171         return '<%s.%s@%s>' % (id[:20], start_time, socket.getfqdn())
   171         return '<%s.%s@%s>' % (id[:20], int(start_time[0]), socket.getfqdn())
   172 
   172 
   173     patches = []
   173     patches = []
   174 
   174 
   175     class exportee:
   175     class exportee:
   176         def __init__(self, container):
   176         def __init__(self, container):
   251     ui.write('\n')
   251     ui.write('\n')
   252 
   252 
   253     if not opts['test'] and not opts['mbox']:
   253     if not opts['test'] and not opts['mbox']:
   254         mailer = mail.connect(ui)
   254         mailer = mail.connect(ui)
   255     parent = None
   255     parent = None
   256 
       
   257     # Calculate UTC offset
       
   258     if time.daylight: offset = time.altzone
       
   259     else: offset = time.timezone
       
   260     if offset <= 0: sign, offset = '+', -offset
       
   261     else: sign = '-'
       
   262     offset = '%s%02d%02d' % (sign, offset / 3600, (offset % 3600) / 60)
       
   263 
   256 
   264     sender_addr = email.Utils.parseaddr(sender)[1]
   257     sender_addr = email.Utils.parseaddr(sender)[1]
   265     for m in msgs:
   258     for m in msgs:
   266         try:
   259         try:
   267             m['Message-Id'] = genmsgid(m['X-Mercurial-Node'])
   260             m['Message-Id'] = genmsgid(m['X-Mercurial-Node'])
   269             m['Message-Id'] = genmsgid('patchbomb')
   262             m['Message-Id'] = genmsgid('patchbomb')
   270         if parent:
   263         if parent:
   271             m['In-Reply-To'] = parent
   264             m['In-Reply-To'] = parent
   272         else:
   265         else:
   273             parent = m['Message-Id']
   266             parent = m['Message-Id']
   274         m['Date'] = time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(start_time)) + ' ' + offset
   267         m['Date'] = util.datestr(date=start_time,
   275 
   268                 format="%a, %d %b %Y %H:%M:%S", timezone=True)
   276         start_time += 1
   269 
       
   270         start_time = (start_time[0] + 1, start_time[1])
   277         m['From'] = sender
   271         m['From'] = sender
   278         m['To'] = ', '.join(to)
   272         m['To'] = ', '.join(to)
   279         if cc: m['Cc']  = ', '.join(cc)
   273         if cc: m['Cc']  = ', '.join(cc)
   280         if bcc: m['Bcc'] = ', '.join(bcc)
   274         if bcc: m['Bcc'] = ', '.join(bcc)
   281         if opts['test']:
   275         if opts['test']:
   289                     raise
   283                     raise
   290             fp.close()
   284             fp.close()
   291         elif opts['mbox']:
   285         elif opts['mbox']:
   292             ui.status('Writing ', m['Subject'], ' ...\n')
   286             ui.status('Writing ', m['Subject'], ' ...\n')
   293             fp = open(opts['mbox'], m.has_key('In-Reply-To') and 'ab+' or 'wb+')
   287             fp = open(opts['mbox'], m.has_key('In-Reply-To') and 'ab+' or 'wb+')
   294             date = time.asctime(time.localtime(start_time))
   288             date = util.datestr(date=start_time,
       
   289                     format='%a %b %d %H:%M:%S %Y', timezone=False)
   295             fp.write('From %s %s\n' % (sender_addr, date))
   290             fp.write('From %s %s\n' % (sender_addr, date))
   296             fp.write(m.as_string(0))
   291             fp.write(m.as_string(0))
   297             fp.write('\n\n')
   292             fp.write('\n\n')
   298             fp.close()
   293             fp.close()
   299         else:
   294         else: