是否可以仅下载不带附件的IMAP消息? [英] Is it possible to only download IMAP messages without attachments?

查看:61
本文介绍了是否可以仅下载不带附件的IMAP消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Net :: IMAP处理一堆电子邮件,但是我想跳过带有附件的电子邮件,因为它们花费的时间太长.有什么提示吗?最终,我希望尽快下载电子邮件的所有文本和HTML内容.现在,我一次获取一个UID,并与15个进程并行化(最大GMAIL允许),但是我却遇到了带有附件的消息.

I want to process a bunch of my emails with Net::IMAP, but I want to skip the ones with attachments because they take too long. Any hints? Ultimately, I'm looking to download all the text and HTML content of emails, as fast as possible. Right now, I'm fetching one UID at a time, and parallelizing it with 15 processes (the max GMAIL allows), but I'm hitting a snag on the messages with attachments.

imap = Net::IMAP.new('imap.gmail.com', 993, usessl = true, certs = nil, verify = false)
imap.authenticate('XOAUTH2', user.email, user.token)
mailbox = "[Gmail]/All Mail"
imap.select(mailbox)
message_id = 177
imap.fetch(message_id,'RFC822')[0].attr['RFC822'] # this fetches the whole message, including attachment, which makes it slow...

推荐答案

imap rfc不提供任何此类实现,但作为替代方案,如果邮件遵循rfc标准,则可能会黑客入侵,提取整个邮件邮件标题,并检查content type是否为multipart/mixed,然后确保邮件中存在附件.

imap rfc does not provide any such implementations but as an alternative there could be a possible hack, assuming that the mail is following the rfc standard, fetch the entire mail header of mail and check for content type if it is multipart/mixed then for sure an attachment exists in a mail.

在内容类型上,您可以在 http://en.wikipedia.org/wiki/MIME中获取更多信息

On content type you can get more info at http://en.wikipedia.org/wiki/MIME

这只是查找附件的一种可能方法.

This is just one of possible ways to find an attachment.

这篇关于是否可以仅下载不带附件的IMAP消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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