ISO 8859-1 filename not decoding

后端 未结 1 1281
刺人心
刺人心 2020-12-11 21:32

I\'m extracting files from MIME messages in a python milter and am running across issues with files named as such:

=?ISO-8859-1?Q?Certificado=5FZonificaci=F3n=5F2010

相关标签:
1条回答
  • 2020-12-11 22:01

    Your string is encoded using the Quoted-printable format for MIME headers. The email.header module handles this for you:

    >>> from email.header import decode_header
    >>> try:
    ...     string_type = unicode  # Python 2
    ... except NameError:
    ...     string_type = str      # Python 3
    ...
    >>> for part in decode_header('=?ISO-8859-1?Q?Certificado=5FZonificaci=F3n=5F2010=2Epdf?='):
    ...     decoded = string_type(*part)
    ...     print(decoded)
    ...
    Certificado_Zonificación_2010.pdf
    
    0 讨论(0)
提交回复
热议问题