From 09f19e675f3396a8a0f26fecd9b0501d19a4999f Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Thu, 25 Sep 2008 13:20:40 -0400
Subject: [PATCH] - Fix problem with non-ascii attachment names in Mail_mime (#1485267, #1485096)

---
 program/lib/Mail/mime.php |   21 ++++++++++++++++++---
 1 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/program/lib/Mail/mime.php b/program/lib/Mail/mime.php
index 92c797b..7641b0c 100644
--- a/program/lib/Mail/mime.php
+++ b/program/lib/Mail/mime.php
@@ -350,7 +350,7 @@
             $err = PEAR::raiseError($msg);
             return $err;
         }
-        $filename = substr('s_'.basename($filename), 2);
+        $filename = $this->_basename($filename);
         if (PEAR::isError($filedata)) {
             return $filedata;
         }
@@ -667,7 +667,7 @@
 
                 $this->_htmlbody = preg_replace($regex, $rep, $this->_htmlbody);
                 $this->_html_images[$key]['name'] = 
-                    substr(basename('s_'.$this->_html_images[$key]['name']), 2);
+                    $this->_basename($this->_html_images[$key]['name']);
             }
         }
 
@@ -1114,6 +1114,21 @@
         }
     }
 
-    
+    /**
+     * Get file's basename (locale independent) 
+     *
+     * @param string Filename
+     *
+     * @return string Basename
+     * @access private
+     */
+    function _basename($filename)
+    {
+	// basename() is not unicode safe and locale dependent
+	if (stristr(PHP_OS, 'win') || stristr(PHP_OS, 'netware'))
+	    return preg_replace('/^.*[\\\\\\/]/', '', $filename);
+	else
+	    return preg_replace('/^.*[\/]/', '', $filename);
+    }
 
 } // End of class

--
Gitblit v1.9.1