Index: privatemsg.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/privatemsg/privatemsg.module,v
retrieving revision 1.70.2.30.2.91.2.64.2.25
diff -u -p -r1.70.2.30.2.91.2.64.2.25 privatemsg.module
--- privatemsg.module	1 Nov 2009 23:53:14 -0000	1.70.2.30.2.91.2.64.2.25
+++ privatemsg.module	5 Nov 2009 20:23:52 -0000
@@ -1214,6 +1214,44 @@ function privatemsg_user_login(&$edit, &
 }
 
 /**
+ * Implements hook_user_cancel().
+ */
+function privatemsg_user_cancel($edit, $account, $method) {
+  switch ($method) {
+    case 'user_cancel_reassign':
+      db_update('pm_message')
+        ->condition('author', $account->uid)
+        ->fields(array('author' => 0))
+        ->execute();
+      break;
+    
+    case 'user_cancel_delete':
+    case 'user_cancel_block_unpublish':
+      $mids = db_select('pm_message', 'pm')
+        ->fields('pm', array('mid'))
+        ->condition('author', $account->uid)
+        ->execute()
+        ->fetchCol();
+
+      // Delete recipient entries in {pm_index} of the messages the user wrote.
+      db_delete('pm_index')
+        ->condition('mid', $mids)
+        ->execute();
+
+      // Delete messages the user wrote.
+      db_delete('pm_message')
+        ->condition('author', $account->uid)
+        ->execute();
+
+      // Delete recipient entries of that user.
+      db_delete('pm_index')
+        ->condition('uid', $account->uid)
+        ->execute();
+      break;
+  }
+}
+
+/**
  * Implements hook_block_info().
  */
 function privatemsg_block_info() {
Index: privatemsg.test
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/privatemsg/privatemsg.test,v
retrieving revision 1.2.2.1.2.5
diff -u -p -r1.2.2.1.2.5 privatemsg.test
--- privatemsg.test	27 Oct 2009 11:49:07 -0000	1.2.2.1.2.5
+++ privatemsg.test	5 Nov 2009 20:23:53 -0000
@@ -337,7 +337,7 @@ class PrivatemsgTestCase extends DrupalW
     // Create users.
     $author = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg', 'delete privatemsg'));
     $recipient = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg', 'delete privatemsg'));
-    $recipient2 = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg'));
+    $recipient2 = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg', 'cancel account'));
     $admin = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg', 'delete privatemsg', 'read all private messages'));
 
     // Create texts.
@@ -412,6 +412,34 @@ class PrivatemsgTestCase extends DrupalW
     $this->assertText($body1, 'First message is still displayed');
     $this->assertNoText($body2, 'Second message has been deleted for all users');
 
+    // Check that messages of canceled users (user_cancel_delete) are deleted too.
+    $edit = array('body' => $this->randomName(100));
+    $this->drupalPost(NULL, $edit, t('Send message'));
+    $this->drupalGet('messages/view/' . $return['message']['thread_id']);
+    $this->assertText($edit['body'], t('New reply is displayed'));
+
+    // Reload user object, don't use the cache.
+    $recipient2 = user_load($recipient2->uid, TRUE);
+
+    // Attempt to cancel account.
+    variable_set('user_cancel_method', 'user_cancel_delete');
+    $this->drupalGet('user/' . $recipient2->uid . '/edit');
+    $this->drupalPost(NULL, NULL, t('Cancel account'));
+
+    // Confirm account cancellation.
+    $timestamp = time();
+    $this->drupalPost(NULL, NULL, t('Cancel account'));
+
+    // Confirm account cancellation request.
+    $this->drupalGet("user/$recipient2->uid/cancel/confirm/$timestamp/" . user_pass_rehash($recipient2->pass, $timestamp, $recipient2->login));
+
+    // Simpletest thinks that we are still logged in.
+    $this->loggedInUser = NULL;
+
+    $this->drupalLogin($admin);
+    $this->drupalGet('messages/view/' . $return['message']['thread_id']);
+    $this->assertText($body1, 'First message is still displayed');
+    $this->assertNoText($edit['body'], t('Reply of deleted user is not displayed anymore'));
   }
 
   /**
Index: pm_block_user/pm_block_user.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/privatemsg/pm_block_user/pm_block_user.module,v
retrieving revision 1.1.2.8.2.6
diff -u -p -r1.1.2.8.2.6 pm_block_user.module
--- pm_block_user/pm_block_user.module	27 Oct 2009 11:49:07 -0000	1.1.2.8.2.6
+++ pm_block_user/pm_block_user.module	5 Nov 2009 20:23:55 -0000
@@ -562,3 +562,16 @@ function pm_block_user_privatemsg_messag
     }
   }
 }
+
+/**
+ * Implements hook_user_cancel().
+ */
+function pm_block_user_user_cancel($edit, $account, $method) {
+  // Always delete, we don't need to keepy anonymous blocking rules.
+  db_delete('pm_block_user')
+    ->condition(db_or()
+      ->condition('author', $account->uid)
+      ->condition('recipient', $account->uid)
+    )
+    ->delete();
+}
Index: privatemsg_filter/privatemsg_filter.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/privatemsg/privatemsg_filter/privatemsg_filter.module,v
retrieving revision 1.1.2.17.2.8
diff -u -p -r1.1.2.17.2.8 privatemsg_filter.module
--- privatemsg_filter/privatemsg_filter.module	29 Oct 2009 15:57:14 -0000	1.1.2.17.2.8
+++ privatemsg_filter/privatemsg_filter.module	5 Nov 2009 20:23:58 -0000
@@ -770,4 +770,14 @@ function privatemsg_filter_sql_tags_auto
     $query->condition('pmt.tag', $tags, 'NOT IN');
   }
   return $query;
+}
+
+/**
+ * Implements hook_user_cancel().
+ */
+function privatemsg_filter_user_cancel($edit, $account, $method) {
+  // Always delete since this is only visible for the user anyway.
+  db_delete('pm_tags_index')
+    ->condition('uid', $account->uid)
+    ->delete();
 }
\ No newline at end of file
