imap_fetchstructureDescriptionimap_fetchstructure() returns a large amount of information about a single message. It returns an object of message properties including:
In addition to the above list, the parameters property contains an array of attribute/value pairs. The parts property is an array with each element in the array an object containing the same properties as the top level object, except that the properties apply to each part. This can be a little difficult to comprehend but examining the output of this function can lead to a greater understanding. ExampleExample 602. Dump message structure <?php $imap = imap_open("{localhost}INBOX","graeme","inferno"); // delibertely choose a message with an attachment $message = 7; // duimp out every property of the message echo "<pre>\n\n"; print_r(imap_fetchstructure($imap, $message)); echo "\n\n</pre>"; imap_close($imap); ?> Example 603. File attachment information <?php $imap = imap_open("{localhost}INBOX","graeme","inferno"); // delibertely choose a message with an attachment $message = 7; $info = imap_fetchstructure($imap, $message); // find out how may parts the object has $numparts = count($info->parts); // find if if multipart message if ($numparts > 1) { echo "More then one part<BR>"; foreach ($info->parts as $part) { if ($part->disposition == "INLINE") { // inline message. Show number of lines printf("Inline message has %s lines<BR>", $part->lines); } elseif ($part->disposition == "ATTACHMENT") { // an attachment echo "Attachment found!"; // print out the file name echo "Filename: ", $part->dparameters[0]->value; } } } else { // only one part so get some useful info echo "Only one part"; } imap_close($imap); ?> Output More then one part Inline message has 9 lines Attachment found!Filename: sound1.wav
PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing
(Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch).
This material may be distributed only subject to the terms and conditions set forth
in the Open Publication License, v1.0 or later (the latest version is presently available at
http://www.opencontent.org/openpub/).
The authors of this book have elected not to choose any options under the OPL. This online book was obtained
from http://www.fooassociates.com/phpfer/
and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4
for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All
persons and entities shall have neither liability nor responsibility to any person or entity with respect to
any loss or damage arising from the information contained in this book.
|