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 13:11:34 -0000 @@ -142,6 +142,13 @@ function _mailsave_save_files(&$node) { global $user; + // 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 ($attachment['filename'] == MAILSAVE_UNNAMED_ATTACHMENT) { + mailsave_generate_filename($attachment); + } + $limits = _upload_file_limits($user); $validators = array( 'file_validate_extensions' => array($limits['extensions']), @@ -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(&$attachment) { + $mapping = array( + 'image/jpeg' => 'image.jpg', + ); + if (isset($mapping[$attachment['filemime']])) { + $attachment['filename'] = $mapping[$attachment['filemime']]; + } +}