? sites/default/files
? sites/default/settings.php
Index: includes/unicode.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/unicode.inc,v
retrieving revision 1.37
diff -u -p -r1.37 unicode.inc
--- includes/unicode.inc	2 Jan 2009 22:09:53 -0000	1.37
+++ includes/unicode.inc	2 Mar 2009 06:08:07 -0000
@@ -269,8 +269,25 @@ function truncate_utf8($string, $len, $w
  *   each chunk starts and ends on a character boundary.
  * - Using \n as the chunk separator may cause problems on some systems and may
  *   have to be changed to \r\n or \r.
+ * - For header fields that are composed of multiple parameters, parameter
+ *   values that contain non-alphanumeric ASCII characters should be quoted-
+ *   string encoded. The following header, for example, requires quoted-string
+ *   encoding of the filename and modification-date parameters:
+ *     Content-Disposition: attachment; filename="My picture.jpg";
+ *       modification-date="Wed, 12 Feb 1997 16:29:51 -0500";
+ *   In this case set the $quoted argument to TRUE and use mime_header_encode()
+ *   to separately encode each parameter. Depending on the characters present in
+ *   the parameter value, a quoted string, including the quotation mark
+ *   delimiters, may then be returned. Do not enable quoted-string encoding when
+ *   calling mime_header_encode() on a header field not composed of multiple
+ *   parameters, such as an e-mail Subject header.
+ *
+ * @param $string
+ *   The string to encode.
+ * @param $quoted
+ *   If TRUE, perform quoted-string encoding of non-alphanumeric ASCII.
  */
-function mime_header_encode($string) {
+function mime_header_encode($string, $quoted = FALSE) {
   if (preg_match('/[^\x20-\x7E]/', $string)) {
     $chunk_size = 47; // floor((75 - strlen("=?UTF-8?B??=")) * 0.75);
     $len = strlen($string);
@@ -284,6 +301,12 @@ function mime_header_encode($string) {
     }
     return trim($output);
   }
+  // Strings containing spaces and certain other characters must in some cases
+  // be quoted-string encoded.
+  if ($quoted && preg_match('/[^A-Za-z0-9_]/', $string)) {
+    // Escape double-quotes and backslashes.
+    return '"' . str_replace(array('\\', '"'), array('\\\\', '\"'), $string) . '"';
+  }
   return $string;
 }
 
Index: modules/simpletest/tests/unicode.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/unicode.test,v
retrieving revision 1.2
diff -u -p -r1.2 unicode.test
--- modules/simpletest/tests/unicode.test	2 Jan 2009 22:09:53 -0000	1.2
+++ modules/simpletest/tests/unicode.test	2 Mar 2009 06:08:07 -0000
@@ -215,4 +215,28 @@ class UnicodeUnitTest extends DrupalWebT
       $this->assertIdentical(decode_entities($input, $exclude), $output, t('Make sure the decoded entity of %input, excluding %excludes, is %output', array('%input' => $input, '%excludes' => implode(',', $exclude), '%output' => $output)));
     }
   }
+
+  /**
+   * Test mime_header_encode().
+   */
+  function testMimeHeaderEncode() {
+    $testcase = array(
+      'tést.txt' => '=?UTF-8?B?dMOpc3QudHh0?=',
+      'my test.txt' => 'my test.txt',
+      'my "test".txt' => 'my "test".txt',
+    );
+    foreach ($testcase as $input => $output) {
+      $this->assertEqual(mime_header_encode($input), $output, t('Make sure %input is encoded as %output.', array('%input' => $input, '%output' => $output)));
+    }
+
+    // Test quoted-string encoding.
+    $testcase = array(
+      'tést.txt' => '=?UTF-8?B?dMOpc3QudHh0?=',
+      'my test.txt' => '"my test.txt"',
+      'my "test".txt' => '"my \"test\".txt"',
+    );
+    foreach ($testcase as $input => $output) {
+      $this->assertEqual(mime_header_encode($input, TRUE), $output, t('Make sure %input is encoded as %output.', array('%input' => $input, '%output' => $output)));
+    }
+  }
 }
