3 "Define assorted handlers for use in :py:mod:`~pygrader.mailpipe`."
5 import pgp_mime as _pgp_mime
8 class InvalidMessage (ValueError):
9 def __init__(self, message=None, error=None):
10 super(InvalidMessage, self).__init__(error)
11 self.message = message
15 """Return a short string identifying the invalid message.
17 if self.message is None:
19 subject = self.message['Subject']
20 if subject is not None:
22 message_id = self.message['Message-ID']
23 if message_id is not None:
28 class InsecureMessage (InvalidMessage):
29 def __init__(self, **kwargs):
30 if 'error' not in kwargs:
31 kwargs['error'] = 'insecure message'
32 super(InsecureMessage, self).__init__(**kwargs)
35 class UnsignedMessage (InsecureMessage):
36 def __init__(self, **kwargs):
37 if 'error' not in kwargs:
38 kwargs['error'] = 'unsigned message'
39 super(UnsignedMessage, self).__init__(**kwargs)
42 class InvalidSubjectMessage (InvalidMessage):
43 def __init__(self, subject=None, **kwargs):
44 if 'error' not in kwargs:
45 kwargs['error'] = 'invalid subject {!r}'.format(subject)
46 super(InvalidSubjectMessage, self).__init__(**kwargs)
47 self.subject = subject
50 class Response (Exception):
51 """Exception to bubble out email responses.
53 Rather than sending email responses themselves, handlers should
54 raise this exception. The caller can catch it and mail the email
55 (or take other appropriate action).
57 def __init__(self, message=None, complete=False):
58 super(Response, self).__init__()
59 self.message = message
60 self.complete = complete