IMAP 附件检索命令
我正在使用 IMAP 开发邮件客户端,并且正在寻找用于接收消息附件的命令。
I am working on a mail client using IMAP and I am looking for the command for receiving the attachments of a message.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
所有消息信息均使用
FETCH
命令检索。但是,对于如何使用它,您有两种选择。首先,您可以逐字检索整个电子邮件。在这种情况下,您需要在客户端中包含一个 MIME 解析器来确定消息的结构。 (每个平台至少有一两个流行的 MIME 解析器;由于您没有告诉我们您正在编码的内容,所以我无法为您推荐一个。)一旦您从 MIME 解析器获得消息结构,您就可以将需要一些客户端逻辑来确定哪些部分是附件。值得一看 RFC 2183 来帮助您入门。一般来说,以“
attachment
”开头的Content-Disposition
部分将是附件,但所有邮件客户端作者都会经历一个尝试和错误的阶段才能获得正确的结果。为了下载整个电子邮件,您需要发出 IMAP 命令其次,您可以通过发出
FETCH BODYSTRUCTURE
(注意:没有方括号)让 IMAP 服务器为您解析消息结构。您必须自己解析返回的 BODYSTRUCTURE 数据; IMAP RFC 解释了格式并给出了一些示例。一旦确定了您感兴趣的部分,您就可以为可显示的消息正文发出
FETCH
。然后,您的客户端可以只列出消息附件(从BODY
响应中解析出来),然后可以返回并在用户单击它们时FETCH
它们。因此,您要发出的 IMAP 命令将类似于:All message info is retrieved using the
FETCH
command. You have two options on how to use it, however.First, you can retrieve the entire email message, verbatim. In that case, you're going to need to include a MIME parser in your client to figure out the structure of the message. (Each platform has at least one or two popular MIME parsers; since you haven't told us what you're coding in, I can't recommend one for you.) Once you get the message structure from your MIME parser, you'll need some client logic to determine which parts are attachments. It's worth looking at RFC 2183 to get you started. In general, parts with a
Content-Disposition
starting with "attachment
" are going to be attachments, but all mail client authors go through a phase of trial and error getting it right. In order to download the entire email message, you'd issue the IMAP commandSecond, you can have the IMAP server parse the message structure for you by issuing a
FETCH BODYSTRUCTURE
(note: no square brackets). You'll have to parse the returned BODYSTRUCTURE data yourself; the IMAP RFC explains the format and gives a few examples.Once you've determined which parts you're interested in, you can issue a
FETCH
for the displayable message body. Your client can then just list the message attachments (parsed out of theBODY
response) and can then go back andFETCH
them if the user clicks on them. So the IMAP commands you'd be issuing would be along the lines of:我相信您正在寻找的是 IMAP v4 FETCH 命令。
I believe what you are looking for is the IMAP v4 FETCH command.
您可以使用 Context.IO 的文件资源来快速轻松地获取附件。
http://context.io/docs/2.0/accounts/files#get
You could use Context.IO's files resource to quickly and easily fetch attachments.
http://context.io/docs/2.0/accounts/files#get