IMAP. Webhost handles server request poorly?

Still experimenting with imap.

I use imap_fetchstructure to find out which “section” html is within. This is the result:

stdClass Object
(
    [type] => 1
    [encoding] => 0
    [ifsubtype] => 1
    [subtype] => ALTERNATIVE
    [ifdescription] => 0
    [ifid] => 0
    [ifdisposition] => 0
    [ifdparameters] => 0
    [ifparameters] => 1
    [parameters] => Array
        (
            [0] => stdClass Object
                (
                    [attribute] => boundary
                    [value] => _000_HE1PR0301MB231489C11B2798F0F62B1C35F3890HE1PR0301MB2314_
                )

        )

    [parts] => Array
        (
            [0] => stdClass Object
                (
                    [type] => 0
                    [encoding] => 4
                    [ifsubtype] => 1
                    [subtype] => PLAIN
                    [ifdescription] => 0
                    [ifid] => 0
                    [lines] => 5
                    [bytes] => 53
                    [ifdisposition] => 0
                    [ifdparameters] => 0
                    [ifparameters] => 1
                    [parameters] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [attribute] => charset
                                    [value] => iso-8859-1
                                )

                        )

                )

            [1] => stdClass Object
                (
                    [type] => 0
                    [encoding] => 4
                    [ifsubtype] => 1
                    [subtype] => **HTML**
                    [ifdescription] => 0
                    [ifid] => 0
                    [lines] => 35
                    [bytes] => 1526
                    [ifdisposition] => 0
                    [ifdparameters] => 0
                    [ifparameters] => 1
                    [parameters] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [attribute] => charset
                                    [value] => iso-8859-1
                                )

                        )

                )

        )

) 

As you can see, HTML stands inside “1”. So I use imap_fetchbody and enter “1” or “1.0” inside the section parameter. This does not give me HTML, in this case I get a lot of other things.

However, when I use “2” or “2.0” in the parameter instead, I get back html. This part is not even printed in the result.

Is it me who does something wrong here, or is it my web host and their servers that have been badly programmed?

Yes. If you look at the manual (http://php.net/imap-fetchbody) the explanation for the section parameter reads

The part number. It is a string of integers delimited by period which index into a body part list as per the IMAP4 specification

So the section number is not the same as the array index in imap_fetchstructure().

Okey. Sometimes the function returns html when I enter 1.0 as section, and sometimes I need to use 2.0 when images are attached for example.

Can I call a function that returns “1.0, 2.0 or whatever number the HTML has in a specific mail”? If not, please feel free to give a solution for this.

One way maybe is to use “fetchmime” and loop over every possible part/section number until It returns “TEXT/HTML”? But the other way seems better if its possible, to tell the function “hey I want the HTML part” and it returns “1.0” for example.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.