 inc/imce.page.inc | 32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/inc/imce.page.inc b/inc/imce.page.inc
index e1f292b..9c481b1 100644
--- a/inc/imce.page.inc
+++ b/inc/imce.page.inc
@@ -399,7 +399,9 @@ function imce_delete_submit($form, &$form_state) {
   $deleted = imce_process_files($form_state['values']['filenames'], $imce, 'imce_delete_file');
 
   if (!empty($deleted)) {
-    drupal_set_message(t('File deletion successful: %files.', array('%files' => utf8_encode(implode(', ', $deleted)))));
+    $files = implode(', ', $deleted);
+    $files_encoded = mb_convert_encoding($files, "UTF-8", mb_detect_encoding($files));
+    drupal_set_message(t('File deletion successful: %files.', array('%files' => $files_encoded)));
   }
 
 }
@@ -423,7 +425,9 @@ function imce_resize_submit($form, &$form_state) {
   $resized = imce_process_files($form_state['values']['filenames'], $imce, 'imce_resize_image', array($width, $height, $form_state['values']['copy']));
 
   if (!empty($resized)) {
-    drupal_set_message(t('File resizing successful: %files.', array('%files' => utf8_encode(implode(', ', $resized)))));
+    $files = implode(', ', $resized);
+    $files_encoded = mb_convert_encoding($files, "UTF-8", mb_detect_encoding($files));
+    drupal_set_message(t('File deletion successful: %files.', array('%files' => $files_encoded)));
   }
 
 }
@@ -500,9 +504,10 @@ function imce_create_thumbnails($filename, &$imce, $values) {
     }
   }
   if (!empty($created)) {
+    $filename_encoded = mb_convert_encoding($filename, "UTF-8", mb_detect_encoding($filename));
     drupal_set_message(t('Thumbnail creation (%thumbnames) successful for %filename.', array(
       '%thumbnames' => implode(', ', $created),
-      '%filename' => utf8_encode($filename),
+      '%filename' => $filename_encoded,
     )));
   }
   return $created;
@@ -536,7 +541,8 @@ function imce_resize_image($filename, &$imce, $width, $height, $copy = TRUE, $de
 
   // Check if the file is an image.
   if (!$imce['files'][$filename]['width'] || !$img = image_get_info($imguri)) {
-    drupal_set_message(t('%filename is not an image.', array('%filename' => utf8_encode($filename))), 'error', FALSE);
+    $filename_encoded = mb_convert_encoding($filename, "UTF-8", mb_detect_encoding($filename));
+    drupal_set_message(t('%filename is not an image.', array('%filename' => $filename_encoded)), 'error', FALSE);
     return FALSE;
   }
 
@@ -556,7 +562,8 @@ function imce_resize_image($filename, &$imce, $width, $height, $copy = TRUE, $de
   // Check if a file having the same properties exists already.
   if (isset($imce['files'][$file->filename])) {
     if (($f = $imce['files'][$file->filename]) && $f['width'] == $width && $f['height'] == $height) {
-      drupal_set_message(t('%filename(%dimensions) already exists.', array('%filename' => utf8_encode($file->filename), '%dimensions' => $width . 'x' . $height)), 'error');
+      $filename_encoded = mb_convert_encoding($file->filename, "UTF-8", mb_detect_encoding($file->filename));
+      drupal_set_message(t('%filename(%dimensions) already exists.', array('%filename' => $filename_encoded, '%dimensions' => $width . 'x' . $height)), 'error');
       return FALSE;
     }
   }
@@ -572,7 +579,8 @@ function imce_resize_image($filename, &$imce, $width, $height, $copy = TRUE, $de
   $image = image_load($imguri);
   $function = 'image_' . $op;
   if (!$image || !function_exists($function) || !$function($image, $width, $height)) {
-    drupal_set_message(t('%filename cannot be resized to %dimensions', array('%filename' => utf8_encode($filename), '%dimensions' => $width . 'x' . $height)), 'error', FALSE);
+    $filename_encoded = mb_convert_encoding($filename, "UTF-8", mb_detect_encoding($filename));
+    drupal_set_message(t('%filename cannot be resized to %dimensions', array('%filename' => $filename_encoded), '%dimensions' => $width . 'x' . $height)), 'error', FALSE);
     return FALSE;
   }
 
@@ -699,11 +707,12 @@ function imce_validate_filesize($file, $maxsize = 0) {
 function imce_validate_quota($file, $quota = 0, $currentsize = 0) {
   $errors = array();
   if ($quota && ($currentsize + $file->filesize) > $quota) {
+    $filename_encoded = mb_convert_encoding($file->filename, "UTF-8", mb_detect_encoding($file->filename));
     $errors[] = t('%filename is %filesize which would exceed your directory quota. You are currently using %size of %total_quota.', array(
       '%size' => format_size($currentsize),
       '%total_quota' => format_size($quota),
       '%filesize' => format_size($file->filesize),
-      '%filename' => utf8_encode($file->filename),
+      '%filename' => $filename_encoded,
     ));
   }
   return $errors;
@@ -715,11 +724,12 @@ function imce_validate_quota($file, $quota = 0, $currentsize = 0) {
 function imce_validate_tuquota($file, $quota = 0, $currentsize = 0) {
   $errors = array();
   if ($quota && ($currentsize + $file->filesize) > $quota) {
+    $filename_encoded = mb_convert_encoding($file->filename, "UTF-8", mb_detect_encoding($file->filename));
     $errors[] = t('%filename is %filesize which would exceed your total user quota. You are currently using %size of %total_quota.', array(
       '%size' => format_size($currentsize),
       '%total_quota' => format_size($quota),
       '%filesize' => format_size($file->filesize),
-      '%filename' => utf8_encode($file->filename),
+      '%filename' => $filename_encoded,
     ));
   }
   return $errors;
@@ -1017,9 +1027,9 @@ function imce_check_directory($dirname, $imce) {
  */
 function imce_inaccessible_directory($dirname, $imce) {
   if (is_string($dirname)) {
-    $dirname = utf8_encode($dirname);
-    $diruri = imce_dir_uri($imce, $dirname);
-    drupal_set_message(t('Directory %dirname is not accessible.', array('%dirname' => $dirname)), 'error');
+    $dirname_encoded = mb_convert_encoding($dirname, "UTF-8", mb_detect_encoding($dirname));
+    $diruri = imce_dir_uri($imce, $dirname_encoded);
+    drupal_set_message(t('Directory %dirname is not accessible.', array('%dirname' => $dirname_encoded)), 'error');
     watchdog('imce', 'Access to %directory was denied.', array('%directory' => $diruri), WATCHDOG_ERROR);
   }
   return FALSE;