imap.fetch(uid,'RFC822')[0].attr['RFC822'] 返回整个消息,包括附件吗?
想知道是否有办法可以避免获取附件。
Wondering if there's a way I can avoid fetching the attachments as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,它返回整个电子邮件源。附件被编码为电子邮件部分。
您可以使用 Ruby Mail 库 提取所有附件。
Yes, it returns the entire email source. The attachments are encoded as email parts.
You can use the Ruby Mail library to extracts all the attachments.
如果您只想下载电子邮件正文,则没有一种干净的方法可以做到这一点(至少我没有发现)。
我要做的就是首先下载标题和正文结构。一旦我有了标题,我就可以确定它是什么类型的电子邮件(多部分、替代或只是单一正文的电子邮件)。
一旦我知道了结构,我就可以下载纯文本或 html 正文部分作为正文部分。
这有帮助吗?
——戴夫
If all you want to do, is download the email body(ies), there isn't a clean way of doing this (at least none that I disovered).
What I had to do, was first download the headers and the body structures. Once I had the headers, I could determine what type of email it was (multi-part, alternative, or just a single bodied email).
Once I knew the structure, I could download the plain text or html body part as a body section.
Does that help?
--Dave
我不知道 ruby ,但它可以只获取电子邮件标题来完成。
我正在用 Python 获取电子邮件标头,如下所示:
其中 uid_lst 是您要获取的电子邮件的 uid 列表。
注意:标头字段 Content-Type = 'Multipart-Mixed' 值的电子邮件有一个附件。
I don't know about ruby , but it can be done only fetching Email Header.
I am Fetching Email header in Python like below:
where uid_lst is the list of uids of emails which you want to fetch.
Note: Email which has value of header field Content-Type = 'Multipart-Mixed' has an attachment.