当前位置: 首页>>代码示例>>Python>>正文


Python email.policy方法代码示例

本文整理汇总了Python中email.policy方法的典型用法代码示例。如果您正苦于以下问题:Python email.policy方法的具体用法?Python email.policy怎么用?Python email.policy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在email的用法示例。


在下文中一共展示了email.policy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: write_to

# 需要导入模块: import email [as 别名]
# 或者: from email import policy [as 别名]
def write_to(self, fp):
        """Output the MHTML file to the given file-like object.

        Args:
            fp: The file-object, opened in "wb" mode.
        """
        msg = email.mime.multipart.MIMEMultipart(
            'related', '---=_qute-{}'.format(uuid.uuid4()))

        root = self._create_root_file()
        msg.attach(root)

        for _, file_data in sorted(self._files.items()):
            msg.attach(self._create_file(file_data))

        gen = email.generator.BytesGenerator(fp, policy=MHTMLPolicy)
        gen.flatten(msg) 
开发者ID:qutebrowser,项目名称:qutebrowser,代码行数:19,代码来源:mhtml.py

示例2: get_imap_messages

# 需要导入模块: import email [as 别名]
# 或者: from email import policy [as 别名]
def get_imap_messages() -> Generator[EmailMessage, None, None]:
    mbox = IMAP4_SSL(settings.EMAIL_GATEWAY_IMAP_SERVER, settings.EMAIL_GATEWAY_IMAP_PORT)
    mbox.login(settings.EMAIL_GATEWAY_LOGIN, settings.EMAIL_GATEWAY_PASSWORD)
    try:
        mbox.select(settings.EMAIL_GATEWAY_IMAP_FOLDER)
        try:
            status, num_ids_data = mbox.search(None, 'ALL')
            for message_id in num_ids_data[0].split():
                status, msg_data = mbox.fetch(message_id, '(RFC822)')
                assert isinstance(msg_data[0], tuple)
                msg_as_bytes = msg_data[0][1]
                message = email.message_from_bytes(msg_as_bytes, policy=email.policy.default)
                assert isinstance(message, EmailMessage)  # https://github.com/python/typeshed/issues/2417
                yield message
                mbox.store(message_id, '+FLAGS', '\\Deleted')
            mbox.expunge()
        finally:
            mbox.close()
    finally:
        mbox.logout() 
开发者ID:zulip,项目名称:zulip,代码行数:22,代码来源:email_mirror.py

示例3: test_charset_not_specified

# 需要导入模块: import email [as 别名]
# 或者: from email import policy [as 别名]
def test_charset_not_specified(self) -> None:
        message_as_string = self.fixture_data('1.txt', type='email')
        message_as_string = message_as_string.replace("Content-Type: text/plain; charset=\"us-ascii\"",
                                                      "Content-Type: text/plain")
        incoming_message = message_from_string(message_as_string, policy=email.policy.default)
        assert isinstance(incoming_message, EmailMessage)  # https://github.com/python/typeshed/issues/2417

        user_profile = self.example_user('hamlet')
        self.login_user(user_profile)
        self.subscribe(user_profile, "Denmark")
        stream = get_stream("Denmark", user_profile.realm)
        stream_to_address = encode_email_address(stream)

        del incoming_message['To']
        incoming_message['To'] = stream_to_address
        process_message(incoming_message)
        message = most_recent_message(user_profile)

        self.assertEqual(message.content, "Email fixture 1.txt body") 
开发者ID:zulip,项目名称:zulip,代码行数:21,代码来源:test_email_mirror.py

示例4: consume

# 需要导入模块: import email [as 别名]
# 或者: from email import policy [as 别名]
def consume(self, event: Mapping[str, Any]) -> None:
        rcpt_to = event['rcpt_to']
        msg = email.message_from_bytes(
            base64.b64decode(event["msg_base64"]),
            policy=email.policy.default,
        )
        assert isinstance(msg, EmailMessage)  # https://github.com/python/typeshed/issues/2417
        if not is_missed_message_address(rcpt_to):
            # Missed message addresses are one-time use, so we don't need
            # to worry about emails to them resulting in message spam.
            recipient_realm = decode_stream_email_address(rcpt_to)[0].realm
            try:
                rate_limit_mirror_by_realm(recipient_realm)
            except RateLimited:
                logger.warning("MirrorWorker: Rejecting an email from: %s "
                               "to realm: %s - rate limited.",
                               msg['From'], recipient_realm.name)
                return

        mirror_email(msg, rcpt_to=rcpt_to) 
开发者ID:zulip,项目名称:zulip,代码行数:22,代码来源:queue_processors.py

示例5: flatten_message

# 需要导入模块: import email [as 别名]
# 或者: from email import policy [as 别名]
def flatten_message(
    message: email.message.Message, utf8: bool = False, cte_type: str = "8bit"
) -> bytes:
    # Make a local copy so we can delete the bcc headers.
    message_copy = copy.copy(message)
    del message_copy["Bcc"]
    del message_copy["Resent-Bcc"]

    if isinstance(message.policy, email.policy.Compat32):  # type: ignore
        # Compat32 cannot use UTF8
        policy = message.policy.clone(  # type: ignore
            linesep=LINE_SEP, cte_type=cte_type
        )
    else:
        policy = message.policy.clone(  # type: ignore
            linesep=LINE_SEP, utf8=utf8, cte_type=cte_type
        )

    with io.BytesIO() as messageio:
        generator = email.generator.BytesGenerator(messageio, policy=policy)
        generator.flatten(message_copy)
        flat_message = messageio.getvalue()

    return flat_message 
