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


Python quopri.decodestring方法代码示例

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


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

示例1: process_payload

# 需要导入模块: import quopri [as 别名]
# 或者: from quopri import decodestring [as 别名]
def process_payload(payload):
    print(payload.get_content_type() + "\n" + "=" * len(
        payload.get_content_type()))
    body = quopri.decodestring(payload.get_payload())
    if payload.get_charset():
        body = body.decode(payload.get_charset())
    else:
        try:
            body = body.decode()
        except UnicodeDecodeError:
            body = body.decode('cp1252')

    if payload.get_content_type() == "text/html":
        outfile = os.path.basename(args.EML_FILE.name) + ".html"
        open(outfile, 'w').write(body)
    elif payload.get_content_type().startswith('application'):
        outfile = open(payload.get_filename(), 'wb')
        body = base64.b64decode(payload.get_payload())
        outfile.write(body)
        outfile.close()
        print("Exported: {}\n".format(outfile.name))
    else:
        print(body) 
开发者ID:PacktPublishing,项目名称:Python-Digital-Forensics-Cookbook,代码行数:25,代码来源:eml_parser.py

示例2: _decode_one_part_body

# 需要导入模块: import quopri [as 别名]
# 或者: from quopri import decodestring [as 别名]
def _decode_one_part_body(lines: List[bytes], transfer_encoding: str, charsets: List[str], _need_decode=True):
    """Decode transfer-encoding then decode raw value to string."""
    if transfer_encoding == 'quoted-printable':
        decoded_bytes = decodestring(b'\r\n'.join(lines))
        if _need_decode:
            return recursive_decode(decoded_bytes, charsets)
        else:
            return b'\r\n'.join(lines)
    elif transfer_encoding == 'base64':
        decoded_bytes = b64decode(b''.join(lines))
        if _need_decode:
            return recursive_decode(decoded_bytes, charsets)
        else:
            return decoded_bytes
    elif transfer_encoding in ('binary', '8bit', '7bit'):
        if _need_decode:
            return recursive_decode(b'\r\n'.join(lines), charsets)
        else:
            return b'\r\n'.join(lines)
    else:
        raise ParseError('Invalid transfer-encoding {}'.format(transfer_encoding)) 
开发者ID:ZYunH,项目名称:zmail,代码行数:23,代码来源:parser.py

示例3: decode_payload

# 需要导入模块: import quopri [as 别名]
# 或者: from quopri import decodestring [as 别名]
def decode_payload(encoding, payload):
    """Decode the payload according to the given encoding

    Supported encodings: base64, quoted-printable.

    :param encoding: the encoding's name
    :param payload: the value to decode
    :return: a string
    """
    encoding = encoding.lower()
    if encoding == "base64":
        import base64
        return base64.b64decode(payload)
    elif encoding == "quoted-printable":
        import quopri
        return quopri.decodestring(payload)
    return payload 
开发者ID:modoboa,项目名称:modoboa-webmail,代码行数:19,代码来源:utils.py

示例4: _build_attachments

# 需要导入模块: import quopri [as 别名]
# 或者: from quopri import decodestring [as 别名]
def _build_attachments(self, message):
        attachments = []

        for attachment in message.attachments:
            file_name = attachment.get_filename()
            encoding = attachment.get('Content-Transfer-Encoding', None)

            if encoding == 'base64':
                decode = not attachment.get_content_maintype() in ['audio', 'image', 'text']
                content = b64decode(attachment.get_payload(decode=decode))
            elif encoding == 'quoted-printable':
                content = decode_quopri(attachment.get_payload())
            else:
                content = attachment.get_payload()

            content_type = attachment.get_content_type()
            attachments.append(('attachment', (file_name, content, content_type)))

        return attachments 
开发者ID:alexandrevicenzi,项目名称:fluentmail,代码行数:21,代码来源:mailgun.py

示例5: test_decodestring

# 需要导入模块: import quopri [as 别名]
# 或者: from quopri import decodestring [as 别名]
def test_decodestring(self):
        for p, e in self.STRINGS:
            self.assertTrue(quopri.decodestring(e) == p) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_quopri.py

示例6: test_idempotent_string

# 需要导入模块: import quopri [as 别名]
# 或者: from quopri import decodestring [as 别名]
def test_idempotent_string(self):
        for p, e in self.STRINGS:
            self.assertTrue(quopri.decodestring(quopri.encodestring(e)) == e) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_quopri.py

示例7: test_embedded_ws

# 需要导入模块: import quopri [as 别名]
# 或者: from quopri import decodestring [as 别名]
def test_embedded_ws(self):
        for p, e in self.ESTRINGS:
            self.assertTrue(quopri.encodestring(p, quotetabs=True) == e)
            self.assertTrue(quopri.decodestring(e) == p) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_quopri.py

示例8: test_decode_header

# 需要导入模块: import quopri [as 别名]
# 或者: from quopri import decodestring [as 别名]
def test_decode_header(self):
        for p, e in self.HSTRINGS:
            self.assertTrue(quopri.decodestring(e, header=True) == p) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_quopri.py

示例9: decode

