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.93
diff -u -p -r1.70.2.30.2.91.2.64.2.93 privatemsg.module
--- privatemsg.module	10 Nov 2010 15:49:58 -0000	1.70.2.30.2.91.2.64.2.93
+++ privatemsg.module	22 Nov 2010 23:45:18 -0000
@@ -2798,6 +2798,12 @@ function privatemsg_tokens($type, $token
  */
 function privatemsg_token_replace($text, $data, array $options = array()) {
   global $user;
+  if (empty($data['privatemsg_recipient'])) {
+    $recipient = $user;
+  }
+  else {
+    $recipient = $data['privatemsg_recipient'];
+  }
 
   if (isset($options['language'])) {
     $url_options['language'] = $options['language'];
@@ -2809,12 +2815,13 @@ function privatemsg_token_replace($text,
 
   $message = $data['privatemsg_message'];
   $show_span = !isset($options['privatemsg-show-span']) || $options['privatemsg-show-span'];
+  $show_invalid = !isset($options['privatemsg-display-invalid']) || $options['privatemsg-display-invalid'];
 
   // We do not replace tokens if the user viewing the message is the author or
   // not a real recipient to avoid confusion.
   $sql = "SELECT 1 FROM {pm_index} WHERE recipient = :uid AND type IN ('hidden', 'user') AND mid = :mid";
-  $args = array(':uid' => $user->uid, ':mid' => $message->mid);
-  if ($message->author->uid == $user->uid || !db_query($sql, $args)->fetchField()) {
+  $args = array(':uid' => $recipient->uid, ':mid' => $message->mid);
+  if ($message->author->uid == $recipient->uid || !db_query($sql, $args)->fetchField()) {
     // Get all tokens of the message.
     $tokens = token_scan($text);
     $invalid_tokens = array();
Index: pm_email_notify/pm_email_notify.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/privatemsg/pm_email_notify/pm_email_notify.admin.inc,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 pm_email_notify.admin.inc
--- pm_email_notify/pm_email_notify.admin.inc	6 Jan 2010 19:29:22 -0000	1.1.2.2
+++ pm_email_notify/pm_email_notify.admin.inc	22 Nov 2010 23:45:26 -0000
@@ -10,37 +10,54 @@
  * Menu callback for administration settings.
  */
 function pm_email_notify_admin_settings_form() {
-  $form['pm_email'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Privatemsg e-mail notification'),
-    '#collapsible' => FALSE,
-    '#collapsed' => FALSE,
-  );
-  $form['pm_email']['pm_email_notify_default'] = array(
+  $form['pm_email_notify_default'] = array(
     '#type' => 'checkbox',
     '#title' => t('Notify users of new private messages by default'),
     '#default_value' => variable_get('pm_email_notify_default', TRUE),
     '#weight' => 0,
   );
 
-  $form['pm_email']['pm_email_notify_desc'] = array(
+  $form['pm_email_notify_desc'] = array(
     '#type' => 'item',
-    '#value' => t('Customize the email messages sent to users upon receipt of a new private message. <br />Available variables are: !author, !author_uid, !pm_subject, !pm_body, !thread, !site, !login_url, !uri, !uri_brief, !message (URL) and !settings (URL).'),
+    '#title' => t('Customize the email messages sent to users upon receipt of a new private message.'),
     '#weight' => 1,
   );
 
-  $form['pm_email']['pm_email_notify_subject'] = array(
+  $form['pm_email_notify_subject'] = array(
     '#type' => 'textfield',
     '#title' => t('Subject of notification messages'),
-    '#default_value' => variable_get('pm_email_notify_subject', 'New private message at !site.'),
+    '#default_value' => variable_get('pm_email_notify_subject', t('New private message at [site:name].')),
     '#weight' => 2,
   );
 
-  $form['pm_email']['pm_email_notify_body'] = array(
+  $form['pm_email_notify_body'] = array(
     '#type' => 'textarea',
     '#title' => t('Body of notification messages'),
     '#default_value' => variable_get('pm_email_notify_body', _pm_email_notify_default_body()),
     '#weight' => 3,
   );
+
+  if (module_exists('token')) {
+    $form['token'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Token browser'),
+      '#weight' => -1,
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE,
+      '#weight' => 4,
+    );
+    $form['token']['browser'] = array(
+      '#theme' => 'token_tree',
+      '#token_types' => array('privatemsg_message'),
+    );
+  }
+  else {
+    $form['tokens'] = array(
+      '#type' => 'item',
+      '#value' => t('Available variables are: !author, !author_uid, !pm_subject, !pm_body, !thread, !site, !login_url, !uri, !uri_brief, !message (URL) and !settings (URL).'),
+      '#weight' => 4,
+    );
+  }
+
   return system_settings_form($form);
 }
\ No newline at end of file
Index: pm_email_notify/pm_email_notify.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/privatemsg/pm_email_notify/pm_email_notify.install,v
retrieving revision 1.1.2.2.2.1
diff -u -p -r1.1.2.2.2.1 pm_email_notify.install
--- pm_email_notify/pm_email_notify.install	13 Sep 2009 23:39:46 -0000	1.1.2.2.2.1
+++ pm_email_notify/pm_email_notify.install	22 Nov 2010 23:45:26 -0000
@@ -35,7 +35,7 @@ function pm_email_notify_schema() {
 }
 
 /**
- * Implement hook_uninstall().
+ * Implements hook_uninstall().
  */
 function pm_email_notify_uninstall() {
   variable_del('pm_email_notify_body');
@@ -43,3 +43,30 @@ function pm_email_notify_uninstall() {
   variable_del('pm_email_notify_subject');
 }
 
+/**
+ * Replace old placeholders with new tokens.
+ */
+function pm_email_notify_update_7000() {
+  $replacements = array(
+    '!author' => '[privatemsg_message:author]',
+    '!username' => '[privatemsg_message:recipient]',
+    '!author_uid' => '[privatemsg_message:author:uid]',
+    '!pm_subject' => '[privatemsg_message:subject]',
+    '!pm_body' => '[privatemsg_message:body]',
+    '!thread' => '[privatemsg_message:thread_id]',
+    '!site' => '[site:name]',
+    '!login-url' => '[site:login-url]',
+    '!uri' => '	[site:url]',
+    '!uri_brief' => '[site:url-brief]',
+    '!message' => '[privatemsg_message:url]',
+    '!settings' => '[privatemsg_message:recipient:edit-url]',
+  );
+  // Only update if there was actually something saved.
+  if ($subject = variable_get('pm_email_notify_subject', FALSE)) {
+    variable_set('pm_email_notify_subject', str_replace(array_keys($replacements), array_values($replacements), $subject));
+  }
+  if ($body = variable_get('pm_email_notify_body', FALSE)) {
+    variable_set('pm_email_notify_body', str_replace(array_keys($replacements), array_values($replacements), $body));
+  }
+}
+
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.1.2.3.2.19
diff -u -p -r1.1.2.3.2.19 pm_email_notify.module
--- pm_email_notify/pm_email_notify.module	9 Sep 2010 08:27:59 -0000	1.1.2.3.2.19
+++ pm_email_notify/pm_email_notify.module	22 Nov 2010 23:45:26 -0000
@@ -64,46 +64,31 @@ function pm_email_notify_privatemsg_mess
  * Implementation of hook_mail().
  */
 function pm_email_notify_mail($key, &$message, $params) {
-  $language = $message['language'];
-  $variables = _pm_email_notify_token($params['recipient'], $params['message'], $language);
   switch ($key) {
     case 'notice':
-      $message['subject'] = trim(t(variable_get('pm_email_notify_subject', 'New private message at !site.'), $variables, array('langcode' => $language->language)));
-      $message['body'] = array(trim(t(variable_get('pm_email_notify_body', _pm_email_notify_default_body()), $variables, array('langcode' => $language->language))));
+      $data = array(
+        'privatemsg_message' => $params['message'],
+        'privatemsg_recipient' => $params['recipient'],
+      );
+      $options = array(
+        'language' => user_preferred_language($params['recipient']),
+        // Don't sanitize output since this is used in an email, not a browser.
+        'sanitize' => FALSE,
+        // Custom token to avoid custom token handling.
+        'privatemsg-display-invalid' => FALSE,
+      );
+
+      $message['subject'] = trim(token_replace(variable_get('pm_email_notify_subject', 'New private message at [site:name].'), $data, $options));
+      $message['body'][] = trim(token_replace(variable_get('pm_email_notify_body', _pm_email_notify_default_body()), $data, $options));
       break;
   }
 }
 
 /**
- * Return an array of token to value mappings for user e-mail messages.
- *
- * @param $message
- *  The private message array being sent.  Must contain at
- *  least the fields 'author', 'subject', 'thread_id' and 'body'.
- * @return
- *  Array of mappings from token names to values (for use with strtr()).
- */
-function _pm_email_notify_token($recipient, $message, $language) {
-
-  $tokens = array(
-    '!author' => $message->author->name,
-    '!thread' => $message->thread_id,
-    '!pm_subject' => drupal_html_to_text(check_plain($message->subject)),
-    '!pm_body' => drupal_html_to_text(check_markup($message->body, $message->format)),
-    '!user_uid' => $recipient->uid,
-    '!message' => url('messages/view/' . $message->thread_id, array('absolute' => TRUE, 'language' => $language)),
-    '!settings' => url('user/' . $recipient->uid . '/edit', array('absolute' => TRUE, 'language' => $language)),
-  );
-
-  return $tokens;
-
-}
-
-/**
  * Returns default email notification body.
  */
 function _pm_email_notify_default_body() {
-  return "Hi !username,\n\nThis is an automatic reminder from the site !site. You have received a new private message from !author.\n\nTo read your message, follow this link:\n!message\n\nIf you don't want to receive these emails again, change your preferences here:\n!settings";
+  return "Hi [privatemsg_message:recipient],\n\nThis is an automatic reminder from the site [site:name]. You have received a new private message from [privatemsg_message:author].\n\nTo read your message, follow this link:\n[privatemsg_message:url]\n\nIf you don't want to receive these emails again, change your preferences here:\n[privatemsg_message:recipient:edit-url]";
 }
 
 /**
