Guido van Rossum | 8b3febe | 2007-08-30 01:15:14 +0000 | [diff] [blame] | 1 | # Copyright (C) 2001-2007 Python Software Foundation |
| 2 | # Author: Barry Warsaw |
| 3 | # Contact: email-sig@python.org |
| 4 | |
| 5 | """A package for parsing, handling, and generating email messages.""" |
| 6 | |
Guido van Rossum | 8b3febe | 2007-08-30 01:15:14 +0000 | [diff] [blame] | 7 | __all__ = [ |
| 8 | 'base64mime', |
| 9 | 'charset', |
| 10 | 'encoders', |
| 11 | 'errors', |
R David Murray | 1b6c724 | 2012-03-16 22:43:05 -0400 | [diff] [blame] | 12 | 'feedparser', |
Guido van Rossum | 8b3febe | 2007-08-30 01:15:14 +0000 | [diff] [blame] | 13 | 'generator', |
| 14 | 'header', |
| 15 | 'iterators', |
| 16 | 'message', |
| 17 | 'message_from_file', |
R. David Murray | 96fd54e | 2010-10-08 15:55:28 +0000 | [diff] [blame] | 18 | 'message_from_binary_file', |
Guido van Rossum | 8b3febe | 2007-08-30 01:15:14 +0000 | [diff] [blame] | 19 | 'message_from_string', |
R. David Murray | 96fd54e | 2010-10-08 15:55:28 +0000 | [diff] [blame] | 20 | 'message_from_bytes', |
Guido van Rossum | 8b3febe | 2007-08-30 01:15:14 +0000 | [diff] [blame] | 21 | 'mime', |
| 22 | 'parser', |
| 23 | 'quoprimime', |
| 24 | 'utils', |
| 25 | ] |
| 26 | |
| 27 | |
| 28 | |
| 29 | # Some convenience routines. Don't import Parser and Message as side-effects |
| 30 | # of importing email since those cascadingly import most of the rest of the |
| 31 | # email package. |
| 32 | def message_from_string(s, *args, **kws): |
| 33 | """Parse a string into a Message object model. |
| 34 | |
| 35 | Optional _class and strict are passed to the Parser constructor. |
| 36 | """ |
| 37 | from email.parser import Parser |
| 38 | return Parser(*args, **kws).parsestr(s) |
| 39 | |
R. David Murray | 96fd54e | 2010-10-08 15:55:28 +0000 | [diff] [blame] | 40 | def message_from_bytes(s, *args, **kws): |
| 41 | """Parse a bytes string into a Message object model. |
| 42 | |
| 43 | Optional _class and strict are passed to the Parser constructor. |
| 44 | """ |
| 45 | from email.parser import BytesParser |
| 46 | return BytesParser(*args, **kws).parsebytes(s) |
Guido van Rossum | 8b3febe | 2007-08-30 01:15:14 +0000 | [diff] [blame] | 47 | |
| 48 | def message_from_file(fp, *args, **kws): |
| 49 | """Read a file and parse its contents into a Message object model. |
| 50 | |
| 51 | Optional _class and strict are passed to the Parser constructor. |
| 52 | """ |
| 53 | from email.parser import Parser |
| 54 | return Parser(*args, **kws).parse(fp) |
R. David Murray | 96fd54e | 2010-10-08 15:55:28 +0000 | [diff] [blame] | 55 | |
| 56 | def message_from_binary_file(fp, *args, **kws): |
| 57 | """Read a binary file and parse its contents into a Message object model. |
| 58 | |
| 59 | Optional _class and strict are passed to the Parser constructor. |
| 60 | """ |
Victor Stinner | 0c4cc55 | 2011-01-25 23:15:47 +0000 | [diff] [blame] | 61 | from email.parser import BytesParser |
R. David Murray | 96fd54e | 2010-10-08 15:55:28 +0000 | [diff] [blame] | 62 | return BytesParser(*args, **kws).parse(fp) |