jpayne@68: # Copyright (C) 2001-2006 Python Software Foundation jpayne@68: # Author: Barry Warsaw jpayne@68: # Contact: email-sig@python.org jpayne@68: jpayne@68: """email package exception classes.""" jpayne@68: jpayne@68: jpayne@68: class MessageError(Exception): jpayne@68: """Base class for errors in the email package.""" jpayne@68: jpayne@68: jpayne@68: class MessageParseError(MessageError): jpayne@68: """Base class for message parsing errors.""" jpayne@68: jpayne@68: jpayne@68: class HeaderParseError(MessageParseError): jpayne@68: """Error while parsing headers.""" jpayne@68: jpayne@68: jpayne@68: class BoundaryError(MessageParseError): jpayne@68: """Couldn't find terminating boundary.""" jpayne@68: jpayne@68: jpayne@68: class MultipartConversionError(MessageError, TypeError): jpayne@68: """Conversion to a multipart is prohibited.""" jpayne@68: jpayne@68: jpayne@68: class CharsetError(MessageError): jpayne@68: """An illegal charset was given.""" jpayne@68: jpayne@68: jpayne@68: # These are parsing defects which the parser was able to work around. jpayne@68: class MessageDefect(ValueError): jpayne@68: """Base class for a message defect.""" jpayne@68: jpayne@68: def __init__(self, line=None): jpayne@68: if line is not None: jpayne@68: super().__init__(line) jpayne@68: self.line = line jpayne@68: jpayne@68: class NoBoundaryInMultipartDefect(MessageDefect): jpayne@68: """A message claimed to be a multipart but had no boundary parameter.""" jpayne@68: jpayne@68: class StartBoundaryNotFoundDefect(MessageDefect): jpayne@68: """The claimed start boundary was never found.""" jpayne@68: jpayne@68: class CloseBoundaryNotFoundDefect(MessageDefect): jpayne@68: """A start boundary was found, but not the corresponding close boundary.""" jpayne@68: jpayne@68: class FirstHeaderLineIsContinuationDefect(MessageDefect): jpayne@68: """A message had a continuation line as its first header line.""" jpayne@68: jpayne@68: class MisplacedEnvelopeHeaderDefect(MessageDefect): jpayne@68: """A 'Unix-from' header was found in the middle of a header block.""" jpayne@68: jpayne@68: class MissingHeaderBodySeparatorDefect(MessageDefect): jpayne@68: """Found line with no leading whitespace and no colon before blank line.""" jpayne@68: # XXX: backward compatibility, just in case (it was never emitted). jpayne@68: MalformedHeaderDefect = MissingHeaderBodySeparatorDefect jpayne@68: jpayne@68: class MultipartInvariantViolationDefect(MessageDefect): jpayne@68: """A message claimed to be a multipart but no subparts were found.""" jpayne@68: jpayne@68: class InvalidMultipartContentTransferEncodingDefect(MessageDefect): jpayne@68: """An invalid content transfer encoding was set on the multipart itself.""" jpayne@68: jpayne@68: class UndecodableBytesDefect(MessageDefect): jpayne@68: """Header contained bytes that could not be decoded""" jpayne@68: jpayne@68: class InvalidBase64PaddingDefect(MessageDefect): jpayne@68: """base64 encoded sequence had an incorrect length""" jpayne@68: jpayne@68: class InvalidBase64CharactersDefect(MessageDefect): jpayne@68: """base64 encoded sequence had characters not in base64 alphabet""" jpayne@68: jpayne@68: class InvalidBase64LengthDefect(MessageDefect): jpayne@68: """base64 encoded sequence had invalid length (1 mod 4)""" jpayne@68: jpayne@68: # These errors are specific to header parsing. jpayne@68: jpayne@68: class HeaderDefect(MessageDefect): jpayne@68: """Base class for a header defect.""" jpayne@68: jpayne@68: def __init__(self, *args, **kw): jpayne@68: super().__init__(*args, **kw) jpayne@68: jpayne@68: class InvalidHeaderDefect(HeaderDefect): jpayne@68: """Header is not valid, message gives details.""" jpayne@68: jpayne@68: class HeaderMissingRequiredValue(HeaderDefect): jpayne@68: """A header that must have a value had none""" jpayne@68: jpayne@68: class NonPrintableDefect(HeaderDefect): jpayne@68: """ASCII characters outside the ascii-printable range found""" jpayne@68: jpayne@68: def __init__(self, non_printables): jpayne@68: super().__init__(non_printables) jpayne@68: self.non_printables = non_printables jpayne@68: jpayne@68: def __str__(self): jpayne@68: return ("the following ASCII non-printables found in header: " jpayne@68: "{}".format(self.non_printables)) jpayne@68: jpayne@68: class ObsoleteHeaderDefect(HeaderDefect): jpayne@68: """Header uses syntax declared obsolete by RFC 5322""" jpayne@68: jpayne@68: class NonASCIILocalPartDefect(HeaderDefect): jpayne@68: """local_part contains non-ASCII characters""" jpayne@68: # This defect only occurs during unicode parsing, not when jpayne@68: # parsing messages decoded from binary.