Barry Warsaw | 40ef006 | 2006-03-18 15:41:53 +0000 | [diff] [blame] | 1 | # Copyright (C) 2001-2006 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 | |
Barry Warsaw | 40ef006 | 2006-03-18 15:41:53 +0000 | [diff] [blame] | 29 | class CharsetError(MessageError): |
| 30 | """An illegal charset was given.""" |
| 31 | |
| 32 | |
Barry Warsaw | 333e830 | 2004-05-09 03:26:07 +0000 | [diff] [blame] | 33 | |
| 34 | # These are parsing defects which the parser was able to work around. |
| 35 | class MessageDefect: |
| 36 | """Base class for a message defect.""" |
| 37 | |
| 38 | def __init__(self, line=None): |
| 39 | self.line = line |
| 40 | |
Barry Warsaw | bb11386 | 2004-10-03 03:16:19 +0000 | [diff] [blame] | 41 | class NoBoundaryInMultipartDefect(MessageDefect): |
Barry Warsaw | 333e830 | 2004-05-09 03:26:07 +0000 | [diff] [blame] | 42 | """A message claimed to be a multipart but had no boundary parameter.""" |
| 43 | |
Barry Warsaw | bb11386 | 2004-10-03 03:16:19 +0000 | [diff] [blame] | 44 | class StartBoundaryNotFoundDefect(MessageDefect): |
Barry Warsaw | 333e830 | 2004-05-09 03:26:07 +0000 | [diff] [blame] | 45 | """The claimed start boundary was never found.""" |
| 46 | |
Barry Warsaw | bb11386 | 2004-10-03 03:16:19 +0000 | [diff] [blame] | 47 | class FirstHeaderLineIsContinuationDefect(MessageDefect): |
Barry Warsaw | 333e830 | 2004-05-09 03:26:07 +0000 | [diff] [blame] | 48 | """A message had a continuation line as its first header line.""" |
| 49 | |
Barry Warsaw | bb11386 | 2004-10-03 03:16:19 +0000 | [diff] [blame] | 50 | class MisplacedEnvelopeHeaderDefect(MessageDefect): |
Barry Warsaw | 333e830 | 2004-05-09 03:26:07 +0000 | [diff] [blame] | 51 | """A 'Unix-from' header was found in the middle of a header block.""" |
| 52 | |
Barry Warsaw | bb11386 | 2004-10-03 03:16:19 +0000 | [diff] [blame] | 53 | class MalformedHeaderDefect(MessageDefect): |
| 54 | """Found a header that was missing a colon, or was otherwise malformed.""" |
| 55 | |
| 56 | class MultipartInvariantViolationDefect(MessageDefect): |
| 57 | """A message claimed to be a multipart but no subparts were found.""" |