From a6b87d3c2818747fa9caadc9eb6c5ea75de002c6 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 2 Sep 2012 10:32:29 -0400 Subject: [PATCH] mailpipe|handler: add `complete` option to control Response mangling. Some handlers may return their emails fully formed, and we won't want to mess with them. --- pygrader/handler/__init__.py | 3 ++- pygrader/mailpipe.py | 51 ++++++++++++++++++------------------ 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/pygrader/handler/__init__.py b/pygrader/handler/__init__.py index 70905f5..4b248ea 100644 --- a/pygrader/handler/__init__.py +++ b/pygrader/handler/__init__.py @@ -57,6 +57,7 @@ class Response (Exception): raise this exception. The caller can catch it and mail the email (or take other appropriate action). """ - def __init__(self, message=None): + def __init__(self, message=None, complete=False): super(Response, self).__init__() self.message = message + self.complete = complete diff --git a/pygrader/mailpipe.py b/pygrader/mailpipe.py index fa01d98..daae3e2 100644 --- a/pygrader/mailpipe.py +++ b/pygrader/mailpipe.py @@ -605,34 +605,35 @@ def mailpipe(basedir, course, stream=None, mailbox=None, input_=None, respond(response) except _Response as response: if respond: - author = course.robot - target = person msg = response.message - if isinstance(response.message, _MIMEText): - # Manipulate body (based on pgp_mime.append_text) - original_encoding = msg.get_charset().input_charset - original_payload = str( - msg.get_payload(decode=True), original_encoding) - new_payload = ( - '{},\n\n' - '{}\n\n' - 'Yours,\n' - '{}\n').format( - target.alias(), original_payload, author.alias()) - new_encoding = _pgp_mime.guess_encoding(new_payload) - if msg.get('content-transfer-encoding', None): - # clear CTE so set_payload will set it properly - del msg['content-transfer-encoding'] - msg.set_payload(new_payload, new_encoding) - subject = msg['Subject'] - assert subject is not None, msg - del msg['Subject'] - msg = _construct_email( - author=author, targets=[person], subject=subject, - message=msg) + if not response.complete: + author = course.robot + target = person + msg = response.message + if isinstance(response.message, _MIMEText): + # Manipulate body (based on pgp_mime.append_text) + original_encoding = msg.get_charset().input_charset + original_payload = str( + msg.get_payload(decode=True), original_encoding) + new_payload = ( + '{},\n\n' + '{}\n\n' + 'Yours,\n' + '{}\n').format( + target.alias(), original_payload, author.alias()) + new_encoding = _pgp_mime.guess_encoding(new_payload) + if msg.get('content-transfer-encoding', None): + # clear CTE so set_payload will set it properly + del msg['content-transfer-encoding'] + msg.set_payload(new_payload, new_encoding) + subject = msg['Subject'] + assert subject is not None, msg + del msg['Subject'] + msg = _construct_email( + author=author, targets=[person], subject=subject, + message=msg) respond(msg) - def _load_messages(course, stream, mailbox=None, input_=None, output=None, continue_after_invalid_message=False, trust_email_infrastructure=False, respond=None, -- 2.26.2