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


Python email.message_from_file方法代碼示例

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


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

示例1: read_file

# 需要導入模塊: import email [as 別名]
# 或者: from email import message_from_file [as 別名]
def read_file(self, fileob):
        """Read the metadata values from a file object."""
        msg = message_from_file(fileob)
        self._fields['Metadata-Version'] = msg['metadata-version']

        # When reading, get all the fields we can
        for field in _ALL_FIELDS:
            if field not in msg:
                continue
            if field in _LISTFIELDS:
                # we can have multiple lines
                values = msg.get_all(field)
                if field in _LISTTUPLEFIELDS and values is not None:
                    values = [tuple(value.split(',')) for value in values]
                self.set(field, values)
            else:
                # single line
                value = msg[field]
                if value is not None and value != 'UNKNOWN':
                    self.set(field, value)
        self.set_metadata_version() 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:23,代碼來源:metadata.py

示例2: test_default_type

# 需要導入模塊: import email [as 別名]
# 或者: from email import message_from_file [as 別名]
def test_default_type(self):
        eq = self.assertEqual
        fp = openfile('msg_30.txt')
        try:
            msg = email.message_from_file(fp)
        finally:
            fp.close()
        container1 = msg.get_payload(0)
        eq(container1.get_default_type(), 'message/rfc822')
        eq(container1.get_content_type(), 'message/rfc822')
        container2 = msg.get_payload(1)
        eq(container2.get_default_type(), 'message/rfc822')
        eq(container2.get_content_type(), 'message/rfc822')
        container1a = container1.get_payload(0)
        eq(container1a.get_default_type(), 'text/plain')
        eq(container1a.get_content_type(), 'text/plain')
        container2a = container2.get_payload(0)
        eq(container2a.get_default_type(), 'text/plain')
        eq(container2a.get_content_type(), 'text/plain') 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:21,代碼來源:test_email.py

示例3: test_default_type_with_explicit_container_type

# 需要導入模塊: import email [as 別名]
# 或者: from email import message_from_file [as 別名]
def test_default_type_with_explicit_container_type(self):
        eq = self.assertEqual
        fp = openfile('msg_28.txt')
        try:
            msg = email.message_from_file(fp)
        finally:
            fp.close()
        container1 = msg.get_payload(0)
        eq(container1.get_default_type(), 'message/rfc822')
        eq(container1.get_content_type(), 'message/rfc822')
        container2 = msg.get_payload(1)
        eq(container2.get_default_type(), 'message/rfc822')
        eq(container2.get_content_type(), 'message/rfc822')
        container1a = container1.get_payload(0)
        eq(container1a.get_default_type(), 'text/plain')
        eq(container1a.get_content_type(), 'text/plain')
        container2a = container2.get_payload(0)
        eq(container2a.get_default_type(), 'text/plain')
        eq(container2a.get_content_type(), 'text/plain') 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:21,代碼來源:test_email.py

示例4: test__all__

# 需要導入模塊: import email [as 別名]
# 或者: from email import message_from_file [as 別名]
def test__all__(self):
        module = __import__('email')
        all = module.__all__
        all.sort()
        self.assertEqual(all, [
            # Old names
            'Charset', 'Encoders', 'Errors', 'Generator',
            'Header', 'Iterators', 'MIMEAudio', 'MIMEBase',
            'MIMEImage', 'MIMEMessage', 'MIMEMultipart',
            'MIMENonMultipart', 'MIMEText', 'Message',
            'Parser', 'Utils', 'base64MIME',
            # new names
            'base64mime', 'charset', 'encoders', 'errors', 'generator',
            'header', 'iterators', 'message', 'message_from_file',
            'message_from_string', 'mime', 'parser',
            'quopriMIME', 'quoprimime', 'utils',
            ]) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:19,代碼來源:test_email.py

示例5: test_message_from_file_with_class

# 需要導入模塊: import email [as 別名]
# 或者: from email import message_from_file [as 別名]
def test_message_from_file_with_class(self):
        # Create a subclass
        class MyMessage(Message):
            pass

        fp = openfile('msg_01.txt')
        try:
            msg = email.message_from_file(fp, MyMessage)
        finally:
            fp.close()
        self.assertIsInstance(msg, MyMessage)
        # Try something more complicated
        fp = openfile('msg_02.txt')
        try:
            msg = email.message_from_file(fp, MyMessage)
        finally:
            fp.close()
        for subpart in msg.walk():
            self.assertIsInstance(subpart, MyMessage) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:21,代碼來源:test_email_renamed.py

示例6: test__all__

# 需要導入模塊: import email [as 別名]
# 或者: from email import message_from_file [as 別名]
def test__all__(self):
        module = __import__('email')
        # Can't use sorted() here due to Python 2.3 compatibility
        all = module.__all__[:]
        all.sort()
        self.assertEqual(all, [
            # Old names
            'Charset', 'Encoders', 'Errors', 'Generator',
            'Header', 'Iterators', 'MIMEAudio', 'MIMEBase',
            'MIMEImage', 'MIMEMessage', 'MIMEMultipart',
            'MIMENonMultipart', 'MIMEText', 'Message',
            'Parser', 'Utils', 'base64MIME',
            # new names
            'base64mime', 'charset', 'encoders', 'errors', 'generator',
            'header', 'iterators', 'message', 'message_from_file',
            'message_from_string', 'mime', 'parser',
            'quopriMIME', 'quoprimime', 'utils',
            ]) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:20,代碼來源:test_email_renamed.py

