From e70b3b24fc8ac7b54a820ae87ce8f4af4043125e Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Thu, 09 Oct 2008 02:25:43 -0400
Subject: [PATCH] - send set_unread_count() only when changing /Seen status

---
 program/lib/Mail/mime.php |   44 ++++++++++++++++++++++++++++++++++++++------
 1 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/program/lib/Mail/mime.php b/program/lib/Mail/mime.php
index 507caca..688c326 100644
--- a/program/lib/Mail/mime.php
+++ b/program/lib/Mail/mime.php
@@ -323,6 +323,8 @@
      *                             of this attachment.
      * @param string $language    The language of the attachment
      * @param string $location    The RFC 2557.4 location of the attachment
+     * @param string $n_encoding      Use RFC 2047 for attachment name (Content-Type) encoding
+     * @param string $f_encoding      Use RFC 2047 for attachment filename (Content-Disposition) encoding
      *
      * @return mixed true on success or PEAR_Error object
      * @access public
@@ -335,7 +337,9 @@
                            $disposition = 'attachment',
                            $charset     = '',
                             $language   = '',
-                           $location    = '')
+                           $location    = '',
+			   $n_encoding	= NULL,
+			   $f_encoding   = NULL)
     {
         $filedata = ($isfile === true) ? $this->_file2str($file)
                                            : $file;
@@ -350,7 +354,7 @@
             $err = PEAR::raiseError($msg);
             return $err;
         }
-        $filename = basename($filename);
+        $filename = $this->_basename($filename);
         if (PEAR::isError($filedata)) {
             return $filedata;
         }
@@ -363,7 +367,9 @@
                                 'charset'     => $charset,
                                 'language'    => $language,
                                 'location'    => $location,
-                                'disposition' => $disposition
+                                'disposition' => $disposition,
+				'name-encoding'    => $n_encoding,
+				'filename-encoding'=> $f_encoding
                                );
         return true;
     }
@@ -532,6 +538,12 @@
         $params['disposition']  = 'inline';
         $params['dfilename']    = $value['name'];
         $params['cid']          = $value['cid'];
+	if ($value['name-encoding']) {
+	    $params['name-encoding'] = $value['name-encoding'];
+	}
+	if ($value['filename-encoding']) {
+	    $params['filename-encoding'] = $value['filename-encoding'];
+	}
         
         $ret = $obj->addSubpart($value['body'], $params);
         return $ret;
@@ -561,6 +573,12 @@
         if ($value['location']) {
             $params['location'] = $value['location'];
         }
+	if ($value['name-encoding']) {
+	    $params['name-encoding'] = $value['name-encoding'];
+	}
+	if ($value['filename-encoding']) {
+	    $params['filename-encoding'] = $value['filename-encoding'];
+	}
         $params['content_type'] = $value['c_type'];
         $params['disposition']  = isset($value['disposition']) ? 
                                   $value['disposition'] : 'attachment';
@@ -667,7 +685,7 @@
 
                 $this->_htmlbody = preg_replace($regex, $rep, $this->_htmlbody);
                 $this->_html_images[$key]['name'] = 
-                    basename($this->_html_images[$key]['name']);
+                    $this->_basename($this->_html_images[$key]['name']);
             }
         }
 
@@ -914,7 +932,6 @@
      */
     function _encodeHeaders($input, $params = array())
     {
-        
         $build_params = $this->_build_params;
         while (list($key, $value) = each($params)) {
             $build_params[$key] = $value;
@@ -1114,6 +1131,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