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 
   7 __version__ = '5.1.0'
   8 
   9 __all__ = [
  10     'base64mime',
  11     'charset',
  12     'encoders',
  13     'errors',
  14     'feedparser',
  15     'generator',
  16     'header',
  17     'iterators',
  18     'message',
  19     'message_from_file',
  20     'message_from_binary_file',
  21     'message_from_string',
  22     'message_from_bytes',
  23     'mime',
  24     'parser',
  25     'quoprimime',
  26     'utils',
  27     ]
  28 
  29 
  30 
  31 # Some convenience routines.  Don't import Parser and Message as side-effects
  32 # of importing email since those cascadingly import most of the rest of the
  33 # email package.
  34 def message_from_string(s, *args, **kws):
  35     """Parse a string into a Message object model.
  36 
  37     Optional _class and strict are passed to the Parser constructor.
  38     """
  39     from email.parser import Parser
  40     return Parser(*args, **kws).parsestr(s)
  41 
  42 def message_from_bytes(s, *args, **kws):
  43     """Parse a bytes string into a Message object model.
  44 
  45     Optional _class and strict are passed to the Parser constructor.
  46     """
  47     from email.parser import BytesParser
  48     return BytesParser(*args, **kws).parsebytes(s)
  49 
  50 def message_from_file(fp, *args, **kws):
  51     """Read a file and parse its contents into a Message object model.
  52 
  53     Optional _class and strict are passed to the Parser constructor.
  54     """
  55     from email.parser import Parser
  56     return Parser(*args, **kws).parse(fp)
  57 
  58 def message_from_binary_file(fp, *args, **kws):
  59     """Read a binary file and parse its contents into a Message object model.
  60 
  61     Optional _class and strict are passed to the Parser constructor.
  62     """
  63     from email.parser import BytesParser
  64     return BytesParser(*args, **kws).parse(fp)