You are here

function MailhandlerPhpImapRetrieve::get_parts in Mailhandler 6.2

Same name and namespace in other branches
  1. 7.2 modules/mailhandler_php_imap/plugins/mailhandler/retrieve/MailhandlerPhpImapRetrieve.class.php \MailhandlerPhpImapRetrieve::get_parts()

Returns an array of parts as file objects

Parameters

$stream:

$msg_number:

Return value

An array of message parts (text body, html body, and attachments).

1 call to MailhandlerPhpImapRetrieve::get_parts()
MailhandlerPhpImapRetrieve::retrieve_message in modules/mailhandler_php_imap/plugins/mailhandler/retrieve/MailhandlerPhpImapRetrieve.class.php
Retrieve individual messages from an IMAP result.

File

modules/mailhandler_php_imap/plugins/mailhandler/retrieve/MailhandlerPhpImapRetrieve.class.php, line 186
Definition of MailhandlerPhpImapRetrieve class.

Class

MailhandlerPhpImapRetrieve
Retrieve messages using PHP IMAP library.

Code

function get_parts($stream, $msg_number) {
  $parts = array(
    'text_body' => '',
    'html_body' => '',
    'attachments' => array(),
  );

  // Load structure.
  if (!($structure = imap_fetchstructure($stream, $msg_number))) {
    mailhandler_report('error', 'Could not fetch structure for message number %msg_number', array(
      '%msg_number' => $msg_number,
    ));
  }

  // Get message parts.
  if ($structure->type == TYPEMULTIPART) {

    // Multi-part message.
    foreach ($structure->parts as $index => $sub_structure) {
      $this
        ->get_part($stream, $msg_number, $sub_structure, $index + 1, $parts);
    }
  }
  else {

    // Single-part message.
    $this
      ->get_part($stream, $msg_number, $structure, FALSE, $parts);
  }
  return $parts;
}