Index: mailsave.module =================================================================== RCS file: /cvs/drupal/contributions/modules/mailsave/mailsave.module,v retrieving revision 1.17 diff -u -p -r1.17 mailsave.module --- mailsave.module 20 Aug 2008 21:50:17 -0000 1.17 +++ mailsave.module 21 Jan 2009 20:32:14 -0000 @@ -304,7 +304,14 @@ function _mailsave_use_mailhandler_attac $attachments = array(); // Parse each mime part in turn - foreach ($node->mimeparts as $mimepart) { + foreach ($node->mimeparts as $key => $mimepart) { + + // Inline attached files show up as "unnamed" files (a filename may be + // present in a Content-Location header but is not detected). Work around + // this by generating a filename based on the mimetype. + if ($mimepart->filename == MAILSAVE_UNNAMED_ATTACHMENT) { + mailsave_generate_filename($mimepart); + } // Only return those parts that have a filename, or are non-text // This is try and prevent unnamed text parts getting treated as attachments @@ -320,6 +327,7 @@ function _mailsave_use_mailhandler_attac 'filepath' => $filepath, 'filemime' => strtolower($mimepart->filemime), 'filesize' => strlen($mimepart->data), + 'mimepart' => $key, ); } } @@ -344,14 +352,14 @@ function _mailsave_save_file($attachment $extensions = ''; foreach ($user->roles as $rid => $name) { $extensions .= ' '. variable_get("upload_extensions_$rid", - variable_get('upload_extensions_default', 'jpg jpeg gif png txt html doc xls pdf ppt pps odt ods odp')); + variable_get('upload_extensions_default', 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp')); } // Begin building file object. $file = new stdClass(); $file->filename = file_munge_filename(trim(basename($attachment['filename']), '.'), $extensions); $file->filepath = $attachment['filepath']; - $file->filemime = file_get_mimetype($file->filename);; + $file->filemime = file_get_mimetype($file->filename); // Rename potentially executable files, to help prevent exploits. if (preg_match('/\.(php|pl|py|cgi|asp|js)$/i', $file->filename) && (substr($file->filename, -4) != '.txt')) { @@ -424,3 +432,16 @@ function _mailsave_sanitise_filename($fi // Return the cleaned up filename return $filename; } + +/** + * Take a raw unnamed mimepart and generate a filename based on the mimetype. + */ +function mailsave_generate_filename(&$mimepart) { + $mapping = array( + 'IMAGE/JPEG' => '.jpg', + ); + if (isset($mapping[$mimepart->filemime])) { + // Generate a unique filename. + $mimepart->filename = md5(uniqid(mt_rand(), TRUE)) . $mapping[$mimepart->filemime]; + } +}