diff -urp --strip-trailing-cr ../privatemsg-orig/privatemsg.install ./privatemsg.install
--- ../privatemsg-orig/privatemsg.install	2009-02-20 09:30:27.000000000 +0100
+++ ./privatemsg.install	2009-03-22 18:55:21.000000000 +0100
@@ -108,7 +108,7 @@ function privatemsg_uninstall() {
   drupal_uninstall_schema('privatemsg');
 }
 
-function privatemsg_update_6001() {
+function privatemsg_update_6010() {
   $ret = array();
 
   if (!db_column_exists('pm_index', 'is_new')) {
@@ -137,8 +137,6 @@ function privatemsg_update_6001() {
 }
 
 function privatemsg_update_6000() {
-  // Give update unlimited time to complete.
-  set_time_limit(0);
 
   // Update the database schema and transfer data to new tables.
   $schema = array();
@@ -290,6 +288,17 @@ function privatemsg_update_6000() {
   if (!(db_table_exists('temp_pm_index'))) {
     db_create_table($ret, 'temp_pm_index', $schema['temp_pm_index']);
   }
+  return $ret;
+}
+
+
+function privatemsg_update_6001() {
+  $ret = array();
+
+  // Enable privatemsg module to avoid dependency issues with new modules force-enabled below
+  // (for the case that privatemsg was disabled, per some upgrade how-tos)
+  $ret[] = update_sql("UPDATE {system} SET status = 1 WHERE name = 'privatemsg' AND type = 'module'");
+
   $modules = array();
   if (!(module_exists('privatemsg_filter'))) {
     $modules[] = 'privatemsg_filter';
@@ -300,18 +309,30 @@ function privatemsg_update_6000() {
   if (count($modules) > 0) {
     drupal_install_modules($modules);
   }
+  return $ret;
+}
+
+
+function privatemsg_update_6002() {
+  $ret = array();
 
   // Step 2: Get the data
 
   // Step 2a: get the folder/tagging data first.
   if (db_table_exists('privatemsg_folder')) {
     $data = db_query("SELECT * FROM {privatemsg_folder}");
-    while ($result = db_fetch_array($data)) {
-      if (db_result(db_query("SELECT COUNT (*) FROM {pm_tags} WHERE tag = '%s'", $result->name)) == 0) {
+    while ($result = db_fetch_object($data)) {
+      if (db_result(db_query("SELECT COUNT(*) FROM {pm_tags} WHERE tag = '%s'", $result->name)) == 0) {
         db_query("INSERT INTO {pm_tags} (tag) VALUES ('%s')", $result->name);
       }
     }
   }
+  return $ret;
+}
+
+
+function privatemsg_update_6003() {
+  $ret = array();
 
   //Step 2b: Next, copy the user blocking data.
   if (db_table_exists('privatemsg_block_user')) {
@@ -320,6 +341,12 @@ function privatemsg_update_6000() {
       db_query("INSERT INTO {pm_block_user} (author, recipient) VALUES ( %d, %d )", $result['author'], $result['recipient']);
     }
   }
+  return $ret;
+}
+
+
+function privatemsg_update_6004() {
+  $ret = array();
 
   //Step 2c: Next the data from the archive table - notice all these messages have been deleted both by the author and the recipient.
   if (db_table_exists('privatemsg_archive')) {
@@ -338,6 +365,12 @@ function privatemsg_update_6000() {
       db_query("INSERT INTO {temp_pm_index} (mid, thread, folder, thread_id, uid, is_new, deleted) VALUES ( %d, %d, %d, %d, %d, %d, %d )", $result['id'], $result['thread'], 0, $result['thread_id'], $result['author'], 0, 1);
     }
   }
+  return $ret;
+}
+
+
+function privatemsg_update_6005() {
+  $ret = array();
 
   //Step 2d: Finally, get the data from the privatemsg table.
   if (db_table_exists('privatemsg')) {
@@ -356,6 +389,12 @@ function privatemsg_update_6000() {
       db_query("INSERT INTO {temp_pm_index} (mid, thread, folder, thread_id, uid, is_new, deleted) VALUES ( %d, %d, %d, %d, %d, %d, %d )", $result['id'], $result['thread'], 0, $result['thread_id'], $result['author'], 0, $result['author_del']);
     }
   }
+  return $ret;
+}
+
+
+function privatemsg_update_6006() {
+  $ret = array();
 
   // Step 3: Process the Data.
   // Step 3a: Fix the thread data.
@@ -363,6 +402,13 @@ function privatemsg_update_6000() {
   while ($result = db_fetch_array($data)) {
     db_query("UPDATE {temp_pm_index} SET thread_id = %d WHERE thread = %d", $result['new_thread'], $result['thread']);
   }
+  return $ret;
+}
+
+
+
+function privatemsg_update_6007() {
+  $ret = array();
 
   // Step 3b: Fix and import the tagging data.
   $data = db_query("SELECT thread_id, folder, uid FROM {temp_pm_index} WHERE folder <> %d", 0);
@@ -372,19 +418,33 @@ function privatemsg_update_6000() {
       db_query("INSERT INTO {pm_tags_index} (uid, tag_id, thread_id) VALUES (%d, %d, %d)", $result->uid, $tag_id, $result->thread_id);
     }
   }
+  return $ret;
+}
+
+
+function privatemsg_update_6008() {
+  $ret = array();
 
   // Step 3c: Copy the index data.
   $data = db_query("SELECT * FROM {temp_pm_index}");
   while ($result = db_fetch_array($data)) {
     db_query("INSERT INTO {pm_index} (mid, thread_id, uid, is_new, deleted) VALUES ( %d, %d, %d, %d, %d )", $result['mid'], $result['thread_id'], $result['uid'], $result['is_new'], $result['deleted']);
   }
+  return $ret;
+}
+
+
+function privatemsg_update_6009() {
+  $ret = array();
 
   // Step 4: Clean up.
   db_drop_table($ret, 'privatemsg');
   db_drop_table($ret, 'privatemsg_archive');
   db_drop_table($ret, 'privatemsg_folder');
-  db_drop_table($ret, 'privatemsg_block_user');
+  if (db_table_exists('privatemsg_block_user')) {
+    db_drop_table($ret, 'privatemsg_block_user');
+  }
   db_drop_table($ret, 'temp_pm_index');
 
   return $ret;
