通过telnet获取imap正文消息 [英] Fetch imap body message by telnet

查看:213
本文介绍了通过telnet获取imap正文消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道要获取所有消息正文,这是命令:

I know that to get all message body, this is the command:

[imap_code] UID FETCH [uid] BODY.PEEK[TEXT]

因此,我得到了整个消息正文。
但是我需要排除附件的一部分。我只想从发件人,文本和/或html写消息。

Thus I get the entire message body. But I need to exclude the part of the attachments. I want only message wrote from sender, text and/or html.

有办法吗?

这是带有附件的完整的原始html邮件

This is a full raw html mail with attachment

http:// pastebin。 com / FMEQdLM3

我只想获取

<div dir="ltr">This is the message body<div><ul><li>one</li><li>two</li></ul></div></div>

或纯文本(如果没有html版本)

or plain text if there isn't html version

推荐答案

消息以任意部分树的形式布置,父项为multipart / *或message / rfc822类型,子项为其他类型。 FETCH BODY [...] 允许任意提取这些部分中的任何一个。

Messages are laid out in an arbitrary tree of parts, with parent items being of the multipart/* or message/rfc822 type, and children being of other types. The FETCH BODY[...] lets arbitrarily extract any of these parts.

不幸的是,没有标准消息的布局。您可以获取BODYSTRUCTURE项以获取消息的MIME布局,但是用眼睛很难解析。

Unfortunately, there is no standard layout for messages. You can fetch the BODYSTRUCTURE item to get the MIME layout of a message, but it is very difficult to parse by eye.

话虽这么说,但有一些常见的消息布局。

That being said, there's a few common message layouts that will get you most of the way.

最简单的消息是只有一个正文的邮件,可以是text / html或text / plain。只需获取 BODY [TEXT]

The easiest is a message with just one body, either text/html or text/plain. Just fetch BODY[TEXT].

下一个是多格式,同时包含text / html和text /普通其MIME结构通常如下所示:

The next is multi-format, with both text/html and text/plain. Its MIME structure generally looks like this:

+ multipart/alternative   [TEXT]
|- text/plain             [1]
\- text/html              [2]

在这种情况下,您要获取 BODY [2]

In this case you want to fetch BODY[2].

如果邮件是带有附件的单身邮件,则看起来像这样:

If the message is single-body, with attachments, it will look something like this:

+ multipart/mixed or multipart/related  [TEXT]
|- text/html or text/plain              [1]
|- image/jpg                            [2]
| ...
\- image/gif

在这种情况下,您要 BODY [1]

最后两个都是:带附件的多格式主体。

Last is both of these: multi-format body with attachments. It will tend to look something like:

+ multipart/mixed or multipart/related  [TEXT]
|-+ multipart/alternative               [1]
| |- text/plain                         [1.1]
| \- text/html                          [1.2]
|- image/jpeg                           [2]
|- image/gif                            [3]
|...
\- image/png

在这种情况下,您可能想要 BODY [1.2] 。您的示例消息是这种类型的。



此外,主体可以采用Quoted-Printable或Base64编码进行编码。不幸的是,基准IMAP无法为服务器提供任何方式为您解码。如果消息是ascii,几乎可以读取Quoted-Printable,但是整个正文中都会有很多 = 逸出。如果是base64,就无法用肉眼解读。 BINARY IMAP扩展可以帮助解决这个问题,但这并未得到广泛部署。

In this case, you probably want BODY[1.2]. Your sample message is of this type.


In addition, the bodies may be encoded in Quoted-Printable or Base64 encoding. Unfortunately, Baseline IMAP does not provide any way for the server to decode this for you. Quoted-Printable can be mostly read if the message is ascii, but will have lots of = escapes throughout the body. If it's base64, you're not going to be able to decipher it by eye. The BINARY IMAP extension can help with this, but this is not widely deployed.

这篇关于通过telnet获取imap正文消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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