I'm having a little trouble figuring out these IMAP functions. I got them compiled and working, I just can't figure out how to use them properly.

I'm able to connect to a mailbox, create a list of UIDs, loop through that list and get all of the envelope information for each email. But I'm having trouble with the bodies.

What I want is to read the text/plain part of each email, unless the email is not a multi-part message, then I'll take the whole body.

I can get the whole body easily enough, but I can't figure out how to check to see if an email is multipart or not, and I can't figure out how to properly select the text/plain portion and only the text/plain portion of an email. 😕

    I'd prefer to just do it myself, rather than use someone else's class.

      Months ago I had the same problem... using IMAP is confusing... I used a lot of print_r() and var_dump() to check whats inside the arrays that those functions return.

      Not only you have to look to the info, but there are some parts that show how you should read the body and headers.

      It is a good idea to check PHPMailer or other, not to use them, but to check how they did it

        a month later

        So I finally got back to trying to solve this problem. So I figured out how imap_fetchstructure() works, and I understand what it returns. Here's what I don't understand though:

        So imap_fetchstructure() returns a object. object->part contains an array of objects. Those objects correspond to "parts" of a multipart message. So it's pretty each to loop through that array, checking each object. [remember, my goal is to find and 'get' only the text/plain portion of an email]

        Here's what I don't understand though. So once I find the plain text part of a multipart message, how do I select it with imap_fetchbody()?

        imap_fetchbody() is looking for you to specify which part you want with a code like "1.1". But how do you get that code from imap_fetchstructure()?

        I think I now get how both of these functions work, I just don't understand how I make them work together.

          Write a Reply...