mailpipe|handler: add `complete` option to control Response mangling.
authorW. Trevor King <wking@tremily.us>
Sun, 2 Sep 2012 14:32:29 +0000 (10:32 -0400)
committerW. Trevor King <wking@tremily.us>
Sun, 2 Sep 2012 14:35:57 +0000 (10:35 -0400)
Some handlers may return their emails fully formed, and we won't want
to mess with them.

pygrader/handler/__init__.py
pygrader/mailpipe.py

index 70905f5605e6ab38810c4328fb26d913d05f8497..4b248eab4948c0f273f7c9625d2fb3e8ace4e3c7 100644 (file)
@@ -57,6 +57,7 @@ class Response (Exception):
     raise this exception.  The caller can catch it and mail the email
     (or take other appropriate action).
     """
     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
         super(Response, self).__init__()
         self.message = message
+        self.complete = complete
index fa01d988e090dc64e5144e2b7419ab7d8560195e..daae3e281a53f1e49ba7e8cfc667d2714387a5bd 100644 (file)
@@ -605,34 +605,35 @@ def mailpipe(basedir, course, stream=None, mailbox=None, input_=None,
                 respond(response)
         except _Response as response:
             if respond:
                 respond(response)
         except _Response as response:
             if respond:
-                author = course.robot
-                target = person
                 msg = response.message
                 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)
 
                 respond(msg)
 
-
 def _load_messages(course, stream, mailbox=None, input_=None, output=None,
                    continue_after_invalid_message=False,
                    trust_email_infrastructure=False, respond=None,
 def _load_messages(course, stream, mailbox=None, input_=None, output=None,
                    continue_after_invalid_message=False,
                    trust_email_infrastructure=False, respond=None,