开发者ID:cole,项目名称:aiosmtplib,代码行数:26,代码来源:email.py

示例6: _parse_email_fixture

# 需要导入模块: import email [as 别名]
# 或者: from email import policy [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

示例7: __init__

# 需要导入模块: import email [as 别名]
# 或者: from email import policy [as 别名]
def __init__(self, _maintype, _subtype, *, policy=None, **_params):
        """This constructor adds a Content-Type: and a MIME-Version: header.

        The Content-Type: header is taken from the _maintype and _subtype
        arguments.  Additional parameters for this header are taken from the
        keyword arguments.
        """
        if policy is None:
            policy = email.policy.compat32
        message.Message.__init__(self, policy=policy)
        ctype = '%s/%s' % (_maintype, _subtype)
        self.add_header('Content-Type', ctype, **_params)
        self['MIME-Version'] = '1.0' 
开发者ID:CedricGuillemet,项目名称:Imogen,代码行数:15,代码来源:base.py

示例8: test_mbox_with_8bit_tags

# 需要导入模块: import email [as 别名]
# 或者: from email import policy [as 别名]
def test_mbox_with_8bit_tags(self):
        self.cli_login()
        self.cli_import("0028-tags-need-8bit-encoding.mbox.gz")
        self.cli_logout()
        mbox = self.client.get("/QEMU/20181126152836.25379-1-rkagan@virtuozzo.com/mbox")
        parser = email.parser.BytesParser(policy=email.policy.SMTP)
        msg = parser.parsebytes(mbox.content)
        payload = decode_payload(msg)
        self.assertIn("SynICState *synic = get_synic(cs);", payload)
        self.assertIn(
            "Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>", payload
        ) 
开发者ID:patchew-project,项目名称:patchew,代码行数:14,代码来源:test_tags.py

示例9: new

# 需要导入模块: import email [as 别名]
# 或者: from email import policy [as 别名]
def new():
    return MIMEPart(policy) 
开发者ID:naspeh,项目名称:mailur,代码行数:4,代码来源:message.py

示例10: test_as_string_policy

# 需要导入模块: import email [as 别名]
# 或者: from email import policy [as 别名]
def test_as_string_policy(self):
        msg = self._msgobj('msg_01.txt')
        newpolicy = msg.policy.clone(linesep='\r\n')
        fullrepr = msg.as_string(policy=newpolicy)
        s = StringIO()
        g = Generator(s, policy=newpolicy)
        g.flatten(msg)
        self.assertEqual(fullrepr, s.getvalue()) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:10,代码来源:test_email.py

示例11: test_as_bytes_policy

# 需要导入模块: import email [as 别名]
# 或者: from email import policy [as 别名]
def test_as_bytes_policy(self):
        msg = self._msgobj('msg_01.txt')
        newpolicy = msg.policy.clone(linesep='\r\n')
        fullrepr = msg.as_bytes(policy=newpolicy)
        s = BytesIO()
        g = BytesGenerator(s,policy=newpolicy)
        g.flatten(msg)
        self.assertEqual(fullrepr, s.getvalue())

    # test_headerregistry.TestContentTypeHeader.bad_params 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:12,代码来源:test_email.py

示例12: test_bytes_parser_on_exception_does_not_close_file

# 需要导入模块: import email [as 别名]
# 或者: from email import policy [as 别名]
def test_bytes_parser_on_exception_does_not_close_file(self):
        with openfile('msg_15.txt', 'rb') as fp:
            bytesParser = email.parser.BytesParser
            self.assertRaises(email.errors.StartBoundaryNotFoundDefect,
                              bytesParser(policy=email.policy.strict).parse,
                              fp)
            self.assertFalse(fp.closed) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:9,代码来源:test_email.py

示例13: test_parser_on_exception_does_not_close_file

# 需要导入模块: import email [as 别名]
# 或者: from email import policy [as 别名]
def test_parser_on_exception_does_not_close_file(self):
        with openfile('msg_15.txt', 'r') as fp:
            parser = email.parser.Parser
            self.assertRaises(email.errors.StartBoundaryNotFoundDefect,
                              parser(policy=email.policy.strict).parse, fp)
            self.assertFalse(fp.closed) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:8,代码来源:test_email.py

示例14: __init__

# 需要导入模块: import email [as 别名]
# 或者: from email import policy [as 别名]
def __init__(self, policy):
            self.check_policy = policy
            super().__init__() 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:5,代码来源:test_parser.py

示例15: test_custom_message_gets_policy_if_possible_from_string

# 需要导入模块: import email [as 别名]
# 或者: from email import policy [as 别名]
def test_custom_message_gets_policy_if_possible_from_string(self):
        msg = email.message_from_string("Subject: bogus\n\nmsg\n",
                                        self.MyMessage,
                                        policy=self.MyPolicy)
        self.assertIsInstance(msg, self.MyMessage)
        self.assertIs(msg.check_policy, self.MyPolicy) 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:8,代码来源:test_parser.py


注:本文中的email.policy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。