Index: user_import.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/user_import/user_import.module,v
retrieving revision 1.20
diff -u -p -r1.20 user_import.module
--- user_import.module	22 Feb 2009 12:52:50 -0000	1.20
+++ user_import.module	19 Nov 2009 00:04:46 -0000
@@ -998,6 +998,14 @@ function _user_import_file_open($filepat
   static $handle;
   if (!empty($handle)) return $handle;
 
+  // convert file to UTF-8 if encoding is not UTF-8
+  $contents = @file_get_contents($filepath);
+  if ($contents && (mb_check_encoding($contents, 'UTF-8') === FALSE)) {
+    // assume we're coming from ISO-8859-1 as utf8_encode() does
+    $contents = utf8_encode($contents);
+    file_put_contents($filepath, $contents);
+  }
+
   $handle = @fopen($filepath, "r");
                     
   if (!$handle) {
@@ -1010,6 +1018,11 @@ function _user_import_file_open($filepat
 // get first row of file
 function _user_import_file_row($filename, $handle) {
     
+    // Locale must be set for fgetcsv() to correctly match our file encoding.
+    // Otherwise a leading special character in a field results in an empty 
+    // string due to PHP bug http://bonsai.php.net/bug.php?id=48507.
+    setlocale(LC_ALL, 'en_US.UTF-8'); 
+
     $data_row = @fgetcsv ($handle, 1000000, ",");
     if (!$data_row) {
         form_set_error('file', t("Could not get data, the file '%filename' is either empty or has incompatible line endings.", array('%filename' => $filename)), 'error');
@@ -1414,7 +1427,12 @@ function _user_import_process($settings)
   
     // start count of imports on this cron run
     $send_counter = 0;
-    
+
+    // Locale must be set for fgetcsv() to correctly match our file encoding.
+    // Otherwise a leading special character in a field results in an empty 
+    // string due to PHP bug http://bonsai.php.net/bug.php?id=48507.
+    setlocale(LC_ALL, 'en_US.UTF-8'); 
+
     while ($data = fgetcsv($handle, $line_max, ',')) {
     
         $errors = user_import_errors(FALSE, TRUE);
