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);
    }
  }