當前位置: 首頁>>代碼示例>>Python>>正文


Python email.message_from_binary_file方法代碼示例

本文整理匯總了Python中email.message_from_binary_file方法的典型用法代碼示例。如果您正苦於以下問題:Python email.message_from_binary_file方法的具體用法?Python email.message_from_binary_file怎麽用?Python email.message_from_binary_file使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在email的用法示例。


在下文中一共展示了email.message_from_binary_file方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: parse

# 需要導入模塊: import email [as 別名]
# 或者: from email import message_from_binary_file [as 別名]
def parse(self):
        try:
            if self.message_type == ParserMessageType.STRING:
                msg = email.message_from_string(self.raw_message, Message)
            elif self.message_type == ParserMessageType.BYTES:
                msg = email.message_from_bytes(self.raw_message, Message)
            elif self.message_type == ParserMessageType.BINARY_FILE:
                msg = email.message_from_binary_file(self.raw_message, Message)
            else:
                raise ValueError("Invalid message_type, could not parse message.")
        except Exception:
            raise ParseEmailException

        # Do basic post-processing of the message, checking it for defects or
        # other missing information.
        if msg.defects:
            raise DefectMessageException

        # Add headers used by LEGO
        msg.original_size = len(self.raw_message)
        msg["X-MailFrom"] = self.mail_from

        return msg 
開發者ID:webkom,項目名稱:lego,代碼行數:25,代碼來源:parser.py

示例2: __init__

# 需要導入模塊: import email [as 別名]
# 或者: from email import message_from_binary_file [as 別名]
def __init__(self, message=None):
        """Initialize a Message instance."""
        if isinstance(message, email.message.Message):
            self._become_message(copy.deepcopy(message))
            if isinstance(message, Message):
                message._explain_to(self)
        elif isinstance(message, bytes):
            self._become_message(email.message_from_bytes(message))
        elif isinstance(message, str):
            self._become_message(email.message_from_string(message))
        elif isinstance(message, io.TextIOWrapper):
            self._become_message(email.message_from_file(message))
        elif hasattr(message, "read"):
            self._become_message(email.message_from_binary_file(message))
        elif message is None:
            email.message.Message.__init__(self)
        else:
            raise TypeError('Invalid message type: %s' % type(message)) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:20,代碼來源:mailbox.py

示例3: _parse_email_fixture

# 需要導入模塊: import email [as 別名]
# 或者: from email import message_from_binary_file [as 別名]
def _parse_email_fixture(self, fixture_path: str) -> EmailMessage:
        if not self._does_fixture_path_exist(fixture_path):
            raise CommandError(f'Fixture {fixture_path} does not exist')

        if fixture_path.endswith('.json'):
            return self._parse_email_json_fixture(fixture_path)
        else:
            with open(fixture_path, "rb") as fp:
                message = email.message_from_binary_file(fp, policy=email.policy.default)
                assert isinstance(message, EmailMessage)  # https://github.com/python/typeshed/issues/2417
                return message 
開發者ID:zulip,項目名稱:zulip,代碼行數:13,代碼來源:send_to_email_mirror.py

示例4: test_file_with_attachement

# 需要導入模塊: import email [as 別名]
# 或者: from email import message_from_binary_file [as 別名]
def test_file_with_attachement(self):
        with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data/test_attachment.eml'), mode='br') as msg:
            imap_client = yield from self.login_user('user@mail', 'pass', select=True)
            mail = Mail(email.message_from_binary_file(msg))

            self.imapserver.receive(mail, imap_user='user@mail')

            result, data = yield from imap_client.fetch('1', '(RFC822)')

            self.assertEqual('OK', result)
            self.assertEqual(['1 FETCH (RFC822 {418898}', mail.as_bytes(), ')', 'FETCH completed.'], data) 
開發者ID:bamthomas,項目名稱:aioimaplib,代碼行數:13,代碼來源:test_acceptance_aioimaplib.py

示例5: test_file_sessions

# 需要導入模塊: import email [as 別名]
# 或者: from email import message_from_binary_file [as 別名]
def test_file_sessions(self):
        """Make sure opening a connection creates a new file"""
        msg = EmailMessage(
            'Subject', 'Content', 'bounce@example.com', ['to@example.com'],
            headers={'From': 'from@example.com'},
        )
        connection = mail.get_connection()
        connection.send_messages([msg])

        self.assertEqual(len(os.listdir(self.tmp_dir)), 1)
        with open(os.path.join(self.tmp_dir, os.listdir(self.tmp_dir)[0]), 'rb') as fp:
            message = message_from_binary_file(fp)
        self.assertEqual(message.get_content_type(), 'text/plain')
        self.assertEqual(message.get('subject'), 'Subject')
        self.assertEqual(message.get('from'), 'from@example.com')
        self.assertEqual(message.get('to'), 'to@example.com')

        connection2 = mail.get_connection()
        connection2.send_messages([msg])
        self.assertEqual(len(os.listdir(self.tmp_dir)), 2)

        connection.send_messages([msg])
        self.assertEqual(len(os.listdir(self.tmp_dir)), 2)

        msg.connection = mail.get_connection()
        self.assertTrue(connection.open())
        msg.send()
        self.assertEqual(len(os.listdir(self.tmp_dir)), 3)
        msg.send()
        self.assertEqual(len(os.listdir(self.tmp_dir)), 3)

        connection.close() 
開發者ID:nesdis,項目名稱:djongo,代碼行數:34,代碼來源:tests.py

示例6: message_from_binary_file

# 需要導入模塊: import email [as 別名]
# 或者: from email import message_from_binary_file [as 別名]
def message_from_binary_file(s, *args, **kw):
    f = io.BytesIO(s.encode())
    return email.message_from_binary_file(f, *args, **kw) 
開發者ID:bkerler,項目名稱:android_universal,代碼行數:5,代碼來源:test_parser.py


注:本文中的email.message_from_binary_file方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。