blob: fae872439edc66d6559250ec63cb049f6be70b6f [file] [log] [blame]
Guido van Rossum8b3febe2007-08-30 01:15:14 +00001# 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 Rossum8b3febe2007-08-30 01:15:14 +00007__all__ = [
8 'base64mime',
9 'charset',
10 'encoders',
11 'errors',
R David Murray1b6c7242012-03-16 22:43:05 -040012 'feedparser',
Guido van Rossum8b3febe2007-08-30 01:15:14 +000013 'generator',
14 'header',
15 'iterators',
16 'message',
17 'message_from_file',
R. David Murray96fd54e2010-10-08 15:55:28 +000018 'message_from_binary_file',
Guido van Rossum8b3febe2007-08-30 01:15:14 +000019 'message_from_string',
R. David Murray96fd54e2010-10-08 15:55:28 +000020 'message_from_bytes',
Guido van Rossum8b3febe2007-08-30 01:15:14 +000021 '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.
32def 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 Murray96fd54e2010-10-08 15:55:28 +000040def 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 Rossum8b3febe2007-08-30 01:15:14 +000047
48def 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 Murray96fd54e2010-10-08 15:55:28 +000055
56def 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 Stinner0c4cc552011-01-25 23:15:47 +000061 from email.parser import BytesParser
R. David Murray96fd54e2010-10-08 15:55:28 +000062 return BytesParser(*args, **kws).parse(fp)