开发者

Decode this type of string in python

开发者 https://www.devze.com 2023-03-11 18:34 出处:网络
=?UTF-8?B?TmV3IFBlcnNvbmFsIE1lc3NhZ2U6IE1vbmcgYW5oIHTDrG0gbOG6oWkgY2h1eWVudGIub3JnIQ==?= Hi, I have this string which is what returned from an IMAP command - do anyone know how to decode this in pyth

=?UTF-8?B?TmV3IFBlcnNvbmFsIE1lc3NhZ2U6IE1vbmcgYW5oIHTDrG0gbOG6oWkgY2h1eWVudGIub3JnIQ==?=

Hi, I have this string which is what returned from an IMAP command - do anyone know how to decode this in python so I'll have the proper UTF-8 string开发者_JS百科?


>>> print unicode(base64.decodestring('TmV3IFBlcnNvbmFsIE1lc3NhZ2U6IE1vbmcgYW5oIHTDrG0gbOG6oWkgY2h1eWVudGIub3JnIQ=='), "utf-8")
New Personal Message: Mong anh tìm lại chuyentb.org!
>>> 


I guess the best way to decode this Encoded-Word is via email.header.decode_header(). It'll return you a list in which the first element is the decoded string, and the second element is the encoding.

Example:

email.header.decode_header('=?utf-8?Q?T=e1=ba=a1p_Ch=c3=ad_Gi=e1=ba=a3m_C=c3=a2n_=28=40tapchigiamcan=29_is_now_following_you_on_Twitter=21?=')
[('T\xe1\xba\xa1p Ch\xc3\xad Gi\xe1\xba\xa3m C\xc3\xa2n (@tapchigiamcan) is now following you on Twitter!', 'utf-8')]
0

精彩评论

暂无评论...
验证码 换一张
取 消