擅长:python、mysql、java
<p>您需要的函数是<a href="http://docs.python.org/library/email.header.html#email.header.decode_header" rel="nofollow">^{<cd1>}</a>,它返回<code>(decoded_string, charset)</code>对的列表。这取决于您根据<code>charset</code>进一步解码它们,并在将它们传递给<code>email.utils.getaddresses</code>或任何地方之前将它们重新连接在一起。在</p>
<p>你可能会认为这很简单:</p>
<pre><code>def decode_rfc2047_header(h):
return ' '.join(s.decode(charset or 'ascii')
for s, charset in email.header.decode_header(h))
</code></pre>
<p>但是,由于消息头通常来自不可信的源,因此您必须处理(1)编码错误的数据;(2)伪造的字符集名称。所以你可以这样做:</p>
^{pr2}$