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)
47 super(InvalidSubjectMessage, self).__init__(**kwargs)
49 raise ValueError(kwargs)
50 self.subject = subject
53 class Response (Exception):
54 """Exception to bubble out email responses.
56 Rather than sending email responses themselves, handlers should
57 raise this exception. The caller can catch it and mail the email
58 (or take other appropriate action).
60 def __init__(self, message=None):
61 super(Response, self).__init__()
62 self.message = message