Barry Warsaw | 333e830 | 2004-05-09 03:26:07 +0000 | [diff] [blame] | 1 | # Copyright (C) 2001-2004 Python Software Foundation |
Barry Warsaw | bb11386 | 2004-10-03 03:16:19 +0000 | [diff] [blame] | 2 | # Author: Barry Warsaw |
| 3 | # Contact: email-sig@python.org |
Barry Warsaw | ba92580 | 2001-09-23 03:17:28 +0000 | [diff] [blame] | 4 | |
Barry Warsaw | 333e830 | 2004-05-09 03:26:07 +0000 | [diff] [blame] | 5 | """email package exception classes.""" |
Barry Warsaw | ba92580 | 2001-09-23 03:17:28 +0000 | [diff] [blame] | 6 | |
| 7 | |
Barry Warsaw | e968ead | 2001-10-04 17:05:11 +0000 | [diff] [blame] | 8 | |
Barry Warsaw | ba92580 | 2001-09-23 03:17:28 +0000 | [diff] [blame] | 9 | class MessageError(Exception): |
Barry Warsaw | c5d1c04 | 2002-06-01 05:45:37 +0000 | [diff] [blame] | 10 | """Base class for errors in the email package.""" |
Barry Warsaw | ba92580 | 2001-09-23 03:17:28 +0000 | [diff] [blame] | 11 | |
| 12 | |
| 13 | class MessageParseError(MessageError): |
| 14 | """Base class for message parsing errors.""" |
| 15 | |
| 16 | |
| 17 | class HeaderParseError(MessageParseError): |
| 18 | """Error while parsing headers.""" |
| 19 | |
| 20 | |
| 21 | class BoundaryError(MessageParseError): |
| 22 | """Couldn't find terminating boundary.""" |
| 23 | |
| 24 | |
| 25 | class MultipartConversionError(MessageError, TypeError): |
| 26 | """Conversion to a multipart is prohibited.""" |
Barry Warsaw | 333e830 | 2004-05-09 03:26:07 +0000 | [diff] [blame] | 27 | |
| 28 | |
| 29 | |
| 30 | # These are parsing defects which the parser was able to work around. |
| 31 | class MessageDefect: |
| 32 | """Base class for a message defect.""" |
| 33 | |
| 34 | def __init__(self, line=None): |
| 35 | self.line = line |
| 36 | |
Barry Warsaw | bb11386 | 2004-10-03 03:16:19 +0000 | [diff] [blame] | 37 | class NoBoundaryInMultipartDefect(MessageDefect): |
Barry Warsaw | 333e830 | 2004-05-09 03:26:07 +0000 | [diff] [blame] | 38 | """A message claimed to be a multipart but had no boundary parameter.""" |
| 39 | |
Barry Warsaw | bb11386 | 2004-10-03 03:16:19 +0000 | [diff] [blame] | 40 | class StartBoundaryNotFoundDefect(MessageDefect): |
Barry Warsaw | 333e830 | 2004-05-09 03:26:07 +0000 | [diff] [blame] | 41 | """The claimed start boundary was never found.""" |
| 42 | |
Barry Warsaw | bb11386 | 2004-10-03 03:16:19 +0000 | [diff] [blame] | 43 | class FirstHeaderLineIsContinuationDefect(MessageDefect): |
Barry Warsaw | 333e830 | 2004-05-09 03:26:07 +0000 | [diff] [blame] | 44 | """A message had a continuation line as its first header line.""" |
| 45 | |
Barry Warsaw | bb11386 | 2004-10-03 03:16:19 +0000 | [diff] [blame] | 46 | class MisplacedEnvelopeHeaderDefect(MessageDefect): |
Barry Warsaw | 333e830 | 2004-05-09 03:26:07 +0000 | [diff] [blame] | 47 | """A 'Unix-from' header was found in the middle of a header block.""" |
| 48 | |
Barry Warsaw | bb11386 | 2004-10-03 03:16:19 +0000 | [diff] [blame] | 49 | class MalformedHeaderDefect(MessageDefect): |
| 50 | """Found a header that was missing a colon, or was otherwise malformed.""" |
| 51 | |
| 52 | class MultipartInvariantViolationDefect(MessageDefect): |
| 53 | """A message claimed to be a multipart but no subparts were found.""" |