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