email.errors: Exception and Defect classes

Source code:Lib/email/errors.py


The following exception classes are defined in theemail.errors module:

exceptionemail.errors.MessageError

This is the base class for all exceptions that theemail package canraise. It is derived from the standardException class and defines noadditional methods.

exceptionemail.errors.MessageParseError

This is the base class for exceptions raised by theParser class. It is derived fromMessageError. This class is also used internally by the parser usedbyheaderregistry.

exceptionemail.errors.HeaderParseError

Raised under some error conditions when parsing theRFC 5322 headers of amessage, this class is derived fromMessageParseError. Theset_boundary() method will raise thiserror if the content type is unknown when the method is called.Header may raise this error for certain base64decoding errors, and when an attempt is made to create a header that appearsto contain an embedded header (that is, there is what is supposed to be acontinuation line that has no leading whitespace and looks like a header).

exceptionemail.errors.BoundaryError

Deprecated and no longer used.

exceptionemail.errors.MultipartConversionError

Raised if theattach() method is calledon an instance of a class derived fromMIMENonMultipart (e.g.MIMEImage).MultipartConversionError multiplyinherits fromMessageError and the built-inTypeError.

exceptionemail.errors.HeaderWriteError

Raised when an error occurs when thegenerator outputsheaders.

exceptionemail.errors.MessageDefect

This is the base class for all defects found when parsing email messages.It is derived fromValueError.

exceptionemail.errors.HeaderDefect

This is the base class for all defects found when parsing email headers.It is derived fromMessageDefect.

Here is the list of the defects that theFeedParsercan find while parsing messages. Note that the defects are added to the messagewhere the problem was found, so for example, if a message nested inside amultipart/alternative had a malformed header, that nested messageobject would have a defect, but the containing messages would not.

All defect classes are subclassed fromemail.errors.MessageDefect.

exceptionemail.errors.NoBoundaryInMultipartDefect

A message claimed to be a multipart, but had noboundaryparameter.

exceptionemail.errors.StartBoundaryNotFoundDefect

The start boundary claimed in theContent-Type header wasnever found.

exceptionemail.errors.CloseBoundaryNotFoundDefect

A start boundary was found, but no corresponding close boundary was everfound.

Added in version 3.3.

exceptionemail.errors.FirstHeaderLineIsContinuationDefect

The message had a continuation line as its first header line.

exceptionemail.errors.MisplacedEnvelopeHeaderDefect

A “Unix From” header was found in the middle of a header block.

exceptionemail.errors.MissingHeaderBodySeparatorDefect

A line was found while parsing headers that had no leading white space butcontained no ‘:’. Parsing continues assuming that the line represents thefirst line of the body.

Added in version 3.3.

exceptionemail.errors.MalformedHeaderDefect

A header was found that was missing a colon, or was otherwise malformed.

Deprecated since version 3.3:This defect has not been used for several Python versions.

exceptionemail.errors.MultipartInvariantViolationDefect

A message claimed to be amultipart, but no subparts were found.Note that when a message has this defect, itsis_multipart() method may returnFalseeven though its content type claims to bemultipart.

exceptionemail.errors.InvalidBase64PaddingDefect

When decoding a block of base64 encoded bytes, the padding was not correct.Enough padding is added to perform the decode, but the resulting decodedbytes may be invalid.

exceptionemail.errors.InvalidBase64CharactersDefect

When decoding a block of base64 encoded bytes, characters outside the base64alphabet were encountered. The characters are ignored, but the resultingdecoded bytes may be invalid.

exceptionemail.errors.InvalidBase64LengthDefect

When decoding a block of base64 encoded bytes, the number of non-paddingbase64 characters was invalid (1 more than a multiple of 4). The encodedblock was kept as-is.

exceptionemail.errors.InvalidDateDefect

When decoding an invalid or unparsable date field. The original value iskept as-is.