Here are the examples of the python api email.parser.Parser.parse taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
9 Examples
3
Example 1
def load_mail_from_file(mail_file, enforceUniqueMessageId=False):
mailset_dir = pkg_resources.resource_filename('test.unit.fixtures', 'mailset')
mail_file = os.path.join(mailset_dir, 'new', mail_file)
with open(mail_file) as f:
mail = Parser().parse(f)
if enforceUniqueMessageId:
mail.add_header('Message-Id', make_msgid())
return mail
3
Example 2
def _load_mail_from_file(self, mail_file):
mailset_dir = pkg_resources.resource_filename('test.unit.fixtures', 'mailset')
mail_file = os.path.join(mailset_dir, 'new', mail_file)
with open(mail_file) as f:
mail = Parser().parse(f)
return mail
3
Example 3
def message_from_file(fp, *args, **kws):
"""Read a file and parse its contents into a Message object model.
Optional _class and strict are passed to the Parser constructor.
"""
from email.parser import Parser
return Parser(*args, **kws).parse(fp)
3
Example 4
def test_unix_mbox(self):
### should be better!
import email.parser
fname = self.createMessage("cur", True)
n = 0
with open(fname) as f:
for msg in mailbox.PortableUnixMailbox(f,
email.parser.Parser().parse):
n += 1
self.assertEqual(msg["subject"], "Simple Test")
self.assertEqual(len(str(msg)), len(FROM_)+len(DUMMY_MESSAGE))
self.assertEqual(n, 1)
3
Example 5
def read_pkg_info(path):
with open(path, "r",
encoding="ascii",
errors="surrogateescape") as headers:
message = Parser().parse(headers)
return message
0
Example 6
Project: python-slimta Source File: envelope.py
def _parse_data(self, data, *extra):
if pycompat.PY3:
return BytesParser(policy=SMTP).parse(BytesIO(data), *extra)
else:
return Parser().parse(BytesIO(data), *extra)
0
Example 7
def read_pkg_info(path):
with open(path, "r") as headers:
message = Parser().parse(headers)
return message
0
Example 8
Project: SAUCE Source File: test_event_request.py
@property
def lastmail(self):
m = list(self.maildir)[-1]
mail = Parser().parse(open(m))
return mail
0
Example 9
def _get_content(self):
# self.content is provided by __getattr__ through the cache var self._content
return Parser().parse(StringIO(self.content))