### Eclipse Workspace Patch 1.0
#P 19stable
Index: admin/uploaduser.php
===================================================================
RCS file: /cvsroot/moodle/moodle/admin/uploaduser.php,v
retrieving revision 1.68.2.13
diff -u -r1.68.2.13 uploaduser.php
--- admin/uploaduser.php	26 Sep 2008 09:10:20 -0000	1.68.2.13
+++ admin/uploaduser.php	9 Oct 2008 00:08:32 -0000
@@ -327,10 +327,28 @@
                 $upt->track('status', $strusernotdeletedmissing, 'error');
                 $deleteerrors++;
             }
+            unset($user->deleted);
             continue;
+        } else {
+            unset($user->deleted);
+            if (!empty($existinguser->deleted)) { //if user was previously deleted but now being restored
+                $upt->track('status', 'trying to move mail', 'warning');
+                if ($messages = get_records_select('message_read', "useridfrom = $existinguser->id", 'timecreated')) {
+                    foreach ($messages as $message) {
+                        $message = addslashes_object($message);
+                        $messageid = $message->id;
+                        unset($message->id); // allow message id to use autoincrement id field
+                        unset($message->timeread); //timeread field not in message table
+                        unset($message->mailed); //mailed field not in message table
+                        if (insert_record('message', $message)) {
+                            delete_records('message_read', 'id', $messageid);
+                            $user->deleted=0;
+                            
+                        }
+                    }
+                }
+            }
         }
-        // we do not need the deleted flag anymore
-        unset($user->deleted);
 
         // renaming requested?
         if (!empty($user->oldusername) ) {
@@ -445,6 +463,7 @@
                             }
                         }
                     }
+                        
                     if ((array_key_exists($column, $existinguser) and array_key_exists($column, $user)) or in_array($column, $PRF_FIELDS)) {
                         if ($updatetype == 3 and $existinguser->$column !== '') {
                             //missing == non-empty only