# 需要导入模块: import quopri [as 别名]
# 或者: from quopri import decodestring [as 别名]
def decode(self, line):
        line = self._consumed_lines + line # add potentially stored previous lines
        self._consumed_lines = ''
        m = QuotedPrintableDecoder.quoted.match(line)
        if m:
            line = line[:m.start(1)] + line[m.end(1):] # remove the matched group 1 from line
            decoded_line = quopri.decodestring(line).decode('UTF-8')
            # Escape newlines, but preserve the last one (which must be '\n', since we read the file in universal newliens mode)
            decoded_line = decoded_line[:-1].replace('\r\n', '\\n')
            decoded_line = decoded_line.replace('\n', '\\n')
            return decoded_line + '\n'
        return line 
开发者ID:jowave,项目名称:vcard2to3,代码行数:14,代码来源:vcard2to3.py

示例10: decode_transfer_encoding

# 需要导入模块: import quopri [as 别名]
# 或者: from quopri import decodestring [as 别名]
def decode_transfer_encoding(encoding, body):
    if encoding == 'base64':
        return _base64_decode(body)
    elif encoding == 'quoted-printable':
        return quopri.decodestring(body)
    else:
        return body 
开发者ID:duo-labs,项目名称:isthislegit,代码行数:9,代码来源:part.py

示例11: get_decoded_payload

# 需要导入模块: import quopri [as 别名]
# 或者: from quopri import decodestring [as 别名]
def get_decoded_payload(self):
        """
        Similar to get_payload(decode=True), but:

        * decoding failures are logged as warnings (instead of being
          completely silent);
        * if the message is a multipart one, the payload of its first
          part is extracted (with `.get_decoded_payload()`, recursively)
          and returned instead of `None`.
        """
        # copied from Py2.7's email.message.Message.get_payload() and adjusted
        payload = self._payload
        if self.is_multipart():
            first_part = payload[0]
            assert isinstance(first_part, self.__class__)
            return first_part.get_decoded_payload()
        cte = self.get('content-transfer-encoding', '').lower()
        if cte == 'quoted-printable':
            payload = quopri.decodestring(payload)
        elif cte == 'base64':
            if payload:
                try:
                    payload = base64.decodestring(payload)
                except binascii.Error:
                    LOGGER.warning('Could not decode the payload using base64'
                                   ' => not decoding')
                    LOGGER.debug('The payload: %r', payload)
        elif cte in ('x-uuencode', 'uuencode', 'uue', 'x-uue'):
            sfp = StringIO()
            try:
                uu.decode(StringIO(payload + '\n'), sfp, quiet=True)
                payload = sfp.getvalue()
            except uu.Error:
                LOGGER.warning('Could not decode the payload using %s'
                               ' => not decoding', cte)
                LOGGER.debug('The payload: %r', payload)
        elif cte not in ('', '7bit', '8bit', 'binary'):
            LOGGER.warning('Unsupported content-transfer-encoding: %s'
                           ' => not decoding', cte)
            LOGGER.debug('The payload: %r', payload)
        return payload 
开发者ID:CERT-Polska,项目名称:n6,代码行数:43,代码来源:email_message.py

示例12: arion_parse

# 需要导入模块: import quopri [as 别名]
# 或者: from quopri import decodestring [as 别名]
def arion_parse(self, payload):
        """Non-multipart but with the plaintext in HTML comment"""
        s = payload[:payload.index("-->")]
        lines = s.splitlines()
        # Fault tolerance, it changes around a bit
        try:
            amount = int(re.sub(r"[^0-9]", "", lines[9].split(": ")[1]))
            raw = quopri.decodestring(lines[11]).split(": ")[1]
        except IndexError:
            raise ValueError("2 Arion Bankmail without plaintext encoutered")
        # Not sure if nessesary or formed user input from user "Numi"
        skyring = raw.strip().decode("tis-620")
        return skyring, amount, "arion" 
开发者ID:benediktkr,项目名称:lokun-record,代码行数:15,代码来源:Bankmail.py

示例13: test_decodestring

# 需要导入模块: import quopri [as 别名]
# 或者: from quopri import decodestring [as 别名]
def test_decodestring(self):
        for p, e in self.STRINGS:
            self.assertEqual(quopri.decodestring(e), p) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:5,代码来源:test_quopri.py

示例14: test_decodestring_double_equals

# 需要导入模块: import quopri [as 别名]
# 或者: from quopri import decodestring [as 别名]
def test_decodestring_double_equals(self):
        # Issue 21511 - Ensure that byte string is compared to byte string
        # instead of int byte value
        decoded_value, encoded_value = (b"123=four", b"123==four")
        self.assertEqual(quopri.decodestring(encoded_value), decoded_value) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:7,代码来源:test_quopri.py

示例15: test_idempotent_string

# 需要导入模块: import quopri [as 别名]
# 或者: from quopri import decodestring [as 别名]
def test_idempotent_string(self):
        for p, e in self.STRINGS:
            self.assertEqual(quopri.decodestring(quopri.encodestring(e)), e) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:5,代码来源:test_quopri.py


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