private static function parseMimePart($part, $raw_mail, &$email) {
    $data = mailparse_msg_get_part_data($part);
    $type = ArrayUtil::findByKeyOrDefault($data, 'content-type', 'text/plain');

    $start = $data['starting-pos-body'];
    $end = $data['ending-pos-body'];
    $encoding = ArrayUtil::findByKeyOrDefault($data, 'transfer-encoding', '');
    $content = self::decodeContent(substr($raw_mail, $start, $end - $start),
                                   $encoding);

    if (isset($data['content-disposition'])) {
      $filename = ArrayUtil::findByKeyOrDefault(
          $data, 'disposition-filename', uniqid());
      $content_id = ArrayUtil::findByKeyOrNull($data, 'content-id');
      if ($content_id != null) {
        $content_id = "<$content_id>";
      }
      $email->addAttachment($filename, $content, $content_id);
    } else if ($type == 'text/html') {
      $email->setHtmlBody($content);
    } else if ($type == 'text/plain') {
      $email->setTextBody($content);
    } else if (!StringUtil::startsWith($type, 'multipart/')) {
      trigger_error("Ignore MIME part with unknown Content-Type $type. " .
                    "Did you forget to specifcy Content-Disposition header?",
                    E_USER_WARNING);
    }
  }
private static function parseMimePart($part, $raw_mail, &$email) {
    $data = mailparse_msg_get_part_data($part);
    $type = ArrayUtil::findByKeyOrDefault($data, 'content-type', 'text/plain');

    $start = $data['starting-pos-body'];
    $end = $data['ending-pos-body'];
    $encoding = ArrayUtil::findByKeyOrDefault($data, 'transfer-encoding', '');
    $content = self::decodeContent(substr($raw_mail, $start, $end - $start),
                                   $encoding);

    if (isset($data['content-disposition'])) {
      $filename = ArrayUtil::findByKeyOrDefault(
          $data, 'disposition-filename', uniqid());
      $content_id = ArrayUtil::findByKeyOrNull($data, 'content-id');
      if ($content_id != null) {
        $content_id = "<$content_id>";
      }
      $email->addAttachment($filename, $content, $content_id);
    } else if ($type == 'text/html') {
      $email->setHtmlBody($content);
    } else if ($type == 'text/plain') {
      $email->setTextBody($content);
    } else if (!StringUtil::startsWith($type, 'multipart/')) {
      trigger_error("Ignore MIME part with unknown Content-Type $type. " .
                    "Did you forget to specifcy Content-Disposition header?",
                    E_USER_WARNING);
    }
  }
private static function parseMimePart ( $ part , $ raw_mail , & $ email ) { $ data = mailparse_msg_get_part_data ( $ part ) ; $ type = ArrayUtil :: findByKeyOrDefault ( $ data , 'content-type' , 'text/plain' ) ; $ start = $ data [ 'starting-pos-body' ] ; $ end = $ data [ 'ending-pos-body' ] ; $ encoding = ArrayUtil :: findByKeyOrDefault ( $ data , 'transfer-encoding' , '' ) ; $ content = self :: decodeContent ( substr ( $ raw_mail , $ start , $ end - $ start ) , $ encoding ) ; if ( isset ( $ data [ 'content-disposition' ] ) ) { $ filename = ArrayUtil :: findByKeyOrDefault ( $ data , 'disposition-filename' , uniqid ( ) ) ; $ content_id = ArrayUtil :: findByKeyOrNull ( $ data , 'content-id' ) ; if ( $ content_id != null ) { $ content_id = "<$content_id>" ; } $ email -> addAttachment ( $ filename , $ content , $ content_id ) ; } else if ( $ type == 'text/html' ) { $ email -> setHtmlBody ( $ content ) ; } else if ( $ type == 'text/plain' ) { $ email -> setTextBody ( $ content ) ; } else if ( ! StringUtil :: startsWith ( $ type , 'multipart/' ) ) { trigger_error ( "Ignore MIME part with unknown Content-Type $type. " . "Did you forget to specifcy Content-Disposition header?" , E_USER_WARNING ) ; } }
Parse a MIME part and set the Message object accordingly.

@param resource $part A MIME part, returned from mailparse_msg_get_part,
to be parse.
@param string $raw_mail The string holding the raw content of the email
$part is extracted from.
@param Message& $email The Message object to be set.
Parse a MIME part and set the Message object accordingly .