★ wanayoo — archive 1999 http://www.php.net/manual/function.imap-fetchbody.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to IMAP
Quick Reference
German version of this pageJapanese version of this pageItalian version of this pageFrench version of this pageHungarian version of this page
IMAP
* imap_append
* imap_base64
* imap_body
* imap_check
* imap_close
* imap_createmailbox
* imap_delete
* imap_deletemailbox
* imap_expunge
* imap_fetchbody
* imap_fetchstructure
* imap_header
* imap_rfc822_parse_headers
* imap_headers
* imap_listmailbox
* imap_getmailboxes
* imap_listsubscribed
* imap_getsubscribed
* imap_mail_copy
* imap_mail_move
* imap_num_msg
* imap_num_recent
* imap_open
* imap_ping
* imap_renamemailbox
* imap_reopen
* imap_subscribe
* imap_undelete
* imap_unsubscribe
* imap_qprint
* imap_8bit
* imap_binary
* imap_scanmailbox
* imap_mailboxmsginfo
* imap_rfc822_write_address
* imap_rfc822_parse_adrlist
* imap_setflag_full
* imap_clearflag_full
* imap_sort
* imap_fetchheader
* imap_uid
* imap_msgno
* imap_search
* imap_last_error
* imap_errors
* imap_alerts
* imap_status
* imap_utf7_decode
* imap_utf7_encode
* imap_utf8
* imap_fetch_overview
* imap_mime_header_decode
* imap_mail_compose
* imap_mail
Manual: imap_fetchbody
View the source code for this pageSearch the site



Previous page
 imap_expunge
 Updated
Sat, 12 Aug 2000
imap_fetchstructure 
Next page


imap_fetchbody

(PHP3 , PHP4 )

imap_fetchbody --  Fetch a particular section of the body of the message

Description

string imap_fetchbody (int imap_stream, int msg_number, string part_number [, flags flags])

This function causes a fetch of a particular section of the body of the specified messages as a text string and returns that text string. The section specification is a string of integers delimited by period which index into a body part list as per the IMAP4 specification. Body parts are not decoded by this function.

The options for imap_fetchbody() is a bitmask with one or more of the following:

  • FT_UID - The msg_number is a UID

  • FT_PEEK - Do not set the \Seen flag if not already set

  • FT_INTERNAL - The return string is in "internal" format, without any attempt to canonicalize CRLF.


User Contributed Notes: imap_fetchbody


cleong@organic.com
04-Apr-2000 09:13
Passing the part number 0 to imap_fetchbody() appears to yield the head of the message, that is, all the header fields.

Note that IMAP "part numbers" (a misnomer if you ask me) starts at 1. So the first part of a multipart message has the part number "1". The first sub-part of part 1 has "1.1". The second sub-part of part 1.1 has "1.1.2" and so on.



cleong@organic.com
04-Apr-2000 09:19
Here's a routine that yields the part of a message with a particular MIME type:

<PRE>
function get_mime_type(&$structure)
{
$primary_mime_type = array("TEXT", "MULTIPART", "MESSAGE", "APPLICATION", "AUDIO", "IMAGE", "VIDEO", "OTHER");
if($structure->subtype)
{
return $primary_mime_type[(int) $structure->type] . '/' . $structure->subtype;
}
return "TEXT/PLAIN";
}

function get_part($stream, $msg_number, $mime_type, $structure = false, $part_number = false)
{
if(!$structure)
{
$structure = imap_fetchstructure($stream, $msg_number);
}
if($structure)
{
if($mime_type == get_mime_type($structure))
{
if(!$part_number)
{
$part_number = "1";
}
$text = imap_fetchbody($stream, $msg_number, $part_number);
if($structure->encoding == 3)
{
return imap_base64($text);
}
else if($structure->encoding == 4)
{
return imap_qprint($text);
}
else
{
return $text;
}
}
if($structure->type == 1) /* multipart */
{
while(list($index, $sub_structure) = each($structure->parts))
{
if($part_number)
{
$prefix = $part_number . '.';
}
$data = get_part($stream, $msg_number, $mime_type, $sub_structure, $prefix . ($index + 1));
if($data)
{
return $data;
}
}
}
}
return false;
}

// get plain text
$data = get_part($stream, $msg_number, "TEXT/PLAIN");
// get HTML text
$data = get_part($stream, $msg_number, "TEXT/HTML");

</PRE>

Right now only the first part with the matching MIME type is returned. A more useful version would create an array and return all matching parts (for GIFs, for instance).



mamurillo@rslcom.es
11-May-2000 05:39
Investigating and fighting with imap functions I think I've discovered that counting parts for imap_fetchbody function fails with forwarded messages.
When I count parts (1, 2, 2.1 etc..) it seems that for a forwarded message insert one part more. For example the part counted as 2.1.2 is the part 2.2 for the imap function. With normal multipart messages do it well, but forwarded messages.Could anyone confirm that I think I dicovered?
If is true take care about this class of message.



sborrill@precedence.co.uk
10-Aug-2000 01:35
Contrary to the top message, the IMAP4 spec can be found at http://www.imap.org/papers/docs/rfc2060.html

The relevant section is 6.4.5



 About Notes


Previous page
 imap_expunge
 Updated
Sat, 12 Aug 2000
imap_fetchstructure 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.