email.parser.Parser.parse

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 7

Example 1

Project: pixelated-user-agent Source File: util.py
Function: load_mail_from_file
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

Example 2

Project: pixelated-user-agent Source File: test_leap_mailstore.py
Function: load_mail_from_file
    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

Example 3

Project: PokemonGo-Bot-Desktop Source File: __init__.py
Function: message_from_file
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)

Example 4

Project: pymo Source File: test_old_mailbox.py
Function: test_unix_mbox
    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)

Example 5

Project: HealthStarter Source File: pkginfo.py
Function: read_pkg_info
    def read_pkg_info(path):
        with open(path, "r", 
                  encoding="ascii", 
                  errors="surrogateescape") as headers:
            message = Parser().parse(headers)
        return message

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)

Example 7

Project: HealthStarter Source File: pkginfo.py
Function: read_pkg_info
    def read_pkg_info(path):
        with open(path, "r") as headers:
            message = Parser().parse(headers)
        return message

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

Example 9

Project: md Source File: __init__.py
Function: get_content
    def _get_content(self):
        # self.content is provided by __getattr__ through the cache var self._content
        return Parser().parse(StringIO(self.content))