diff --git a/include/class.format.php b/include/class.format.php
index bf331e033b49adce56b0129c4d4d6885e042642f..7a339e429212a1d1b7919dc14b7bd6bb0bd0e24c 100644
--- a/include/class.format.php
+++ b/include/class.format.php
@@ -46,11 +46,13 @@ class Format {
             $charset = 'ISO-8859-1';
 
         if(function_exists('iconv') && $charset)
-            return iconv($charset, $encoding.'//IGNORE', $text);
-        elseif(function_exists('iconv_mime_decode'))
-            return iconv_mime_decode($text, 0, $encoding);
-        else //default to utf8 encoding.
-            return utf8_encode($text);
+            $text = iconv($charset, $encoding.'//IGNORE', $text);
+        elseif(function_exists('mb_convert_encoding') && $charset && $encoding)
+            $text = mb_convert_encoding($text, $encoding, $charset);
+        elseif(!strcasecmp($encoding, 'utf-8')) //forced blind utf8 encoding.
+            $text = function_exists('imap_utf8')?imap_utf8($text):utf8_encode($text);
+
+        return $text;
     }
 
     //Wrapper for utf-8 encoding.
@@ -58,6 +60,24 @@ class Format {
         return Format::encode($text, $charset, 'utf-8');
     }
 
+    function mimedecode($text, $encoding='UTF-8') {
+
+        if(function_exists('imap_mime_header_decode')
+                && ($parts = imap_mime_header_decode($text))) {
+            $str ='';
+            foreach ($parts as $part)
+                $str.= Format::encode($part->text, $part->charset, $encoding);
+
+            $text = $str;
+        } elseif(function_exists('iconv_mime_decode')) {
+            $text = iconv_mime_decode($text, 0, $encoding);
+        } elseif(!strcasecmp($encoding, 'utf-8') && function_exists('imap_utf8')) {
+            $text = imap_utf8($text);
+        }
+
+        return $text;
+    }
+
 	function phone($phone) {
 
 		$stripped= preg_replace("/[^0-9]/", "", $phone);