function GetContent($part, &$attachments, $post_id, $poster, $config) { extract($config); //global $charset, $encoding; DebugEcho('----'); $meta_return = ''; if (property_exists($part, "ctype_primary")) { DebugEcho("GetContent: primary= " . $part->ctype_primary . ", secondary = " . $part->ctype_secondary); //DebugDump($part); } DecodeBase64Part($part); //look for banned file names if (property_exists($part, 'ctype_parameters') && is_array($part->ctype_parameters) && array_key_exists('name', $part->ctype_parameters)) { if (isBannedFileName($part->ctype_parameters['name'], $banned_files_list)) { return NULL; } } if (property_exists($part, "ctype_primary") && $part->ctype_primary == "application" && $part->ctype_secondary == "octet-stream") { if (property_exists($part, 'disposition') && $part->disposition == "attachment") { //nothing } else { DebugEcho("GetContent: decoding application/octet-stream"); $mimeDecodedEmail = DecodeMIMEMail($part->body); filter_PreferedText($mimeDecodedEmail, $prefer_text_type); foreach ($mimeDecodedEmail->parts as $section) { $meta_return .= GetContent($section, $attachments, $post_id, $poster, $config); } } } if (property_exists($part, "ctype_primary") && $part->ctype_primary == "multipart" && $part->ctype_secondary == "appledouble") { DebugEcho("multipart appledouble"); $mimeDecodedEmail = DecodeMIMEMail("Content-Type: multipart/mixed; boundary=" . $part->ctype_parameters["boundary"] . "\n" . $part->body); filter_PreferedText($mimeDecodedEmail, $prefer_text_type); filter_AppleFile($mimeDecodedEmail); foreach ($mimeDecodedEmail->parts as $section) { $meta_return .= GetContent($section, $attachments, $post_id, $poster, $config); } } else { $filename = ""; if (property_exists($part, 'ctype_parameters') && is_array($part->ctype_parameters) && array_key_exists('name', $part->ctype_parameters)) { $filename = $part->ctype_parameters['name']; } elseif (property_exists($part, 'd_parameters') && is_array($part->d_parameters) && array_key_exists('filename', $part->d_parameters)) { $filename = $part->d_parameters['filename']; } $filename = sanitize_file_name($filename); $fileext = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); DebugEcho("GetContent: file name '{$filename}'"); DebugEcho("GetContent: extension '{$fileext}'"); $mimetype_primary = ""; $mimetype_secondary = ""; if (property_exists($part, "ctype_primary")) { $mimetype_primary = strtolower($part->ctype_primary); } if (property_exists($part, "ctype_secondary")) { $mimetype_secondary = strtolower($part->ctype_secondary); } $typeinfo = wp_check_filetype($filename); //DebugDump($typeinfo); if (!empty($typeinfo['type'])) { DebugEcho("GetContent: secondary lookup found " . $typeinfo['type']); $mimeparts = explode('/', strtolower($typeinfo['type'])); $mimetype_primary = $mimeparts[0]; $mimetype_secondary = $mimeparts[1]; } else { DebugEcho("GetContent: secondary lookup failed, checking configured extensions"); if (in_array($fileext, $audiotypes)) { DebugEcho("GetContent: found audio extension"); $mimetype_primary = 'audio'; $mimetype_secondary = $fileext; } elseif (in_array($fileext, array_merge($video1types, $video2types))) { DebugEcho("GetContent: found video extension"); $mimetype_primary = 'video'; $mimetype_secondary = $fileext; } else { DebugEcho("GetContent: found no extension"); } } DebugEcho("GetContent: mimetype {$mimetype_primary}/{$mimetype_secondary}"); switch ($mimetype_primary) { case 'multipart': DebugEcho("multipart: " . count($part->parts)); //DebugDump($part); filter_PreferedText($part, $prefer_text_type); foreach ($part->parts as $section) { //DebugDump($section->headers); $meta_return .= GetContent($section, $attachments, $post_id, $poster, $config); } break; case 'text': DebugEcho("ctype_primary: text"); //DebugDump($part); $charset = ""; if (property_exists($part, 'ctype_parameters') && array_key_exists('charset', $part->ctype_parameters) && !empty($part->ctype_parameters['charset'])) { $charset = $part->ctype_parameters['charset']; DebugEcho("charset: {$charset}"); } $encoding = ""; if (array_key_exists('content-transfer-encoding', $part->headers) && !empty($part->headers['content-transfer-encoding'])) { $encoding = $part->headers['content-transfer-encoding']; DebugEcho("encoding: {$encoding}"); } if (array_key_exists('content-transfer-encoding', $part->headers)) { //DebugDump($part); $part->body = HandleMessageEncoding($encoding, $charset, $part->body, $message_encoding, $message_dequote); if (!empty($charset)) { $part->ctype_parameters['charset'] = ""; //reset so we don't double decode } //DebugDump($part); } if (array_key_exists('disposition', $part) && $part->disposition == 'attachment') { DebugEcho("text Attachement: {$filename}"); if (!preg_match('/ATT\\d\\d\\d\\d\\d.txt/i', $filename)) { $file_id = postie_media_handle_upload($part, $post_id, $poster, $generate_thumbnails); if (!is_wp_error($file_id)) { $file = wp_get_attachment_url($file_id); $icon = chooseAttachmentIcon($file, $mimetype_primary, $mimetype_secondary, $icon_set, $icon_size); $attachments["html"][$filename] = "<a href='{$file}'>" . $icon . $filename . '</a>' . "\n"; DebugEcho("text attachment: adding '{$filename}'"); } else { LogInfo($file_id->get_error_message()); } } else { DebugEcho("text attachment: skipping '{$filename}'"); } } else { //go through each sub-section if ($mimetype_secondary == 'enriched') { //convert enriched text to HTML DebugEcho("enriched"); $meta_return .= filter_Etf2HTML($part->body) . "\n"; } elseif ($mimetype_secondary == 'html') { //strip excess HTML DebugEcho("html"); $meta_return .= filter_CleanHtml($part->body) . "\n"; } elseif ($mimetype_secondary == 'plain') { DebugEcho("plain text"); //DebugDump($part); DebugEcho("body text"); if ($allow_html_in_body) { DebugEcho("html allowed"); $meta_return .= $part->body; //$meta_return = "<div>$meta_return</div>\n"; } else { DebugEcho("html not allowed (htmlentities)"); $meta_return .= htmlentities($part->body); } $meta_return = filter_StripPGP($meta_return); //DebugEcho("meta return: $meta_return"); } else { DebugEcho("text Attachement wo disposition: {$filename}"); $file_id = postie_media_handle_upload($part, $post_id, $poster); if (!is_wp_error($file_id)) { $file = wp_get_attachment_url($file_id); $icon = chooseAttachmentIcon($file, $mimetype_primary, $mimetype_secondary, $icon_set, $icon_size); $attachments["html"][$filename] = "<a href='{$file}'>" . $icon . $filename . '</a>' . "\n"; } else { LogInfo($file_id->get_error_message()); } } } break; case 'image': DebugEcho("image Attachement: {$filename}"); $file_id = postie_media_handle_upload($part, $post_id, $poster, $generate_thumbnails); if (!is_wp_error($file_id)) { //featured image logic //set the first image we come across as the featured image DebugEcho("has_post_thumbnail: " . has_post_thumbnail($post_id)); //DebugEcho("get_the_post_thumbnail: " .get_the_post_thumbnail($post_id)); if ($featured_image && !has_post_thumbnail($post_id)) { DebugEcho("featured image: {$file_id}"); set_post_thumbnail($post_id, $file_id); } $file = wp_get_attachment_url($file_id); $cid = ""; if (array_key_exists('content-id', $part->headers)) { $cid = trim($part->headers["content-id"], "<>"); DebugEcho("found cid: {$cid}"); } $the_post = get_post($file_id); $attachments["html"][$filename] = parseTemplate($file_id, $mimetype_primary, $imagetemplate, $filename); if ($cid) { $attachments["cids"][$cid] = array($file, count($attachments["html"]) - 1); DebugEcho("CID Attachement: {$cid}"); } } else { LogInfo("image error: " . $file_id->get_error_message()); } break; case 'audio': //DebugDump($part->headers); DebugEcho("audio Attachement: {$filename}"); $file_id = postie_media_handle_upload($part, $post_id, $poster, $generate_thumbnails); if (!is_wp_error($file_id)) { $file = wp_get_attachment_url($file_id); $cid = ""; if (array_key_exists('content-id', $part->headers)) { $cid = trim($part->headers["content-id"], "<>"); DebugEcho("audio Attachement cid: {$cid}"); } if (in_array($fileext, $audiotypes)) { DebugEcho("using audio template: {$mimetype_secondary}"); $audioTemplate = $audiotemplate; } else { DebugEcho("using default audio template: {$mimetype_secondary}"); $icon = chooseAttachmentIcon($file, $mimetype_primary, $mimetype_secondary, $icon_set, $icon_size); $audioTemplate = '<a href="{FILELINK}">' . $icon . '{FILENAME}</a>'; } $attachments["html"][$filename] = parseTemplate($file_id, $mimetype_primary, $audioTemplate, $filename); } else { LogInfo("audio error: " . $file_id->get_error_message()); } break; case 'video': DebugEcho("video Attachement: {$filename}"); $file_id = postie_media_handle_upload($part, $post_id, $poster, $generate_thumbnails); if (!is_wp_error($file_id)) { $file = wp_get_attachment_url($file_id); $cid = ""; if (array_key_exists('content-id', $part->headers)) { $cid = trim($part->headers["content-id"], "<>"); DebugEcho("video Attachement cid: {$cid}"); } //DebugDump($part); if (in_array($fileext, $video1types)) { DebugEcho("using video1 template: {$fileext}"); $videoTemplate = $video1template; } elseif (in_array($fileext, $video2types)) { DebugEcho("using video2 template: {$fileext}"); $videoTemplate = $video2template; } else { DebugEcho("using default template: {$fileext}"); $icon = chooseAttachmentIcon($file, $mimetype_primary, $mimetype_secondary, $icon_set, $icon_size); $videoTemplate = '<a href="{FILELINK}">' . $icon . '{FILENAME}</a>'; } $attachments["html"][$filename] = parseTemplate($file_id, $mimetype_primary, $videoTemplate, $filename); //echo "videoTemplate = $videoTemplate\n"; } else { LogInfo($file_id->get_error_message()); } break; default: DebugEcho("found file type: " . $mimetype_primary); if (in_array($mimetype_primary, $supported_file_types)) { //pgp signature - then forget it if ($mimetype_secondary == 'pgp-signature') { DebugEcho("found pgp-signature - done"); break; } $file_id = postie_media_handle_upload($part, $post_id, $poster, $generate_thumbnails); if (!is_wp_error($file_id)) { $file = wp_get_attachment_url($file_id); DebugEcho("uploaded {$file_id} ({$file})"); $icon = chooseAttachmentIcon($file, $mimetype_primary, $mimetype_secondary, $icon_set, $icon_size); DebugEcho("default: {$icon} {$filename}"); $attachments["html"][$filename] = parseTemplate($file_id, $mimetype_primary, $generaltemplate, $filename, $icon); if (array_key_exists('content-id', $part->headers)) { $cid = trim($part->headers["content-id"], "<>"); if ($cid) { $attachments["cids"][$cid] = array($file, count($attachments["html"]) - 1); } } else { DebugEcho("No content-id"); } } else { LogInfo($file_id->get_error_message()); } } else { DebugEcho("Not in supported filetype list"); DebugDump($supported_file_types); } break; } } DebugEcho("meta_return: " . substr($meta_return, 0, 500)); DebugEcho("===="); return $meta_return; }
function GetContent($part, &$attachments, $post_id, $poster, $config) { extract($config); global $charset, $encoding; /* if (!function_exists(imap_mime_header_decode)) echo "you need to install the php-imap extension for full functionality, including mime header decoding\n"; */ $meta_return = NULL; echo "primary= " . $part->ctype_primary . ", secondary = " . $part->ctype_secondary . "\n"; DecodeBase64Part($part); if (BannedFileName($part->ctype_parameters['name'], $banned_files_list)) { return NULL; } if ($part->ctype_primary == "application" && $part->ctype_secondary == "octet-stream") { if ($part->disposition == "attachment") { $image_endings = array("jpg", "png", "gif", "jpeg", "pjpeg"); foreach ($image_endings as $type) { if (eregi(".{$type}\$", $part->d_parameters["filename"])) { $part->ctype_primary = "image"; $part->ctype_secondary = $type; break; } } } else { $mimeDecodedEmail = DecodeMIMEMail($part->body); FilterTextParts($mimeDecodedEmail, $prefer_text_type); foreach ($mimeDecodedEmail->parts as $section) { $meta_return .= GetContent($section, $attachments, $post_id, $poster, $config); } } } if ($part->ctype_primary == "multipart" && $part->ctype_secondary == "appledouble") { $mimeDecodedEmail = DecodeMIMEMail("Content-Type: multipart/mixed; boundary=" . $part->ctype_parameters["boundary"] . "\n" . $part->body); FilterTextParts($mimeDecodedEmail, $prefer_text_type); FilterAppleFile($mimeDecodedEmail); foreach ($mimeDecodedEmail->parts as $section) { $meta_return .= GetContent($section, $attachments, $post_id, $poster, $config); } } else { // fix filename (remove non-standard characters) $filename = preg_replace("/[^\t\n\r -]/", "", $part->ctype_parameters['name']); switch (strtolower($part->ctype_primary)) { case 'multipart': FilterTextParts($part, $prefer_text_type); foreach ($part->parts as $section) { $meta_return .= GetContent($section, $attachments, $post_id, $poster, $config); } break; case 'text': $tmpcharset = trim($part->ctype_parameters['charset']); if ($tmpcharset != '') { $charset = $tmpcharset; } $tmpencoding = trim($part->headers['content-transfer-encoding']); if ($tmpencoding != '') { $encoding = $tmpencoding; } $part->body = HandleMessageEncoding($part->headers["content-transfer-encoding"], $part->ctype_parameters["charset"], $part->body, $message_encoding, $message_dequote); //go through each sub-section if ($part->ctype_secondary == 'enriched') { //convert enriched text to HTML $meta_return .= etf2HTML($part->body) . "\n"; } elseif ($part->ctype_secondary == 'html') { //strip excess HTML //$meta_return .= HTML2HTML($part->body ) . "\n"; $meta_return .= $part->body . "\n"; } else { //regular text, so just strip the pgp signature if (ALLOW_HTML_IN_BODY) { $meta_return .= $part->body . "\n"; } else { $meta_return .= htmlentities($part->body) . "\n"; } $meta_return = StripPGP($meta_return); } break; case 'image': $file_id = postie_media_handle_upload($part, $post_id, $poster); $file = wp_get_attachment_url($file_id); $cid = trim($part->headers["content-id"], "<>"); //cids are in <cid> $the_post = get_post($file_id); $attachments["html"][$filename] = parseTemplate($file_id, $part->ctype_primary, $imagetemplate); if ($cid) { $attachments["cids"][$cid] = array($file, count($attachments["html"]) - 1); } break; case 'audio': $file_id = postie_media_handle_upload($part, $post_id, $poster); $file = wp_get_attachment_url($file_id); $cid = trim($part->headers["content-id"], "<>"); //cids are in <cid> if (in_array($part->ctype_secondary, $audiotypes)) { $audioTemplate = $audiotemplate; } else { $icon = chooseAttachmentIcon($file, $part->ctype_primary, $part->ctype_secondary, $icon_set, $icon_size); $audioTemplate = '<a href="{FILELINK}">' . $icon . '{FILENAME}</a>'; } $attachments["html"][$filename] = parseTemplate($file_id, $part->ctype_primary, $audioTemplate); break; case 'video': $file_id = postie_media_handle_upload($part, $post_id, $poster); $file = wp_get_attachment_url($file_id); $cid = trim($part->headers["content-id"], "<>"); //cids are in <cid> if (in_array(strtolower($part->ctype_secondary), $video1types)) { $videoTemplate = $video1template; } elseif (in_array(strtolower($part->ctype_secondary), $video2types)) { $videoTemplate = $video2template; } else { $icon = chooseAttachmentIcon($file, $part->ctype_primary, $part->ctype_secondary, $icon_set, $icon_size); $videoTemplate = '<a href="{FILELINK}">' . $icon . '{FILENAME}</a>'; } $attachments["html"][$filename] = parseTemplate($file_id, $part->ctype_primary, $videoTemplate); //echo "videoTemplate = $videoTemplate\n"; break; default: if (in_array(strtolower($part->ctype_primary), $supported_file_types)) { //pgp signature - then forget it if ($part->ctype_secondary == 'pgp-signature') { break; } $file_id = postie_media_handle_upload($part, $post_id, $poster); $file = wp_get_attachment_url($file_id); $cid = trim($part->headers["content-id"], "<>"); //cids are in <cid> $icon = chooseAttachmentIcon($file, $part->ctype_primary, $part->ctype_secondary, $icon_set, $icon_size); $attachments["html"][$filename] = "<a href='{$file}'>" . $icon . $filename . '</a>' . "\n"; if ($cid) { $attachments["cids"][$cid] = array($file, count($attachments["html"]) - 1); } } break; } } return $meta_return; }
function GetContent($part, &$attachments, $post_id, $config) { global $charset, $encoding; /* if (!function_exists(imap_mime_header_decode)) echo "you need to install the php-imap extension for full functionality, including mime header decoding\n"; */ $meta_return = NULL; echo "primary= " . $part->ctype_primary . ", secondary = " . $part->ctype_secondary . "\n"; DecodeBase64Part($part); if (BannedFileName($part->ctype_parameters['name'], $config['BANNED_FILES_LIST'])) { return NULL; } if ($part->ctype_primary == "application" && $part->ctype_secondary == "octet-stream") { if ($part->disposition == "attachment") { $image_endings = array("jpg", "png", "gif", "jpeg", "pjpeg"); foreach ($image_endings as $type) { if (eregi(".{$type}\$", $part->d_parameters["filename"])) { $part->ctype_primary = "image"; $part->ctype_secondary = $type; break; } } } else { $mimeDecodedEmail = DecodeMIMEMail($part->body); FilterTextParts($mimeDecodedEmail, $config['PREFER_TEXT_TYPE']); foreach ($mimeDecodedEmail->parts as $section) { $meta_return .= GetContent($section, $attachments, $post_id, $config); } } } if ($part->ctype_primary == "multipart" && $part->ctype_secondary == "appledouble") { $mimeDecodedEmail = DecodeMIMEMail("Content-Type: multipart/mixed; boundary=" . $part->ctype_parameters["boundary"] . "\n" . $part->body); FilterTextParts($mimeDecodedEmail, $config['PREFER_TEXT_TYPE']); FilterAppleFile($mimeDecodedEmail); foreach ($mimeDecodedEmail->parts as $section) { $meta_return .= GetContent($section, $attachments, $post_id, $config); } } else { switch (strtolower($part->ctype_primary)) { case 'multipart': FilterTextParts($part, $config['PREFER_TEXT_TYPE']); foreach ($part->parts as $section) { $meta_return .= GetContent($section, $attachments, $post_id, $config); } break; case 'text': $tmpcharset = trim($part->ctype_parameters['charset']); if ($tmpcharset != '') { $charset = $tmpcharset; } $tmpencoding = trim($part->headers['content-transfer-encoding']); if ($tmpencoding != '') { $encoding = $tmpencoding; } $part->body = HandleMessageEncoding($part->headers["content-transfer-encoding"], $part->ctype_parameters["charset"], $part->body, $config['MESSAGE_ENCODING'], $config['MESSAGE_DEQUOTE']); //go through each sub-section if ($part->ctype_secondary == 'enriched') { //convert enriched text to HTML $meta_return .= etf2HTML($part->body) . "\n"; } elseif ($part->ctype_secondary == 'html') { //strip excess HTML //$meta_return .= HTML2HTML($part->body ) . "\n"; $meta_return .= $part->body . "\n"; } else { //regular text, so just strip the pgp signature if (ALLOW_HTML_IN_BODY) { $meta_return .= $part->body . "\n"; } else { $meta_return .= htmlentities($part->body) . "\n"; } $meta_return = StripPGP($meta_return); } break; case 'image': echo "looking at an image\n"; $file_id = postie_media_handle_upload($part, $post_id); $file = wp_get_attachment_url($file_id); $cid = trim($part->headers["content-id"], "<>"); //cids are in <cid> $the_post = get_post($file_id); /* TODO make these options */ $attachments["html"][] = parseTemplate($file_id, $part->ctype_primary, $config['IMAGETEMPLATE']); if ($cid) { $attachments["cids"][$cid] = array($file, count($attachments["html"]) - 1); } break; case 'audio': $file_id = postie_media_handle_upload($part, $post_id); $file = wp_get_attachment_url($file_id); $cid = trim($part->headers["content-id"], "<>"); //cids are in <cid> if (in_array($part->ctype_secondary, $config['AUDIOTYPES'])) { $audioTemplate = $config['AUDIOTEMPLATE']; } else { $icon = chooseAttachmentIcon($file, $part->ctype_primary, $part->ctype_secondary, $config['ICON_SET'], $config['ICON_SIZE']); $audioTemplate = '<a href="{FILELINK}">' . $icon . '{FILENAME}</a>'; } $attachments["html"][] = parseTemplate($file_id, $part->ctype_primary, $audioTemplate); break; case 'video': $file_id = postie_media_handle_upload($part, $post_id); $file = wp_get_attachment_url($file_id); $cid = trim($part->headers["content-id"], "<>"); //cids are in <cid> if (in_array($part->ctype_secondary, $config['VIDEO1TYPES'])) { $videoTemplate = $config['VIDEO1TEMPLATE']; } else { if (in_array($part->ctype_secondary, $config['VIDEO2TYPES'])) { $videoTemplate = $config['VIDEO2TEMPLATE']; } else { $icon = chooseAttachmentIcon($file, $part->ctype_primary, $part->ctype_secondary, $config['ICON_SET'], $config['ICON_SIZE']); $videoTemplate = '<a href="{FILELINK}">' . $icon . '{FILENAME}</a>'; } } $attachments["html"][] = parseTemplate($file_id, $part->ctype_primary, $videoTemplate); break; default: if (in_array(strtolower($part->ctype_primary), $config["SUPPORTED_FILE_TYPES"])) { //pgp signature - then forget it if ($part->ctype_secondary == 'pgp-signature') { break; } $file_id = postie_media_handle_upload($part, $post_id); $file = wp_get_attachment_url($file_id); echo "file={$file}\n"; $cid = trim($part->headers["content-id"], "<>"); //cids are in <cid> $icon = chooseAttachmentIcon($file, $part->ctype_primary, $part->ctype_secondary, $config['ICON_SET'], $config['ICON_SIZE']); $attachments["html"][] = '<a href="' . $file . '" style="text-decoration:none">' . $icon . $part->ctype_parameters['name'] . '</a>' . "\n"; if ($cid) { $attachments["cids"][$cid] = array($file, count($attachments["html"]) - 1); } } break; } } return $meta_return; }
function GetContent($part, &$attachments) { $config = GetConfig(); $meta_return = NULL; DecodeBase64Part($part); if (BannedFileName($part->ctype_parameters['name']) || BannedFileName($part->ctype_parameters['name'])) { return NULL; } if ($part->ctype_primary == "application" && $part->ctype_secondary == "octet-stream") { if ($part->disposition == "attachment") { $image_endings = array("jpg", "png", "gif", "jpeg", "pjpeg"); foreach ($image_endings as $type) { if (eregi(".{$type}\$", $part->d_parameters["filename"])) { $part->ctype_primary = "image"; $part->ctype_secondary = $type; break; } } } else { $mimeDecodedEmail = DecodeMIMEMail($part->body); FilterTextParts($mimeDecodedEmail); foreach ($mimeDecodedEmail->parts as $section) { $meta_return .= GetContent($section, $attachments); } } } if ($part->ctype_primary == "multipart" && $part->ctype_secondary == "appledouble") { $mimeDecodedEmail = DecodeMIMEMail("Content-Type: multipart/mixed; boundary=" . $part->ctype_parameters["boundary"] . "\n" . $part->body); FilterTextParts($mimeDecodedEmail); FilterAppleFile($mimeDecodedEmail); foreach ($mimeDecodedEmail->parts as $section) { $meta_return .= GetContent($section, $attachments); } } else { switch (strtolower($part->ctype_primary)) { case 'multipart': FilterTextParts($part); foreach ($part->parts as $section) { $meta_return .= GetContent($section, $attachments); } break; case 'text': HandleMessageEncoding($part->headers["content-transfer-encoding"], $part->ctype_parameters["charset"], $part->body); //go through each sub-section if ($part->ctype_secondary == 'enriched') { //convert enriched text to HTML $meta_return .= etf2HTML($part->body) . "\n"; } elseif ($part->ctype_secondary == 'html') { //strip excess HTML $meta_return .= HTML2HTML($part->body) . "\n"; } else { //regular text, so just strip the pgp signature if (ALLOW_HTML_IN_BODY) { $meta_return .= $part->body . "\n"; } else { $meta_return .= htmlentities($part->body) . "\n"; } $meta_return = StripPGP($meta_return); } break; case 'image': $file = GenerateImageFileName($config["REALPHOTOSDIR"], $part->ctype_secondary); //This makes sure there is no collision $ctr = 0; while (file_exists($file) && $ctr < 1000) { $file = GenerateImageFileName($config["REALPHOTOSDIR"], $part->ctype_secondary); $ctr++; } if ($ctr >= 1000) { die("Unable to find a name for images that does not collide\n"); } $fileName = basename($file); $fp = fopen($file, 'w'); fwrite($fp, $part->body); fclose($fp); @exec('chmod 755 ' . $file); if ($config["USE_IMAGEMAGICK"] && $config["AUTO_SMART_SHARP"]) { ImageMagickSharpen($file); } $mimeTag = '<!--Mime Type of File is ' . $part->ctype_primary . "/" . $part->ctype_secondary . ' -->'; $thumbImage = NULL; $cid = trim($part->headers["content-id"], "<>"); //cids are in <cid> if ($config["RESIZE_LARGE_IMAGES"]) { list($thumbImage, $fullImage) = ResizeImage($file, strtolower($part->ctype_secondary)); } $attachments["image_files"][] = array($thumbImage ? $config["REALPHOTOSDIR"] . $thumbImage : NULL, $config["REALPHOTOSDIR"] . $fileName, $part->ctype_secondary); if ($thumbImage) { $marime = DetermineImageSize($file); $marimex = $marime[0] + 20; $marimey = $marime[1] + 20; $attachments["html"][] .= $mimeTag . '<div class="' . $config["IMAGEDIV"] . '"><a href="' . $config["URLPHOTOSDIR"] . $fullImage . '" onclick="window.open(' . "'" . $config["URLPHOTOSDIR"] . $fullImage . "','" . "full_size_image" . "','" . "toolbar=0,scrollbars=0,location=0,status=0,menubar=0,resizable=1,height=" . $marimey . ",width=" . $marimex . "');" . "return false;" . '"><img src="' . $config["URLPHOTOSDIR"] . $thumbImage . '" alt="' . $part->ctype_parameters['name'] . '" title="' . $part->ctype_parameters['name'] . '" style="' . $config["IMAGESTYLE"] . '" class="' . $config["IMAGECLASS"] . '" /></a></div>' . "\n"; if ($cid) { $attachments["cids"][$cid] = array($config["URLPHOTOSDIR"] . $fullImage, count($attachments["html"]) - 1); } } else { $attachments["html"][] .= $mimeTag . '<div class="' . $config["IMAGEDIV"] . '"><img src="' . $config["URLPHOTOSDIR"] . $fileName . '" alt="' . $part->ctype_parameters['name'] . '" style="' . $config["IMAGESTYLE"] . '" class="' . $config["IMAGECLASS"] . '" /></div>' . "\n"; if ($cid) { $attachments["cids"][$cid] = array($config["URLPHOTOSDIR"] . $fileName, count($attachments["html"]) - 1); } } break; default: if (in_array(strtolower($part->ctype_primary), $config["SUPPORTED_FILE_TYPES"])) { //pgp signature - then forget it if ($part->ctype_secondary == 'pgp-signature') { break; } //other attachments save to FILESDIR $filename = $part->ctype_parameters['name']; $file = $config["REALFILESDIR"] . $filename; $fp = fopen($file, 'w'); fwrite($fp, $part->body); fclose($fp); @exec('chmod 755 ' . $file); $cid = trim($part->headers["content-id"], "<>"); //cids are in <cid> if ($part->ctype_secondary == "3gpp" || $part->ctype_secondary == "3gp" || $part->ctype_secondary == "3g2" || $part->ctype_secondary == "3gpp2") { if ($config["3GP_QT"]) { //Shamelessly borrowed from http://www.postneo.com/2003/12/19/embedding-3gpp-in-html $attachments["html"][] = '<!--Mime Type of File is ' . $part->ctype_primary . "/" . $part->ctype_secondary . ' -->' . '<a href="' . $config["URLFILESDIR"] . $filename . '">Video' . '<object ' . 'classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" ' . 'codebase="http://www.apple.com/qtactivex/qtplugin.cab" ' . 'width="128" ' . 'height="112"> ' . '<param name="src" VALUE="' . $config["URLFILESDIR"] . $filename . '"> ' . '<param name="autoplay" VALUE="false"> ' . '<param name="controller" VALUE="true"> ' . '<embed ' . 'src="' . $config["URLFILESDIR"] . $filename . '" ' . 'width="128" ' . 'height="112" ' . 'autoplay="true" ' . 'controller="true" ' . 'type="video/quicktime" ' . 'pluginspage="http://www.apple.com/quicktime/download/" ' . 'width="128" ' . 'height="150"></embed> ' . '</object></a>'; } else { if (file_exists($config["3GP_FFMPEG"])) { $fileName = basename($file); //options from http://www.getid3.org/phpBB2/viewtopic.php?p=1290& $scaledFileName = "thumb." . $fileName; $scaledFile = $config["REALPHOTOSDIR"] . $scaledFileName; @exec(escapeshellcmd($config["3GP_FFMPEG"]) . " -i " . escapeshellarg($file) . " -y -ss 00:00:01 -vframes 1 -an -sameq -f gif " . escapeshellarg($scaledFile)); @exec('chmod 755 ' . escapeshellarg($scaledFile)); $attachments["html"][] .= '<!--Mime Type of File is ' . $part->ctype_primary . "/" . $part->ctype_secondary . ' --><div class="' . $config["3GPDIV"] . '"><a href="' . $config["URLPHOTOSDIR"] . $fileName . '"><img src="' . $config["URLPHOTOSDIR"] . $scaledFileName . '" alt="' . $part->ctype_parameters['name'] . '" style="' . $config["IMAGESTYLE"] . '" class="' . $config["IMAGECLASS"] . '" /></a></div>' . "\n"; } else { $attachments["html"][] = '<!--Mime Type of File is ' . $part->ctype_primary . "/" . $part->ctype_secondary . ' --><div class="' . $config["ATTACHMENTDIV"] . '"><a href="' . $config["URLFILESDIR"] . $filename . '" class="' . $config["3GPCLASS"] . '">' . $part->ctype_parameters['name'] . '</a></div>' . "\n"; } } } elseif ($part->ctype_secondary == "x-shockwave-flash") { $attachments["html"][] = '<!--Mime Type of File is ' . $part->ctype_primary . "/" . $part->ctype_secondary . ' -->' . '<object ' . 'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' . 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" ' . 'width="" ' . 'height=""> ' . '<param name="movie" value="' . $config["URLFILESDIR"] . $filename . '"> ' . '<param name="quality" value="high"> ' . '<embed ' . 'src="' . $config["URLFILESDIR"] . $filename . '" ' . 'width="" ' . 'height="" ' . 'quality="high" ' . 'pluginspage="http://www.macromedia.com/go/getflashplayer" ' . 'type="application/x-shockwave-flash" ' . 'width="" ' . 'height=""></embed> ' . '</object>'; } else { $attachments["html"][] = '<!--Mime Type of File is ' . $part->ctype_primary . "/" . $part->ctype_secondary . ' --><a href="' . $config["URLFILESDIR"] . $filename . '">' . $part->ctype_parameters['name'] . '</a>' . "\n"; } if ($cid) { $attachments["cids"][$cid] = array($config["URLFILESDIR"] . $filename, count($attachments["html"]) - 1); } } break; } } return $meta_return; }