Mail_IMAP::getRelatedParts()

array|FALSE getRelatedParts(int &$mid, str &$pid = '0'[, array $secureMIME = array()])

Retrieves related parts if the message is a multipart/related message, returns FALSE if there are no related parts.

Limiting the types of files with the $secureMIME argument

The optional $secureMIME argument allows the types of files allowed in a multipart/related message to be limited. This feature can be used to prevent the browser from automatically downloading potentially malicious files embedded in a message.

<?php

  
require_once 'Mail/IMAP.php';

  
$msg =& new Mail_IMAP();

  
// Open up a mail connection
  
if (!$msg->connect('imap://'.urlencode('user@domain.com').':password@mail.example.com:143/INBOX')) {
      echo 
"<span style='font-weight: bold;'>Error:</span> Unable to build a connection.<br/> ";
      echo 
$msg->alerts();
      echo 
$msg->errors();
      
// See if ErrorStack has any errors.
      
if ($msg->error->hasErrors()) {
          echo 
"<pre> ";
          
var_dump($msg->error->getErrors(TRUE));
          echo 
"</pre> ";
      }
  }

  
// Get Parts
  
$msg->getParts($_GET['mid'], $_GET['pid']);

  
// Get Related Parts
  // The MIME types of the related parts are limited in the $secureMIME argument.
  
$related $msg->getRelatedParts($_GET['mid'], $_GET['pid'], array('text/plain''text/html''text/css''image/jpeg''image/pjpeg''image/gif''image/png''image/x-png''application/xml''application/xhtml+xml''text/xml'));

  if (
$related) {
      
// Do your own CID replacement algorithm
      // Dump information to see how it is structured
      
echo "<pre> ";
      
var_dump($related);
      echo 
"</pre> ";
  }

?>

Method summary:

param int &$mid message id
param str &$pid part id.
param bool $secureMIME (optional) See above.
return array|FALSE
throws ErrorStack: Message structure does not exist. The method was unable to find the message structure associated with the message id passed.
access public
Execution time: 0.07 seconds