Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell 通过telnet获取imap正文消息_Shell_Email_Imap_Telnet - Fatal编程技术网

Shell 通过telnet获取imap正文消息

Shell 通过telnet获取imap正文消息,shell,email,imap,telnet,Shell,Email,Imap,Telnet,我知道要获取所有消息体,以下是命令: [imap_code] UID FETCH [uid] BODY.PEEK[TEXT] 因此,我得到了整个消息体。 但我需要排除附件的部分。我只想从发件人写的消息,文本和/或html 有办法吗 这是一封带有附件的完整原始html邮件 我只想 <div dir="ltr">This is the message body<div><ul><li>one</li><li>two</

我知道要获取所有消息体,以下是命令:

[imap_code] UID FETCH [uid] BODY.PEEK[TEXT]
因此,我得到了整个消息体。 但我需要排除附件的部分。我只想从发件人写的消息,文本和/或html

有办法吗

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

我只想

<div dir="ltr">This is the message body<div><ul><li>one</li><li>two</li></ul></div></div>
这是消息正文
  • one
  • two

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

消息以任意部分树的形式排列,父项为multipart/*或message/rfc822类型,子项为其他类型。
fetchbody[…]
允许任意提取这些部分中的任何部分

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

也就是说,有一些常见的消息布局可以让您在大部分时间内都可以使用

最简单的是一条只有一个正文的消息,text/html或text/plain。只需获取
正文[文本]

下一种是多格式,既有text/html,也有text/plain。其MIME结构通常如下所示:

+ multipart/alternative   [TEXT]
|- text/plain             [1]
\- text/html              [2]
+ multipart/mixed or multipart/related  [TEXT]
|- text/html or text/plain              [1]
|- image/jpg                            [2]
| ...
\- image/gif
在本例中,您希望获取
正文[2]

如果邮件是带有附件的单体邮件,则其外观如下:

+ multipart/alternative   [TEXT]
|- text/plain             [1]
\- text/html              [2]
+ multipart/mixed or multipart/related  [TEXT]
|- text/html or text/plain              [1]
|- image/jpg                            [2]
| ...
\- image/gif
在这种情况下,您需要
正文[1]

最后是这两个:带附件的多格式正文。它会看起来像:

+ 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]
。您的示例消息属于此类型。

此外,主体可采用引用的可打印或Base64编码进行编码。不幸的是,基线IMAP没有为服务器提供任何方式来为您解码。如果消息是ascii码,则大多数情况下可以读取引用的可打印消息,但在整个正文中会有大量转义符。如果它是base64,你将无法用肉眼破译它。可以帮助解决这一问题,但尚未广泛应用。

请使用实际日志中的示例条目和您期望的实际输出更新问题。我提供了一个示例。您的所有消息都与此示例类似吗?[请原谅我的ascii艺术树]有人知道这个答案有多棒吗?那么,试着在任何RFC中找到这种细节。。。哦,马上接受这个,给这个人买杯咖啡。@suchislife谢谢你的好话:)