简体   繁体   中英

Does imap.fetch(uid,'RFC822')[0].attr['RFC822'] return the entire message, including attachments?

想知道是否有一种方法可以避免获取附件。

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.

I don't know about ruby , but it can be done only fetching Email Header.
I am Fetching Email header in Python like below:

    resp, data = obj.uid('FETCH' , ','.join(map(str,uid_lst)),'(RFC822.HEADER RFC822.SIZE)')

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM