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 6 Sep 2008 05:51:29 -0000 @@ -306,6 +306,13 @@ function _mailsave_use_mailhandler_attac // Parse each mime part in turn foreach ($node->mimeparts as $mimepart) { + // Attachments in AT&T MMS messages show up as "unnamed" files (actually a + // filename is 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 if ($mimepart->filename != MAILSAVE_UNNAMED_ATTACHMENT || ((strpos($mimepart->filemime, 'TEXT') === FALSE) && (strpos($mimepart->filemime, 'MULTIPART') === FALSE))) { @@ -344,14 +351,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 +431,15 @@ 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' => 'image.jpg', + ); + if (isset($mapping[$mimepart->filemime])) { + $mimepart->filename = $mapping[$mimepart->filemime]; + } +}