Smiling Souls

Steeped in the delicious tea like leaves of anthroposophy for the evolving soul.


mixed getBody(int &$mid,[ str $pid = "1" [, int $action[, str $get_mime = "text/html" [, int $attempt]]]])

Searches $structure property set in Mail_IMAP::_declareParts() for a displayable message. If the part id passed is message/rfc822 (an attached email message) getBody automatically looks in subparts for a displayable body.

Attempts to return a text/html inline message part by default. And will automatically attempt to find a text/plain part if a text/html part could not be found. This can be reversed to find a text/plain part by default and a text/html part if a text/plain part couldn"t be found by specifying the default MIME type in the $get_mime argument. The $attempt argument is used internally to track the method"s attempt at finding a suitable message part to display.

By default getBody returns an array containing four associative indices; "ftype", "fname", "charset" and "message". "ftype" contains the MIME type of the message, "fname", the original file name, if any (empty string otherwise), "charset" contains information about the character set and "message", contains the message body itself, which is returned decoded from base64 or quoted-printable if either of those encoding types are specified, returns untouched otherwise. Returns FALSE on failure.

Internally, getBody calls on two methods, Mail_IMAP::_checkIfParsed() (protected) and Mail_IMAP::_scanMultipart() (private).

$action constants

The $action argument of getBody may accept any one of the following constants which toggles how the function returns data.

Constant Purpose
MAIL_IMAPv2_BODY (default value) If the message part is message/rfc822 searches subparts for a displayable body and returns the body decoded as part of an array.
MAIL_IMAPv2_LITERAL Return the message part for the specified $part id without searching subparts or decoding the message (may return unparsed message).
MAIL_IMAPv2_LITERAL_DECODE Same as MAIL_IMAP_LITERALv2, except message decoding is attempted from base64 or quoted-printable encoding, returns undecoded string if decoding failed.

Example of retrieving the message body:

<?php // Simple viewer for message body or attachments // Browser will attempt to display MIME types it recognizes, // otherwise it'll present the user with a save as dialouge. // IMAP.message.php $msg =& new Mail_IMAP("imap://"); // message id and part id passed by get method to viewer script $body = $msg->getBody($_GET["mid"], $_GET["pid"]); // Output header changes for MIME type header("Content-type: ".$body["ftype"]); echo $body["message"]; ?>

Method summary:

param int &$mid message id
param str $pid part id
param int $action
param str $get_mime MIME type to look for.
param int $attempt
return array|string|FALSE
access public
access PHP 4.2.0
see $structure


There are no comments posted at this time.

Leave a Comment

Simple HTML is allowed: <code>, <b>, <i>, <u>, <var>, <strong>, <em>, <blockquote>, <ul>, <ol>, <li>, <p> (no attributes). All spacing and line breaks in your comment will be preserved.

* All comments are moderated and are subject to approval.
Your comment will appear once it has been approved.
Posting multiple times will not expedite the approval process.

Comments are closed at this time.

© Copyright 2015 Hot Toddy, All Rights Reserved.