示例7: _get_version_from_pkg_metadata

# 需要導入模塊: import email [as 別名]
# 或者: from email import message_from_file [as 別名]
def _get_version_from_pkg_metadata(package_name):
    """Get the version from package metadata if present.

    This looks for PKG-INFO if present (for sdists), and if not looks
    for METADATA (for wheels) and failing that will return None.
    """
    pkg_metadata_filenames = ['PKG-INFO', 'METADATA']
    pkg_metadata = {}
    for filename in pkg_metadata_filenames:
        try:
            pkg_metadata_file = open(filename, 'r')
        except (IOError, OSError):
            continue
        try:
            pkg_metadata = email.message_from_file(pkg_metadata_file)
        except email.errors.MessageError:
            continue

    # Check to make sure we're in our own dir
    if pkg_metadata.get('Name', None) != package_name:
        return None
    return pkg_metadata.get('Version', None) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:24,代碼來源:packaging.py

示例8: read_file

# 需要導入模塊: import email [as 別名]
# 或者: from email import message_from_file [as 別名]
def read_file(self, fileob):
        """Read the metadata values from a file object."""
        msg = message_from_file(fileob)
        self._fields['Metadata-Version'] = msg['metadata-version']

        # When reading, get all the fields we can
        for field in _ALL_FIELDS:
            if field not in msg:
                continue
            if field in _LISTFIELDS:
                # we can have multiple lines
                values = msg.get_all(field)
                if field in _LISTTUPLEFIELDS and values is not None:
                    values = [tuple(value.split(',')) for value in values]
                self.set(field, values)
            else:
                # single line
                value = msg[field]
                if value is not None and value != 'UNKNOWN':
                    self.set(field, value)
        logger.debug('Attempting to set metadata for %s', self)
        self.set_metadata_version() 
開發者ID:HaoZhang95,項目名稱:Python24,代碼行數:24,代碼來源:metadata.py

示例9: text_parser

# 需要導入模塊: import email [as 別名]
# 或者: from email import message_from_file [as 別名]
def text_parser(path):
    with open(path) as eml:
        m = email.message_from_file(eml)

    if m.get_content_type!='mixed':
        for m in m.walk():
            if m.get_content_subtype()=='plain':
                try:
                    text = str(m.get_payload(decode=True),encoding='utf-8')
                except:
                    text = str(m.get_payload(decode=True),encoding='gbk')
                text = text.replace('--\n發自我的網易郵箱平板適配版','')
                text = text.split('----------------')[0]
                text = text.strip()
                return text
            if m.get_content_subtype()=='html':
                try:
                    text = str(m.get_payload(decode=True),encoding='utf-8')
                except:
                    text = str(m.get_payload(decode=True),encoding='gbk')
                text = h2t.handle(text)
                text = text.strip()
                text = text.replace('  ','')
                return text 
開發者ID:DannyVim,項目名稱:ToolsCollection,代碼行數:26,代碼來源:email_parser.py

示例10: test_message_from_file_with_class

# 需要導入模塊: import email [as 別名]
# 或者: from email import message_from_file [as 別名]
def test_message_from_file_with_class(self):
        unless = self.assertTrue
        # Create a subclass
        class MyMessage(Message):
            pass

        fp = openfile('msg_01.txt')
        try:
            msg = email.message_from_file(fp, MyMessage)
        finally:
            fp.close()
        unless(isinstance(msg, MyMessage))
        # Try something more complicated
        fp = openfile('msg_02.txt')
        try:
            msg = email.message_from_file(fp, MyMessage)
        finally:
            fp.close()
        for subpart in msg.walk():
            unless(isinstance(subpart, MyMessage)) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:22,代碼來源:test_email_renamed.py

示例11: read_file

# 需要導入模塊: import email [as 別名]
# 或者: from email import message_from_file [as 別名]
def read_file(self, fileob):
        """Read the metadata values from a file object."""
        msg = message_from_file(fileob)
        self._fields['Metadata-Version'] = msg['metadata-version']

        # When reading, get all the fields we can
        for field in _ALL_FIELDS:
            if field not in msg:
                continue
            if field in _LISTFIELDS:
                # we can have multiple lines
                values = msg.get_all(field)
                if field in _LISTTUPLEFIELDS and values is not None:
                    values = [tuple(value.split(',')) for value in values]
                self.set(field, values)
            else:
                # single line
                value = msg[field]
                if value is not None and value != 'UNKNOWN':
                    self.set(field, value)
        # logger.debug('Attempting to set metadata for %s', self)
        # self.set_metadata_version() 
開發者ID:PacktPublishing,項目名稱:Mastering-Elasticsearch-7.0,代碼行數:24,代碼來源:metadata.py


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