summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Bruce Park <robert.park@canonical.com>2017-03-09 17:51:06 (GMT)
committerRobert Bruce Park <robert.park@canonical.com>2017-03-09 17:51:06 (GMT)
commit2dec3ded31b0b22ce05cb47286b1d61ac1fb66cb (patch)
tree8f5502dbaafe1ee900ee5e6799832f138ca0fe53
parent5f4c2e735dcb0fe891f96c068b185723679e1a27 (diff)
Backport EmailPolicy to Python 3.2
-rw-r--r--britney2/policies/email.py28
1 files changed, 15 insertions, 13 deletions
diff --git a/britney2/policies/email.py b/britney2/policies/email.py
index 6fcf757..e5be176 100644
--- a/britney2/policies/email.py
+++ b/britney2/policies/email.py
@@ -5,7 +5,6 @@ import smtplib
from urllib.parse import unquote
from collections import defaultdict
-from email.mime.text import MIMEText
from britney2.policies.rest import Rest
from britney2.policies.policy import BasePolicy, PolicyVerdict
@@ -22,7 +21,12 @@ BOTS = {
USER + 'katie',
}
-MESSAGE_BODY = """Hi,
+MESSAGE = """From: Ubuntu Release Team <noreply@canonical.com>
+To: {recipients}
+X-Proposed-Migration: notice
+Subject: [proposed-migration] {source_name} {version} stuck in {series}-proposed
+
+Hi,
{source_name} {version} needs attention.
@@ -160,20 +164,18 @@ class EmailPolicy(BasePolicy, Rest):
# don't update the cache file in dry run mode; we'll see all output each time
return PolicyVerdict.PASS
if stuck and not sent:
- msg = MIMEText(MESSAGE_BODY.format(**locals()))
- msg['X-Proposed-Migration'] = 'notice'
- msg['Subject'] = '[proposed-migration] {} {} stuck in {}-proposed'.format(source_name, version, series)
- msg['From'] = 'Ubuntu Release Team <noreply@canonical.com>'
emails = self.lp_get_emails(source_name, version)
if emails:
- msg['To'] = ', '.join(emails)
+ recipients = ', '.join(emails)
+ msg = MESSAGE.format(**locals())
try:
- with smtplib.SMTP('localhost') as smtp:
- self.log ("%s/%s stuck for %d days, emailing %s" %
- (source_name, version, age, ', '.join(emails)))
- smtp.send_message(msg)
- sent = True
- except ConnectionRefusedError as err:
+ self.log("%s/%s stuck for %d days, emailing %s" %
+ (source_name, version, age, recipients))
+ server = smtplib.SMTP('localhost')
+ server.sendmail('noreply@canonical.com', emails, msg)
+ server.quit()
+ sent = True
+ except smtplib.SMTPException as err:
self.log("Failed to send mail! Is SMTP server running?")
self.log(err)
self.emails_by_pkg[source_name][version] = sent