#!/usr/bin/python # Copyright (C) 2001 Martin Michlmayr # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import os, sys, rfc822, time, re, string, StringIO, status maint = os.environ['LOCAL_PART'][4:] # skip the 'mia-' part mail = StringIO.StringIO(sys.stdin.read()) msg = rfc822.Message(mail) if string.find(msg.get('Subject'), "MIA-SUMMARY") >= 0: msg.rewindbody() summary = None id = None for line in msg.fp.readlines(): if summary is None: summary = re.search("MIA-Summary:\s*(.+)", line, re.I) if id is None: id = re.search("MIA-ID:\s*(\d+)", line, re.I) if (summary and id) is not None: status.write_status(maint, id.group(0), summary.group(0)) try: sendmail = os.popen('/usr/sbin/sendmail -oi -t', 'w') except IOError: print 'Cannot open sendmail' sys.exit(1) mail_message = """Return-Path: mia@qa.debian.org From: Martin Michlmayr and others To: mia@qa.debian.org Subject: thanks for the summary In-Reply-To: %s References: %s %s Thanks for adding the following summary for '%s': MIA-Summary: %s MIA-ID: %s """ % (maint, msg.get('Message-ID'), msg.get('References'), msg.get('Message-ID'), maint, summary.groups()[0], id.groups()[0]) sendmail.write(mail_message) sendmail.close() else: print "not ok: no summary or ID" sys.exit(1) else: try: mbox = open(status.origin + '/' + maint, 'a') except IOError: print "Cannot open mbox file for %s to append!" % maint sys.exit(1) mbox.write(mail.getvalue()) mbox.close() try: sendmail = os.popen('/usr/sbin/sendmail -oi -t', 'w') except IOError: print 'Cannot open sendmail' sys.exit(1) date = msg.getdate("Date") when = int(time.mktime(date)) mail_message = """Return-Path: mia@qa.debian.org From: Martin Michlmayr and others To: mia@qa.debian.org Reply-To: mia-%s@qa.debian.org """ % (maint, maint) summary = msg.get('X-MIA-Summary') if summary: status.write_status(maint, when, summary) mail_message = mail_message + """Subject: Added: %s Summary: %s """ % (msg.get('Subject'), summary) else: mail_message = mail_message + """Subject: MIA-SUMMARY %s In-Reply-To: %s References: %s %s Please respond with a summary and leave the ID intact. MIA-Summary: MIA-ID: %s Some possible summaries include: initial contact, willfix, willorphan, needs help, active, removed """ % (msg.get('Subject'), msg.get('Message-ID'), msg.get('References'),, msg.get('Message-ID'), when) mail_message = mail_message + """ ---------------------------------------------------------------- From: %s Date: %s """ % (msg.get('From'), msg.get('Date')) sendmail.write(mail_message) msg.rewindbody() for line in msg.fp.readlines(): sendmail.write(line) sendmail.close()