Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
PHP: imap_body - Manual
[go: Go Back, main page]

PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<imap_binaryimap_bodystruct" width="11" height="7"/>
view the version of this page
Last updated: Fri, 28 Oct 2005

imap_body

(PHP 3, PHP 4, PHP 5)

imap_body -- Read the message body

Description

string imap_body ( resource imap_stream, int msg_number [, int options] )

imap_body() returns the body of the message, numbered msg_number in the current mailbox.

The optional options are a bit mask 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, will not canonicalize to CRLF.

imap_body() will only return a verbatim copy of the message body. To extract single parts of a multipart MIME-encoded message you have to use imap_fetchstructure() to analyze its structure and imap_fetchbody() to extract a copy of a single body component.



add a note add a note User Contributed Notes
imap_body
Ortreum
21-Oct-2005 08:55
This is a little script to create a query for all emails-addresses that are in your mails in this folder. So you are able to flag unreachable/wrong emailaddresses if this folder has a filter for daemon-addresses.
It's not checking or setting the flag for 'read'.

<?php
$rootfolder
= 'Returned';
$imaphost = '{imap.domain.org:143}' . $rootfolder;
$mbox = imap_open($imaphost, $imap_user, $imap_password, OP_HALFOPEN) or die("can't connect: " . imap_last_error());
$list = imap_getmailboxes ($mbox, $imaphost, "*");
$emaillist = array();
if (
is_array ($list))
{
  
reset ($list);
   while (list(
$key, $val) = each($list))
   {
      
// get folder name without root folder
      
$name = substr(imap_utf7_decode($val->name), strlen($imaphost));

      
$status = imap_status ($mbox, $imaphost . $name, SA_ALL);
       if(
$status) {
          
$ilen = $status->messages;

          
// get every message body
          
for ($i = 1; $i <= $ilen; $i++)
           {
              
// don't touch the read-flag
              
$message = imap_body($mbox, $i, FT_PEEK);
              
              
// lower case
              
$message = strtolower($message);
              
              
// clear not needed characters
              
$message = str_replace( "\t", " ", $message);
              
$message = str_replace( "\n", " ", $message);
              
$message = str_replace( "\r", " ", $message);
              
$message = str_replace';', " ", $message);
              
$message = str_replace'"', " ", $message);
              
$message = str_replace( "\\", " ", $message);
              
$message = str_replace"/", " ", $message);
              
$message = str_replace("=3d", " ", $message);
              
$message = str_replace"=", " ", $message);
              
$message = str_replace":", " ", $message);
              
$message = str_replace"<", " ", $message);
              
$message = str_replace">", " ", $message);
              
$message = str_replace"[", " ", $message);
              
$message = str_replace"]", " ", $message);
              
$message = str_replace"'", " ", $message);
              
              
// get a list of all single words
              
$wordlist = explode(" ", $message);
              
$ilenword = count($wordlist);
               for (
$iword = 0; $iword < $ilenword; $iword++)
               {
                  
$email = $wordlist[$iword];
                  
                  
// has this "email" exact 1 @ ?
                  
if (("$email" != "") && ((strlen(str_replace("@", "", $email)) + 1) == strlen($email)))
                   {
                      
// is this email in list yet?
                      
if (array_search($email, $emaillist) . "" == "")
                       {
                          
// add email
                          
$emaillist[count($emaillist)] = $email;
                       }
                   }
               }
           }
       }
       else
       {
           print
"imap_status failed: " . imap_last_error() . "\n";
       }
   }
}
else
{
   print
"imap_getmailboxes failed: " . imap_last_error() . "\n";
}

// create a query
$query = "UPDATE tblUsers SET US_EmailFailed = 1 WHERE US_Email IN (''";
$ilen = count($emaillist);
for (
$i = 0; $i < $ilen; $i++)
{
  
$query .= ",'" . $emaillist[$i] . "'";
}
$query .= ")";
imap_close($mbox);
?>

Gtz ...
webmaster at pedro dot frandt dot com
07-Mar-2005 02:36
I was having a problem where I was connecting to a POP3 server and no matter what I did PHP always said there was as many unread messages as there was messages in total.

After about an hour of Googling I found this in a comment in an existing file:

> POP3 considers ALL messages as "unseen" and/or "recent" because POP3 does not retain such info as seen or unseen

I hope this helps you save some time.
sito
11-Sep-2003 10:09
Usually, not multipart or 'zero-parts' messages are displayed with imap_body, but you may have a multipart message with no parts. For this type, displaying with imap_body, you may get unwanted data(like 'this is a MIME...' and boundary string), so a better solution is use imap_fetchbody.

<?php
// Type 1 is 'multipart'
if(($struct->type==1) && (sizeOf($struct->parts)==0))
{
   echo(
imap_fetchbody($mailConn,$msg,"1"));
}
?>

Where $struct is the object returned by imap_fetchstructure.
jh at junetz dot de
02-Jul-2003 08:37
If you read the description of options carefully you'll see that imap_body() marks messages as read (SEEN) by default. Note that if you parse messages containing MIME using some of the other imap functions and don't call imap_body() in such a case, the messages will probably still be unread.

For example in a webmail environment you may have collected enough information to display a particular message simply by parsing the MIME content with no need to call imap_body(). In this case you can use imap_setflag_full(stream, sequence, "\\SEEN", options) to explicitly mark it as read.
gryu at korea dot com
18-May-2001 08:05
There is another constants for flags argument...

(below is quoted form Core PHP Programming 2nd Edition)

FT_NOT : do not fetch header lines.

FT_PREFETCHTEXT : fetch the text when getting the header.
------

Ryu, Gwang
http://occam.com.ne.kr, http://gpgstudy.com

<imap_binaryimap_bodystruct" width="11" height="7"/>
 Last updated: Fri, 28 Oct 2005
show source | credits | sitemap | contact | advertising | mirror sites 
Copyright © 2001-2005 The PHP Group
All rights reserved.
This mirror generously provided by: PacketBusiness, Inc.
Last updated: Sat Nov 12 11:36:05 2005 JST