3

好的。这是我的代码:

hotmail = poplib.POP3_SSL("pop3.live.com", 995)

hotmail.user("username")

hotmail.pass_("password")

mail_1= hotmail.retr(1)

message_1 = email.message_from_string("\n".join(mail_1[1]))

for part in message.walk():
    print part.get_content_type()

    print "\n"

    print part.get_payload()

    print "----------------------------------------------"


mail_2 = hotmail.retr(2)

message_2 = email.message_from_string("\n".join(mail_2[1]))

for part in message.walk():
    print part.get_content_type()

    print "\n"

    print part.get_payload()

    print "----------------------------------------------"

我现在遇到的问题是,mail_1这是一封 hotmail 欢迎邮件,一切正常,尤其是text/html部分,它的格式正确。但这mail_2是一条multipart/alternative消息,我从中得到的text/html是一团糟,有很多填充物,比如和=0D到处都是,一些典型的线条看起来像这样:3D=

<td id=3D"middle_column=
_content_cell" style=3D"background-color:#ffffff;=0D
                                                    -webkit-border-radius:6=
px; -moz-border-radius:6px; border-radius:6px;=0D
                                                    -webkit-box-shadow:0 1p=
x 3px rgba(0,0,0, 0.2);=0D
                                                    -moz-box-shadow:0 1px 3=
px rgba(0,0,0, 0.2);=0D
                                                    box-shadow:0 1px 3px rg=
ba(0,0,0, 0.2);">=0D
=0D
                                                        <span style=3D"font=
-family:'Helvetica Neue', Helvetica, Arial, sans-serif;=0D
                                                        font-size:16px; lin=
e-height:22px; color:#424242;">=0D

那么我该怎么做才能获得有意义的text/html消息体呢?

4

1 回答 1

2

你想要quopri模块:

import quopri

decoded_text = quopri.decodestring(encoded_text)
于 2012-10-26T02:59:03.220 回答