comparison hgext/patchbomb.py @ 15559:1830d0cc4bc1

patchbomb: minor refactoring of mbox functionality, preparing for move This allows reuse of the mbox functionality but causes minor changes in the patchbomb console output when writing to a mbox.
author Mads Kiilerich <mads@kiilerich.com>
date Wed, 23 Nov 2011 02:09:38 +0100
parents 9ec9dd8d1b24
children cc58c228503e
comparison
equal deleted inserted replaced
15558:c6b600d2348c 15559:1830d0cc4bc1
531 if inst.errno != errno.EPIPE: 531 if inst.errno != errno.EPIPE:
532 raise 532 raise
533 if fp is not ui: 533 if fp is not ui:
534 fp.close() 534 fp.close()
535 elif mbox: 535 elif mbox:
536 ui.status(_('Writing '), subj, ' ...\n') 536 ui.status(_('Sending '), subj, ' ...\n')
537 ui.progress(_('writing'), i, item=subj, total=len(msgs)) 537 ui.progress(_('sending'), i, item=subj, total=len(msgs))
538 fp = open(mbox, 'In-Reply-To' in m and 'ab+' or 'wb+') 538 fp = open(mbox, i > 0 and 'ab+' or 'wb+')
539 generator = email.Generator.Generator(fp, mangle_from_=True) 539 generator = email.Generator.Generator(fp, mangle_from_=True)
540 # Should be time.asctime(), but Windows prints 2-characters day 540 # Should be time.asctime(), but Windows prints 2-characters day
541 # of month instead of one. Make them print the same thing. 541 # of month instead of one. Make them print the same thing.
542 date = time.strftime('%a %b %d %H:%M:%S %Y', 542 date = time.strftime('%a %b %d %H:%M:%S %Y', time.localtime())
543 time.localtime(start_time[0]))
544 fp.write('From %s %s\n' % (sender_addr, date)) 543 fp.write('From %s %s\n' % (sender_addr, date))
545 generator.flatten(m, 0) 544 generator.flatten(m, 0)
546 fp.write('\n\n') 545 fp.write('\n\n')
547 fp.close() 546 fp.close()
548 else: 547 else:
553 # Exim does not remove the Bcc field 552 # Exim does not remove the Bcc field
554 del m['Bcc'] 553 del m['Bcc']
555 fp = cStringIO.StringIO() 554 fp = cStringIO.StringIO()
556 generator = email.Generator.Generator(fp, mangle_from_=False) 555 generator = email.Generator.Generator(fp, mangle_from_=False)
557 generator.flatten(m, 0) 556 generator.flatten(m, 0)
558 sendmail(sender, to + bcc + cc, fp.getvalue()) 557 sendmail(sender_addr, to + bcc + cc, fp.getvalue())
559 558
560 ui.progress(_('writing'), None) 559 ui.progress(_('writing'), None)
561 ui.progress(_('sending'), None) 560 ui.progress(_('sending'), None)