From e5fc57de9b73f2520a3b1e994703abeb7720f62a Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Tue, 30 Dec 2008 01:26:32 -0600 Subject: Improve MIME-correctness of rawhide reports. --- scripts/buildrawhide | 2 +- scripts/send_rawhide_report | 107 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+), 1 deletion(-) create mode 100755 scripts/send_rawhide_report diff --git a/scripts/buildrawhide b/scripts/buildrawhide index d17a4c1..2aa94c9 100755 --- a/scripts/buildrawhide +++ b/scripts/buildrawhide @@ -53,6 +53,6 @@ sudo -u ftpsync /usr/bin/rsync $RSYNC_OPTS --exclude repodata/ /mnt/koji/mash/ra # repodata & cleanup sudo -u ftpsync /usr/bin/rsync $RSYNC_OPTS --delete --delete-after /mnt/koji/mash/rawhide-$DATE/development/ $DESTPATH if [ "$?" = "0" ]; then - cat /mnt/koji/mash/rawhide-$DATE/logs/start /mnt/koji/mash/rawhide-$DATE/logs/repodiff /mnt/koji/mash/rawhide-$DATE/logs/depcheck | mail -s 'rawhide report: '$DATE' changes' fedora-devel-list@redhat.com,fedora-test-list@redhat.com -- -f rawhide@fedoraproject.org -F "Rawhide Report" + send_rawhide_report --subject 'rawhide report: '$DATE' changes' /mnt/koji/mash/rawhide-$DATE/logs/start /mnt/koji/mash/rawhide-$DATE/logs/repodiff /mnt/koji/mash/rawhide-$DATE/logs/depcheck fi exit 0 diff --git a/scripts/send_rawhide_report b/scripts/send_rawhide_report new file mode 100755 index 0000000..19fe8dc --- /dev/null +++ b/scripts/send_rawhide_report @@ -0,0 +1,107 @@ +#!/usr/bin/python +# -*- mode: python; coding: utf-8 -*- + +# Copyright © 2008 Jeffrey C. Ollie + +# 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 3 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, see +# . + +import sys +import smtplib + +from optparse import OptionParser +from email.charset import Charset, QP +from email.message import Message +from email import utils +from email.header import Header +from email.generator import Generator +from cStringIO import StringIO + +default_recipients = ["Fedora Development List ", + "Fedora Test List "], + +default_sender = "Rawhide Report " + +utf8 = Charset('utf-8') +utf8.body_encoding = QP +utf8.header_encoding = QP + +parser = OptionParser() + +parser.add_option("--subject", + action = "store", + dest = "subject", + help = "subject for email") + +parser.add_option("--from", + action = "store", + dest = "sender", + default = default_sender, + help = "report will be from EMAIL", + metavar = "EMAIL") + +parser.add_option("--to", + action = "append", + dest = "recipients", + default = [], + help="add EMAIL to list of recipients", + metavar="EMAIL") + +(options, args) = parser.parse_args() + +if options.subject is None: + sys.stderr.write('Must specify subject!\n') + sys.exit(1) + +if len(options.recipients) == 0: + options.recipients = default_recipients + +subject = options.subject.decode('utf-8') + +sender_realname, sender_email = utils.parseaddr(options.sender.decode('utf-8')) + +sender = utils.formataddr((sender_realname, sender_email)) + +recipients_email_only = [] +recipients = [] + +for recipient in options.recipients: + recipient_realname, recipient_email = utils.parseaddr(recipient.decode('utf-8')) + recipients_email_only.append(recipient_email) + recipients.append(utils.formataddr((recipient_realname, recipient_email))) + +body_parts = [] + +for arg in args: + body_parts.append(file(arg, 'r').read().decode('utf-8', 'replace').encode('utf-8').encode('quoted-printable')) + +body = ''.join(body_parts) + +msg = Message() +msg.set_charset(utf8) +msg.set_payload(body) + +msg['From'] = Header(sender, utf8) +msg['To'] = Header(u', '.join(recipients), utf8) +msg['Subject'] = Header(subject, utf8) +msg['Date'] = Header(unicode(utils.formatdate()), utf8) + +msg_fp = StringIO() +msg_g = Generator(msg_fp, False) +msg_g.flatten(msg) + +smtp = smtplib.SMTP() +smtp.connect() +smtp.sendmail(sender_email, recipients_email_only, msg_fp.getvalue()) +smtp.close() -- cgit