#!/usr/bin/python # # Upload a series of patches to a webserver # # cheap hack by Matt Mackall 2003 (GPL) # # Patchset file format: # recipient1, recipient2.. # cc1, cc2 # series prefix # filename subject line # # If the first file is prefixed with !, it's a 0/n series description import sys, os, re, time, pwd, socket, random, smtplib patchset = sys.argv[1] files = [] desc = {} subject = {} base = 1 f = open(patchset) to = f.readline()[:-1] cc = f.readline()[:-1] prefix = f.readline()[:-1] for l in f.xreadlines(): split = l.index(' '); file, comment = l[:split], l[split+1:-1] files.append(file) desc[file] = comment if files[0][0] is "!": base = 0 f = files[0] files[0] = f[1:] desc[files[0]] = desc[f] try: fullname = os.environ['DEBFULLNAME'] except: fullname = pwd.getpwuid(os.getuid())[4].split(',')[0] try: email = os.environ['DEBEMAIL'] except: email = os.environ['LOGNAME']+'@'+socket.getfqdn() try: mailserver = os.environ['SMTPSERVER'] except: mailserver = 'localhost' From = "%s <%s>" % (fullname, email) threadfmt = "%%d.%08d@%s" % (random.randint(1,1000000000), email.split('@')[1]) print "From:", From print "To:", to print "Cc:", cc n = base for f in files: s = "[PATCH %d/%d] %s: %s" % (n, len(files)-(1-base), prefix, desc[f]) subject[f] = s print s n = n+1 print "proceed?" if sys.stdin.readline()[0] != "y": sys.exit() n = base server = smtplib.SMTP(mailserver) toaddrs = to.split(',')+cc.split(',') for f in files: print "Sending %s" % subject[f] msg = "From: %s\n" % From msg += "To: %s\n" % to msg += "X-PatchBomber: http://selenic.com/scripts/mailpatches\n" if cc: msg += "Cc: %s\n" % cc if f != files[0]: msg += "In-Reply-To: <%s>\n" % (threadfmt % n) n += 1 msg += "Message-Id: <%s>\n" % (threadfmt % n) msg+="Subject: %s\n\n" % subject[f] msg += open(f).read() server.sendmail(From, toaddrs, msg) time.sleep(.2)