### Eclipse Workspace Patch 1.0
#P mailsave
Index: mailsave.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mailsave/mailsave.module,v
retrieving revision 1.12.2.1
diff -u -r1.12.2.1 mailsave.module
--- mailsave.module	23 Mar 2008 22:41:18 -0000	1.12.2.1
+++ mailsave.module	18 Jul 2008 21:15:53 -0000
@@ -150,18 +150,6 @@
     $attachment['fid'] = $key;
     $attachment['list'] = 1;
 
-    // Filenames may be encoded, so decode to ensure they work properly
-    $attachment['filename'] = mb_decode_mimeheader($attachment['filename']);
-
-    // Replaces all characters up through space and all past ~ along with the above reserved characters to sanitise filename
-    // from php.net/manual/en/function.preg-replace.php#80431
-
-    // Define characters that are  illegal on any of the 3 major OS's
-    $reserved = preg_quote('\/:*?"<>|', '/');
-
-    // Perform cleanup
-    $attachment['filename'] = preg_replace("/([\\x00-\\x20\\x7f-\\xff{$reserved}])/e", "_", $attachment['filename']);
-
     // Create the $node->files elements
     $node->files[$key] = $attachment;
   }
@@ -268,7 +256,7 @@
     $mimetypes = array ('text', 'multipart', 'message', 'application', 'audio', 'image', 'video', 'other');
 
     $partsarray[] = array(
-      'filename' => $filename,
+      'filename' => _mailsave_sanitise_filename($filename),
       'filepath' => $filepath,
       'filemime' => strtolower($mimetypes[$p->type].'/'.$p->subtype),
       'filesize' => strlen($part),
@@ -535,9 +523,9 @@
       $temp_file = tempnam(file_directory_temp(), 'mail');
       $filepath = file_save_data($mimepart->data, $temp_file);
 
-      // Add the item to the attachments array
+      // Add the item to the attachments array, and sanitise filename
       $attachments[] = array(
-        'filename' => $mimepart->filename,
+        'filename' => _mailsave_sanitise_filename($mimepart->filename),
         'filepath' => $filepath,
         'filemime' => strtolower($mimepart->filemime),
         'filesize' => strlen($mimepart->data),
@@ -549,3 +537,21 @@
   return $attachments;
 
 }
+
+function _mailsave_sanitise_filename($filename) {
+
+  // Decode multibyte encoded filename
+  $filename = mb_decode_mimeheader($filename);
+
+  // Replaces all characters up through space and all past ~ along with the above reserved characters to sanitise filename
+  // from php.net/manual/en/function.preg-replace.php#80431
+
+  // Define characters that are  illegal on any of the 3 major OS's
+  $reserved = preg_quote('\/:*?"<>|', '/');
+
+  // Perform cleanup
+  $filename = preg_replace("/([\\x00-\\x20\\x7f-\\xff{$reserved}])/e", "_", $filename);
+
+  // Return the cleaned up filename
+  return $filename;
+}
