lib电子邮件解析问题...... [英] The lib email parse problem...

查看:84
本文介绍了lib电子邮件解析问题......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有


当电子邮件正文包含multipart / alternative时,我必须知道

边界何时解析它,


但是电子邮件库没有提供一些功能来指示

边界结束,如何解决?


谢谢。

解决方案

" ????"写道:


当一个电子邮件正文包含multipart / alternative时,我必须知道

边界是否结束解析它,



或使用了解多部分消息的库。


但是电子邮件lib没有提供某些功能来指示

边界结束,如何解决?

http:// docs。 python.org/lib/module-email.Parser.html


< / F>


????????????写道:


所有


当电子邮件正文包含multipart / alternative时,我必须知道何时

边界结束解析它,


但是电子邮件lib没有提供一些功能来指示

边界结束,如何解决它?



阅读手册。
http://docs.python.org/lib/module-email.Message.html


你不喜欢我需要关注自己的界限 - 提供一个高级别的
解析器。


这里有一个简单的例子:


这个脚本:


msg_text ="""

[snip - message是一些纯文本加上附件]

""

导入电子邮件

pmsg = email.message_from_string(msg_text)

for部分在pmsg.walk():

print part.get_content_type(),part.get_filename("<< NoFileName>>")

产生了这个输出:


multipart / mixed<< NoFileName>>

text / plain<< NoFileName>>

application / octet-stream Extract.py


如需更多合作例如,请参阅
http://docs.python.org/ lib / node597.html

HTH,

John


这还不够。


当一个部件是mulitpart / alternative时,我必须找出我需要哪个子部件,而不是所有的子部件。所以我必须知道替代方案何时结束。

John Machin ???é?????


?????????????写道:


所有


当电子邮件正文包含multipart / alternative时,我必须知道何时

边界结束解析它,


但是电子邮件lib没有提供一些功能来指示

边界结束,如何解决它?



阅读手册。
http://docs.python.org/lib/module-email.Message.html


你不喜欢我需要关注自己的界限 - 提供一个高级别的
解析器。


这里有一个简单的例子:


这个脚本:


msg_text ="""

[snip - message是一些纯文本加上附件]

""

导入电子邮件

pmsg = email.message_from_string(msg_text)

for部分在pmsg.walk():

print part.get_content_type(),part.get_filename("<< NoFileName>>")

产生了这个输出:


multipart / mixed<< NoFileName>>

text / plain<< NoFileName>>

application / octet-stream Extract.py


更多内容重要的例子,请参阅
http://docs.python.org/ lib / node597.html


HTH,

John


hi, all

when a email body consist with multipart/alternative, i must know when
the boundary ends to parse it,

but the email lib have not provide some function to indicate the
boundary end, how to solve it ?

thanks.

解决方案

"????" wrote:

when a email body consist with multipart/alternative, i must know when
the boundary ends to parse it,

or use a library that understands multipart messages.

but the email lib have not provide some function to indicate the
boundary end, how to solve it ?

http://docs.python.org/lib/module-email.Parser.html

</F>


???????????? wrote:

hi, all

when a email body consist with multipart/alternative, i must know when
the boundary ends to parse it,

but the email lib have not provide some function to indicate the
boundary end, how to solve it ?

By reading the manual.
http://docs.python.org/lib/module-email.Message.html

You don''t need to concern yourself with boundaries -- a high-level
parser is provided.

Here''s a simple example:

This script:

msg_text = """
[snip -- message is some plain text plus an attached file]
"""
import email
pmsg = email.message_from_string(msg_text)
for part in pmsg.walk():
print part.get_content_type(), part.get_filename("<<NoFileName>>")

produced this output:

multipart/mixed <<NoFileName>>
text/plain <<NoFileName>>
application/octet-stream Extract.py

For a more comprehensive example, see
http://docs.python.org/lib/node597.html

HTH,
John


this is not enough.

when a part is mulitpart/alternative, i must find out which sub part i
need, not all the subparts. so i must know when the alternative is
ended.
John Machin ???é?????

???????????? wrote:

hi, all

when a email body consist with multipart/alternative, i must know when
the boundary ends to parse it,

but the email lib have not provide some function to indicate the
boundary end, how to solve it ?


By reading the manual.
http://docs.python.org/lib/module-email.Message.html

You don''t need to concern yourself with boundaries -- a high-level
parser is provided.

Here''s a simple example:

This script:

msg_text = """
[snip -- message is some plain text plus an attached file]
"""
import email
pmsg = email.message_from_string(msg_text)
for part in pmsg.walk():
print part.get_content_type(), part.get_filename("<<NoFileName>>")

produced this output:

multipart/mixed <<NoFileName>>
text/plain <<NoFileName>>
application/octet-stream Extract.py

For a more comprehensive example, see
http://docs.python.org/lib/node597.html

HTH,
John


这篇关于lib电子邮件解析问题......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