Index: pm_email_notify/pm_email_notify.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/privatemsg/pm_email_notify/pm_email_notify.module,v
retrieving revision 1.15
diff -u -p -r1.15 pm_email_notify.module
--- pm_email_notify/pm_email_notify.module	22 Oct 2010 09:02:10 -0000	1.15
+++ pm_email_notify/pm_email_notify.module	9 Nov 2010 19:09:10 -0000
@@ -62,6 +62,50 @@ function pm_email_notify_privatemsg_mess
 }
 
 /**
+ * Implements hook_privatemsg_message_recipient_changed().
+ *
+ * This adds support of notifying users, added to message as recipients after message was sent.
+ * That technique is used in privatemsg_roles, so this adds support of it.
+ */
+function pm_email_notify_privatemsg_message_recipient_changed($mid, $thread_id, $uid, $type, $add) {
+  // First check if we need to send email
+
+  if (!$add)
+    return;
+
+  $thread_id = db_result(db_query('SELECT thread_id FROM {pm_index} WHERE mid = %d', $mid));
+  // Only add the recipient if he does not block the author.
+  $author_uid = db_result(db_query('SELECT author FROM {pm_message} WHERE mid = %d', $mid));
+  $recipient = privatemsg_user_load($uid);
+  $user_blocked = module_invoke_all('privatemsg_block_message', privatemsg_user_load($author_uid), array(privatemsg_recipient_key($recipient) => $recipient));
+  if (count($user_blocked) <> 0) {
+    return;
+  }
+
+  // Make sure to only add a recipient once. The types user and hidden are
+  // considered equal here.
+  if ($type == 'user' || $type == 'hidden') {
+    $exists = db_result(db_query("SELECT 1 FROM {pm_index} WHERE type IN ('user', 'hidden') AND recipient = %d AND mid = %d", $uid, $mid));
+  }
+  else {
+    $exists = db_result(db_query("SELECT 1 FROM {pm_index} WHERE type = '%s' AND recipient = %d AND mid = %d", $type, $uid, $mid));
+  }
+
+  if (!$exists)
+    return;
+
+  // check if recipient enabled email notifications
+  if (!(isset($recipient->uid) && _pm_email_notify_is_enabled($recipient->uid)))
+    return;
+
+  // OK, we need to send e-mail, do it
+  $message = privatemsg_message_load($mid);
+  $params['message'] = $message;
+  $params['recipient'] = $recipient;
+  drupal_mail('pm_email_notify', 'notice', $recipient->mail, user_preferred_language($recipient), $params, variable_get('pm_email_notify_from',''));
+}
+
+/**
  * Implements hook_mail().
  */
 function pm_email_notify_mail($key, &$message, $params) {
