How to get raw email data with the imap extension?

前端 未结 4 2102
花落未央
花落未央 2021-02-19 20:04

I\'m looking for a way to download the whole raw email data (including attachment), similar to what you get by clicking \"Show Original\" in Gmail.

Currently, I can get

4条回答
  •  -上瘾入骨i
    2021-02-19 20:23

    My answer is "overcomplete", see Boy Baukema's answer for a more straight forward "view source" way of doing if you don't need the whole structure of the email.

    If you want to fetch all, you need to fetch

    • The headers imap_fetchheader.
    • Obtain the number of bodies the message has imap_fetchstructure.
    • Each mine-headers a body has imap_fetchmime.
    • Each body it has imap_fetchbody.

    As mime-message can have multiple bodies, you need to process each part after the other. To reduce load to the server use the FT_PREFETCHTEXT option for imap_fetchheader. Some example code about imap_fetchstructure in another answer that shows handling the imap connection and iterating over parts of a message already through encapsulation.

提交回复
热议问题