Can i download IMAP messages without attachments?

I want to process a bunch of my emails using Net :: IMAP, but I want to skip them with attachments because they take too much time. Any hints? Ultimately, I want to load all the text and content of the HTML messages as quickly as possible. Right now I am collecting one UID at a time and parallelizing it with 15 processes (GMAIL is most acceptable), but I click on 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... 
+1
source share
1 answer

imap rfc does not provide such implementations, but as an alternative there may be a possible hack, assuming that the mail conforms to the rfc standard, extracts the entire mail header of the mail and checks for the content type , if it is multipart/mixed then there is certainly an attachment in the letter.

For the type of content you can get more information at http://en.wikipedia.org/wiki/MIME

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

+2
source

Source: https://habr.com/ru/post/947147/


All Articles