jpayne@69
|
1 # Copyright (C) 2001-2006 Python Software Foundation
|
jpayne@69
|
2 # Author: Barry Warsaw
|
jpayne@69
|
3 # Contact: email-sig@python.org
|
jpayne@69
|
4
|
jpayne@69
|
5 """email package exception classes."""
|
jpayne@69
|
6
|
jpayne@69
|
7
|
jpayne@69
|
8 class MessageError(Exception):
|
jpayne@69
|
9 """Base class for errors in the email package."""
|
jpayne@69
|
10
|
jpayne@69
|
11
|
jpayne@69
|
12 class MessageParseError(MessageError):
|
jpayne@69
|
13 """Base class for message parsing errors."""
|
jpayne@69
|
14
|
jpayne@69
|
15
|
jpayne@69
|
16 class HeaderParseError(MessageParseError):
|
jpayne@69
|
17 """Error while parsing headers."""
|
jpayne@69
|
18
|
jpayne@69
|
19
|
jpayne@69
|
20 class BoundaryError(MessageParseError):
|
jpayne@69
|
21 """Couldn't find terminating boundary."""
|
jpayne@69
|
22
|
jpayne@69
|
23
|
jpayne@69
|
24 class MultipartConversionError(MessageError, TypeError):
|
jpayne@69
|
25 """Conversion to a multipart is prohibited."""
|
jpayne@69
|
26
|
jpayne@69
|
27
|
jpayne@69
|
28 class CharsetError(MessageError):
|
jpayne@69
|
29 """An illegal charset was given."""
|
jpayne@69
|
30
|
jpayne@69
|
31
|
jpayne@69
|
32 # These are parsing defects which the parser was able to work around.
|
jpayne@69
|
33 class MessageDefect(ValueError):
|
jpayne@69
|
34 """Base class for a message defect."""
|
jpayne@69
|
35
|
jpayne@69
|
36 def __init__(self, line=None):
|
jpayne@69
|
37 if line is not None:
|
jpayne@69
|
38 super().__init__(line)
|
jpayne@69
|
39 self.line = line
|
jpayne@69
|
40
|
jpayne@69
|
41 class NoBoundaryInMultipartDefect(MessageDefect):
|
jpayne@69
|
42 """A message claimed to be a multipart but had no boundary parameter."""
|
jpayne@69
|
43
|
jpayne@69
|
44 class StartBoundaryNotFoundDefect(MessageDefect):
|
jpayne@69
|
45 """The claimed start boundary was never found."""
|
jpayne@69
|
46
|
jpayne@69
|
47 class CloseBoundaryNotFoundDefect(MessageDefect):
|
jpayne@69
|
48 """A start boundary was found, but not the corresponding close boundary."""
|
jpayne@69
|
49
|
jpayne@69
|
50 class FirstHeaderLineIsContinuationDefect(MessageDefect):
|
jpayne@69
|
51 """A message had a continuation line as its first header line."""
|
jpayne@69
|
52
|
jpayne@69
|
53 class MisplacedEnvelopeHeaderDefect(MessageDefect):
|
jpayne@69
|
54 """A 'Unix-from' header was found in the middle of a header block."""
|
jpayne@69
|
55
|
jpayne@69
|
56 class MissingHeaderBodySeparatorDefect(MessageDefect):
|
jpayne@69
|
57 """Found line with no leading whitespace and no colon before blank line."""
|
jpayne@69
|
58 # XXX: backward compatibility, just in case (it was never emitted).
|
jpayne@69
|
59 MalformedHeaderDefect = MissingHeaderBodySeparatorDefect
|
jpayne@69
|
60
|
jpayne@69
|
61 class MultipartInvariantViolationDefect(MessageDefect):
|
jpayne@69
|
62 """A message claimed to be a multipart but no subparts were found."""
|
jpayne@69
|
63
|
jpayne@69
|
64 class InvalidMultipartContentTransferEncodingDefect(MessageDefect):
|
jpayne@69
|
65 """An invalid content transfer encoding was set on the multipart itself."""
|
jpayne@69
|
66
|
jpayne@69
|
67 class UndecodableBytesDefect(MessageDefect):
|
jpayne@69
|
68 """Header contained bytes that could not be decoded"""
|
jpayne@69
|
69
|
jpayne@69
|
70 class InvalidBase64PaddingDefect(MessageDefect):
|
jpayne@69
|
71 """base64 encoded sequence had an incorrect length"""
|
jpayne@69
|
72
|
jpayne@69
|
73 class InvalidBase64CharactersDefect(MessageDefect):
|
jpayne@69
|
74 """base64 encoded sequence had characters not in base64 alphabet"""
|
jpayne@69
|
75
|
jpayne@69
|
76 class InvalidBase64LengthDefect(MessageDefect):
|
jpayne@69
|
77 """base64 encoded sequence had invalid length (1 mod 4)"""
|
jpayne@69
|
78
|
jpayne@69
|
79 # These errors are specific to header parsing.
|
jpayne@69
|
80
|
jpayne@69
|
81 class HeaderDefect(MessageDefect):
|
jpayne@69
|
82 """Base class for a header defect."""
|
jpayne@69
|
83
|
jpayne@69
|
84 def __init__(self, *args, **kw):
|
jpayne@69
|
85 super().__init__(*args, **kw)
|
jpayne@69
|
86
|
jpayne@69
|
87 class InvalidHeaderDefect(HeaderDefect):
|
jpayne@69
|
88 """Header is not valid, message gives details."""
|
jpayne@69
|
89
|
jpayne@69
|
90 class HeaderMissingRequiredValue(HeaderDefect):
|
jpayne@69
|
91 """A header that must have a value had none"""
|
jpayne@69
|
92
|
jpayne@69
|
93 class NonPrintableDefect(HeaderDefect):
|
jpayne@69
|
94 """ASCII characters outside the ascii-printable range found"""
|
jpayne@69
|
95
|
jpayne@69
|
96 def __init__(self, non_printables):
|
jpayne@69
|
97 super().__init__(non_printables)
|
jpayne@69
|
98 self.non_printables = non_printables
|
jpayne@69
|
99
|
jpayne@69
|
100 def __str__(self):
|
jpayne@69
|
101 return ("the following ASCII non-printables found in header: "
|
jpayne@69
|
102 "{}".format(self.non_printables))
|
jpayne@69
|
103
|
jpayne@69
|
104 class ObsoleteHeaderDefect(HeaderDefect):
|
jpayne@69
|
105 """Header uses syntax declared obsolete by RFC 5322"""
|
jpayne@69
|
106
|
jpayne@69
|
107 class NonASCIILocalPartDefect(HeaderDefect):
|
jpayne@69
|
108 """local_part contains non-ASCII characters"""
|
jpayne@69
|
109 # This defect only occurs during unicode parsing, not when
|
jpayne@69
|
110 # parsing messages decoded from binary.
|