Index: modules/contact/contact.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/contact/contact.module,v
retrieving revision 1.91
diff -u -r1.91 contact.module
--- modules/contact/contact.module	26 Jun 2007 22:21:08 -0000	1.91
+++ modules/contact/contact.module	27 Jun 2007 21:57:15 -0000
@@ -360,32 +360,25 @@
  * Process the personal contact page form submission.
  */
 function contact_mail_user_submit($form, &$form_state) {
-  global $user;
+  global $user, $language;
 
   $account = user_load(array('uid' => arg(1), 'status' => 1));
-  // Compose the body:
-  $message[] = "$account->name,";
-  $message[] = t("!name (!name-url) has sent you a message via your contact form (!form-url) at !site.", array('!name' => $user->name, '!name-url' => url("user/$user->uid", array('absolute' => TRUE)), '!form-url' => url($_GET['q'], array('absolute' => TRUE)), '!site' => variable_get('site_name', 'Drupal')));
-  $message[] = t("If you don't want to receive such e-mails, you can change your settings at !url.", array('!url' => url("user/$account->uid", array('absolute' => TRUE))));
-  $message[] = t('Message:');
-  $message[] = $form_state['values']['message'];
 
   // Prepare all fields:
   $to = $account->mail;
   $from = $user->mail;
 
-  // Format the subject:
-  $subject = '['. variable_get('site_name', 'Drupal') .'] '. $form_state['values']['subject'];
-
-  // Prepare the body:
-  $body = drupal_wrap_mail(implode("\n\n", $message));
+  // Prepare the parameters:
+  $values = $form_state['values'];
+  $values['account'] = $account;
+  $values['user'] = $user;
 
   // Send the e-mail:
-  drupal_mail('contact-user-mail', $to, $subject, $body, $from);
+  drupal_get_mail('contact_user_mail', $to, $from, user_language($account), $values, TRUE);
 
-  // Send a copy if requested:
+  // Send a copy if requested, using current language:
   if ($form_state['values']['copy']) {
-    drupal_mail('contact-user-copy', $from, $subject, $body, $from);
+    drupal_get_mail('contact_user_copy', $from, $from, $language, $values, TRUE);
   }
 
   // Log the operation:
@@ -504,35 +497,30 @@
  * Process the site-wide contact page form submission.
  */
 function contact_mail_page_submit($form, &$form_state) {
-
+  global $language;
+  
   // E-mail address of the sender: as the form field is a text field,
   // all instances of \r and \n have been automatically stripped from it.
   $from = $form_state['values']['mail'];
 
-  // Compose the body:
-  $message[] = t("!name sent a message using the contact form at !form.", array('!name' => $form_state['values']['name'], '!form' => url($_GET['q'], array('absolute' => TRUE))));
-  $message[] = $form_state['values']['message'];
-
   // Load the category information:
   $contact = db_fetch_object(db_query("SELECT * FROM {contact} WHERE cid = %d", $form_state['values']['cid']));
 
-  // Format the category:
-  $subject = t('[!category] !subject', array('!category' => $contact->category, '!subject' => $form_state['values']['subject']));
-
-  // Prepare the body:
-  $body = drupal_wrap_mail(implode("\n\n", $message));
+  // Prepare parameters
+  $values = $form_state['values'];
+  $values['contact'] = $contact;
+  
+  // Send the e-mail to the recipients using default language:
+  drupal_get_mail('contact_page_mail', $contact->recipients, $from, language_default(), $values, TRUE); 
 
-  // Send the e-mail to the recipients:
-  drupal_mail('contact-page-mail', $contact->recipients, $subject, $body, $from);
-
-  // If the user requests it, send a copy.
+  // If the user requests it, send a copy using current language.
   if ($form_state['values']['copy']) {
-    drupal_mail('contact-page-copy', $from, $subject, $body, $from);
+    drupal_get_mail('contact_page_copy', $from, $from, $language, $values, TRUE);
   }
 
-  // Send an auto-reply if necessary:
+  // Send an auto-reply if necessary using current language:
   if ($contact->reply) {
-    drupal_mail('contact-page-autoreply', $from, $subject, drupal_wrap_mail($contact->reply), $contact->recipients);
+    drupal_get_mail('contact_page_autoreply', $from, $contact->recipients, $language, $values, TRUE);
   }
 
   // Log the operation:
@@ -546,3 +534,35 @@
   $form_state['redirect'] = '';
   return;
 }
+
+/**
+ * Implementation of hook_mail_text().
+ */
+function contact_mail_text(&$message, $values = array()) {
+  $language = $message['#language'];
+  switch ($message['#mail_id']) {
+    case 'contact_page_mail':
+    case 'contact_page_copy':
+      $contact = $values['contact'];
+      $message['#subject'] .= t('[!category] !subject', array('!category' => $contact->category, '!subject' => $values['subject']), $language->language);
+      $message['#body'][] = t("!name sent a message using the contact form at !form.", array('!name' => $values['name'], '!form' => url($_GET['q'], array('absolute' => TRUE, 'language' => $language))), $language->language);
+      $message['#body'][] = $values['message'];
+      break;
+    case 'contact_page_autoreply':
+      $message['#subject'] .= t('[!category] !subject', array('!category' => $contact->category, '!subject' => $values['subject']), $language->language);
+      $contact = $values['contact'];
+      $message['#body'][] = $contact->reply;
+      break;
+    case 'contact_user_mail':
+    case 'contact_user_copy':
+      $user = $values['user'];
+      $account = $values['account'];
+      $message['#subject'] .= '['. variable_get('site_name', 'Drupal') .'] '. $values['subject'];
+      $message['#body'][] = "$account->name,";
+      $message['#body'][] = t("!name (!name-url) has sent you a message via your contact form (!form-url) at !site.", array('!name' => $user->name, '!name-url' => url("user/$user->uid", array('absolute' => TRUE, 'language' => $language)), '!form-url' => url($_GET['q'], array('absolute' => TRUE, 'language' => $language)), '!site' => variable_get('site_name', 'Drupal')), $language->language);
+      $message['#body'][] = t("If you don't want to receive such e-mails, you can change your settings at !url.", array('!url' => url("user/$account->uid", array('absolute' => TRUE))), $language->language);
+      $message['#body'][] = t('Message:', NULL, $language->language);
+      $message['#body'][] = $values['message'];
+      break;
+  }
+}
\ No newline at end of file
Index: includes/mail.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/mail.inc,v
retrieving revision 1.1
diff -u -r1.1 mail.inc
--- includes/mail.inc	26 Jun 2007 22:21:08 -0000	1.1
+++ includes/mail.inc	27 Jun 2007 21:57:14 -0000
@@ -2,11 +2,11 @@
 // $Id: mail.inc,v 1.1 2007/06/26 22:21:08 goba Exp $
 
 /**
- * Send an e-mail message, using Drupal variables and default settings.
+ * Build an e-mail message, using Drupal variables and default settings.
  * More information in the <a href="http://php.net/manual/en/function.mail.php">
  * PHP function reference for mail()</a>
  *
- * @param $mailkey
+ * @param $mail_id
  *   A key to identify the mail sent, for altering.
  * @param $to
  *   The mail address or addresses where the message will be send to. The
@@ -15,23 +15,19 @@
  *    user@example.com, anotheruser@example.com
  *    User <user@example.com>
  *    User <user@example.com>, Another User <anotheruser@example.com>
- * @param $subject
- *   Subject of the e-mail to be sent. This must not contain any newline
- *   characters, or the mail may not be sent properly.
- * @param $body
- *   Message to be sent. Accepts both CRLF and LF line-endings.
- *   E-mail bodies must be wrapped. You can use drupal_wrap_mail() for
- *   smart plain text wrapping.
  * @param $from
  *   Sets From, Reply-To, Return-Path and Error-To to this value, if given.
- * @param $headers
- *   Associative array containing the headers to add. This is typically
- *   used to add extra headers (From, Cc, and Bcc).
- *   <em>When sending mail, the mail must contain a From header.</em>
- * @return Returns TRUE if the mail was successfully accepted for delivery,
- *   FALSE otherwise.
+ * @param $language
+ *   Language to compose the e-mail
+ * @param $send
+ *   Optionally send the message. If so, the result of drupal_mail will be 
+ *   returned in the '#result' element of the returned array
+ * @return Returns mail array
  */
-function drupal_mail($mailkey, $to, $subject, $body, $from = NULL, $headers = array()) {
+function drupal_get_mail($mail_id, $to, $from, $language, $params = array(), $send = FALSE) {
+  // Bundle up the variables into a structured array for altering.
+  $message = array('#mail_id' => $mail_id, '#to' => $to,  '#from' => $from, '#language' => $language, '#subject' => '', '#body' => array());
+  // Build the default headers
   $defaults = array(
     'MIME-Version' => '1.0',
     'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
@@ -48,11 +44,63 @@
   if ($from) {
     $defaults['From'] = $defaults['Reply-To'] = $from;
   }
-  $headers = array_merge($defaults, $headers);
-
-  // Bundle up the variables into a structured array for altering.
-  $message = array('#mail_id' => $mailkey, '#to' => $to, '#subject' => $subject, '#body' => $body, '#from' => $from, '#headers' => $headers);
+  $message['#headers'] = $defaults;
+    
+  // Build the e-mail invoking hook_mail_text()
+  foreach (module_list() as $module) {
+    $function = $module .'_mail_text';
+    if (function_exists($function)) {
+      $function($message, $params);
+    }    
+  }
+  // Invoke hook_mail_alter()
   drupal_alter('mail', $message);
+  
+  // Now build the e-mail body if not already built
+  $message['#body'] = is_array($message['#body']) ? drupal_wrap_mail(implode("\n\n", $message['#body'])) : drupal_wrap_mail($message['#body']);
+  
+  // Optionally send e-mail 
+  if ($send) {
+    $message['#result'] = drupal_mail($message);
+  }
+  
+  return $message;
+}
+
+/**
+ * Send an e-mail message, using Drupal variables and default settings.
+ * More information in the <a href="http://php.net/manual/en/function.mail.php">
+ * PHP function reference for mail()</a>
+ *
+ * @param $message
+ *  Mail array with the following elements:
+ * 
+ * #mail_id 
+ *  A key to identify the mail sent, for altering.
+ * #to
+ *   The mail address or addresses where the message will be send to. The
+ *   formatting of this string must comply with RFC 2822. Some examples are:
+ *    user@example.com
+ *    user@example.com, anotheruser@example.com
+ *    User <user@example.com>
+ *    User <user@example.com>, Another User <anotheruser@example.com>
+ * #subject
+ *   Subject of the e-mail to be sent. This must not contain any newline
+ *   characters, or the mail may not be sent properly.
+ * #body
+ *   Message to be sent. Accepts both CRLF and LF line-endings.
+ *   E-mail bodies must be wrapped. You can use drupal_wrap_mail() for
+ *   smart plain text wrapping.
+ * #from
+ *   Sets From, Reply-To, Return-Path and Error-To to this value, if given.
+ * #headers
+ *   Associative array containing the headers to add. This is typically
+ *   used to add extra headers (From, Cc, and Bcc).
+ *   <em>When sending mail, the mail must contain a From header.</em>
+ * @return Returns TRUE if the mail was successfully accepted for delivery,
+ *   FALSE otherwise.
+ */
+function drupal_mail($message) {
   $mailkey = $message['#mail_id'];
   $to = $message['#to'];
   $subject = $message['#subject'];
Index: modules/locale/locale.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/locale/locale.module,v
retrieving revision 1.180
diff -u -r1.180 locale.module
--- modules/locale/locale.module	18 Jun 2007 16:09:38 -0000	1.180
+++ modules/locale/locale.module	27 Jun 2007 21:57:16 -0000
@@ -186,12 +186,14 @@
  * Implementation of hook_user().
  */
 function locale_user($type, $edit, &$user, $category = NULL) {
-  if ($type == 'form' && $category == 'account' && variable_get('language_count', 1) > 1 && variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE) == LANGUAGE_NEGOTIATION_PATH) {
+  global $language;
+  if (variable_get('language_count', 1) > 1 && ($type == 'register' && user_access('administer users') || $type == 'form' && $category == 'account' )) {
     $languages = language_list('enabled');
     $languages = $languages['1'];
-    if ($user->language == '') {
-      $user->language = language_default('language');
-    }
+
+    // If user ir being created, so we set user language to the current page one
+    $user_language = $user ? user_language($user) : $language;
+
     $names = array();
     foreach ($languages as $langcode => $language) {
       $names[$langcode] = t($language->name) .' ('. $language->native .')';
@@ -200,11 +202,12 @@
       '#title' => t('Interface language settings'),
       '#weight' => 1,
     );
+    
     $form['locale']['language'] = array('#type' => 'radios',
       '#title' => t('Language'),
-      '#default_value' => $user->language,
+      '#default_value' => $user_language->language,
       '#options' => $names,
-      '#description' => t('Selecting a different locale will change the interface language of the site.'),
+      '#description' => t('Selecting a locale will set the default site interface and mail language for this account.'),
     );
     return $form;
   }
Index: modules/user/user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.module,v
retrieving revision 1.808
diff -u -r1.808 user.module
--- modules/user/user.module	26 Jun 2007 22:21:08 -0000	1.808
+++ modules/user/user.module	27 Jun 2007 21:57:19 -0000
@@ -1232,9 +1232,11 @@
 }
 
 function user_pass_submit($form, &$form_state) {
+  global $language;
+
   $account = $form_state['values']['account'];
-  // Mail one time login URL and instructions.
-  $mail_success = _user_mail_notify('password_reset', $account);
+  // Mail one time login URL and instructions using current language
+  $mail_success = _user_mail_notify('password_reset', $account, $language);
   if ($mail_success) {
     watchdog('user', 'Password reset instructions mailed to %name at %email.', array('%name' => $account->name, '%email' => $account->mail));
     drupal_set_message(t('Further instructions have been sent to your e-mail address.'));
@@ -1420,12 +1422,14 @@
     return;
   }
   else {
+    // Add plain text password into user account to generate mail tokens
+    $account->password = $pass;
     if ($admin && !$notify) {
       drupal_set_message(t('Created a new user account. No e-mail has been sent.'));
     }
     else if (!variable_get('user_email_verification', TRUE) && $account->status && !$admin) {
       // No e-mail verification is required, create new user account, and login user immediately.
-      _user_mail_notify('register_no_approval_required', $account, $pass);
+      _user_mail_notify('register_no_approval_required', $account);
       user_authenticate($account->name, trim($pass));
       $form_state['redirect'] = '';
       return;
@@ -1433,7 +1437,7 @@
     else if ($account->status || $notify) {
       // Create new user account, no administrator approval required.
       $op = $notify ? 'register_admin_created' : 'register_no_approval_required';
-      _user_mail_notify($op, $account, $pass);
+      _user_mail_notify($op, $account);
       if ($notify) {
         drupal_set_message(t('Password and further instructions have been e-mailed to the new user %user.', array('%user' => $name)));
       }
@@ -1445,7 +1449,7 @@
     }
     else {
       // Create new user account, administrator approval required.
-      _user_mail_notify('register_pending_approval', $account, $pass);
+      _user_mail_notify('register_pending_approval', $account);
       drupal_set_message(t('Thank you for applying for an account. Your account is currently pending approval by the site administrator.<br />In the meantime, your password and further instructions have been sent to your e-mail address.'));
 
     }
@@ -1707,44 +1711,60 @@
   return $account->content;
 }
 
-/*** Administrative features ***********************************************/
+/**
+ * Implementation of hook_mail_text()
+ */
+function user_mail_text(&$message, $params) {
+  if (strpos($message['#mail_id'], 'user_mail_') === 0) {
+    // Get user account from parameters
+    $account = $params['account'];
+    $language = $message['#language'];
+    $variables = user_mail_tokens($account, $language);
+    $message['#subject'] .= _user_mail_text($message['#mail_id'].'_subject', $language, $variables);
+    $message['#body'][] = _user_mail_text($message['#mail_id'].'_body', $language, $variables);
+  }
+}
 
-function _user_mail_text($messageid, $variables = array()) {
+/*** Administrative features ***********************************************/
 
+function _user_mail_text($messageid, $language, $variables) {
   // Check if an admin setting overrides the default string.
-  if ($admin_setting = variable_get('user_mail_'. $messageid, FALSE)) {
+  if ($admin_setting = variable_get($messageid, FALSE)) {
     return strtr($admin_setting, $variables);
   }
   // No override, return with default strings.
   else {
     switch ($messageid) {
-      case 'register_no_approval_required_subject':
-        return t('Account details for !username at !site', $variables);
-      case 'register_no_approval_required_body':
-        return t("!username,\n\nThank you for registering at !site. You may now log in to !login_uri using the following username and password:\n\nusername: !username\npassword: !password\n\nYou may also log in by clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.\n\n\n--  !site team", $variables);
-      case 'register_admin_created_subject':
-        return t('An administrator created an account for you at !site', $variables);
-      case 'register_admin_created_body':
-        return t("!username,\n\nA site administrator at !site has created an account for you. You may now log in to !login_uri using the following username and password:\n\nusername: !username\npassword: !password\n\nYou may also log in by clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.\n\n\n--  !site team", $variables);
-      case 'register_pending_approval_subject':
-        return t('Account details for !username at !site (pending admin approval)', $variables);
-      case 'register_pending_approval_body':
-        return t("!username,\n\nThank you for registering at !site. Your application for an account is currently pending approval. Once it has been approved, you will receive another e-mail containing information about how to log in, set your password, and other details.\n\n\n--  !site team", $variables);
-      case 'password_reset_subject':
-        return t('Replacement login information for !username at !site', $variables);
-      case 'password_reset_body':
-        return t("!username,\n\nA request to reset the password for your account has been made at !site.\n\nYou may now log in to !uri_brief clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once. It expires after one day and nothing will happen if it's not used.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.", $variables);
-      case 'status_activated_subject':
-        return t('Account details for !username at !site (approved)', $variables);
-      case 'status_activated_body':
+      case 'user_mail_register_no_approval_required_subject':
+        return t('Account details for !username at !site', $variables, $language->language);
+      case 'user_mail_register_no_approval_required_body':
+        return t("!username,\n\nThank you for registering at !site. You may now log in to !login_uri using the following username and password:\n\nusername: !username\npassword: !password\n\nYou may also log in by clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.\n\n\n--  !site team", $variables, $language->language);
+      case 'user_mail_register_admin_created_subject':
+        return t('An administrator created an account for you at !site', $variables, $language->language);
+      case 'user_mail_register_admin_created_body':
+        return t("!username,\n\nA site administrator at !site has created an account for you. You may now log in to !login_uri using the following username and password:\n\nusername: !username\npassword: !password\n\nYou may also log in by clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.\n\n\n--  !site team", $variables, $language->language);
+      case 'user_mail_register_pending_approval_subject':
+      case 'user_mail_register_pending_approval_admin_subject':
+        return t('Account details for !username at !site (pending admin approval)', $variables, $language->language);
+      case 'user_mail_register_pending_approval_body':
+        return t("!username,\n\nThank you for registering at !site. Your application for an account is currently pending approval. Once it has been approved, you will receive another e-mail containing information about how to log in, set your password, and other details.\n\n\n--  !site team", $variables, $language->language);
+      case 'user_mail_register_pending_approval_admin_body':
+        return t("!username has applied for an account.\n\n!edit_uri", $variables, $language->language);
+      case 'user_mail_password_reset_subject':
+        return t('Replacement login information for !username at !site', $variables, $language->language);
+      case 'user_mail_password_reset_body':
+        return t("!username,\n\nA request to reset the password for your account has been made at !site.\n\nYou may now log in to !uri_brief clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once. It expires after one day and nothing will happen if it's not used.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.", $variables, $language->language);
+      case 'user_mail_status_activated_subject':
+        return t('Account details for !username at !site (approved)', $variables, $language->language);
+      case 'user_mail_status_activated_body':
         return "!username,\n\nYour account at !site has been activated.\n\nYou may now log in by clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.\n\nOnce you have set your own password, you will be able to log in to !login_uri in the future using the following username:\n\nusername: !username\n";
-      case 'status_blocked_subject':
-        return t('Account details for !username at !site (blocked)', $variables);
-      case 'status_blocked_body':
+      case 'user_mail_status_blocked_subject':
+        return t('Account details for !username at !site (blocked)', $variables, $language->language);
+      case 'user_mail_status_blocked_body':
         return "!username,\n\nYour account on !site has been blocked.";
-      case 'status_deleted_subject':
-        return t('Account details for !username at !site (deleted)', $variables);
-      case 'status_deleted_body':
+      case 'user_mail_status_deleted_subject':
+        return t('Account details for !username at !site (deleted)', $variables, $language->language);
+      case 'user_mail_status_deleted_body':
         return "!username,\n\nYour account on !site has been deleted.";
     }
   }
@@ -3091,12 +3111,12 @@
  * @param $account
  *  The user object of the account being notified.  Must contain at
  *  least the fields 'uid', 'name', and 'mail'.
- * @param $password
- *  Optional string containing the user's current password (if known).
+ * @param $language
+ *  Language for the tokens
  * @return
  *  Array of mappings from token names to values (for use with strtr()).
  */
-function user_mail_tokens($account, $password = NULL) {
+function user_mail_tokens($account, $language) {
   global $base_url;
   $tokens = array(
     '!username' => $account->name,
@@ -3105,17 +3125,33 @@
     '!uri' => $base_url,
     '!uri_brief' => substr($base_url, strlen('http://')),
     '!mailto' => $account->mail,
-    '!date' => format_date(time()),
-    '!login_uri' => url('user', array('absolute' => TRUE)),
-    '!edit_uri' => url('user/'. $account->uid .'/edit', array('absolute' => TRUE)),
+    '!date' => format_date(time(), 'medium', '', NULL, $language->language),
+    '!login_uri' => url('user', array('absolute' => TRUE, 'language' => $language)),
+    '!edit_uri' => url('user/'. $account->uid .'/edit', array('absolute' => TRUE, 'language' => $language)),
   );
-  if (!empty($password)) {
-    $tokens['!password'] = $password;
+  if (!empty($account->password)) {
+    $tokens['!password'] = $account->password;
   }
   return $tokens;
 }
 
 /**
+ * Get user language
+ * 
+ * @param $account
+ *   User account
+ * @param $default
+ *   Optional default language if account has no valid language
+ */
+function user_language($account, $default = NULL) {
+  $language_list = language_list();
+  if ($account->language && isset($language_list[$account->language])) {
+    return $language_list[$account->language];
+  } else {
+    return $default ? $default : language_default();
+  }
+}
+/**
  * Conditionally create and send a notification email when a certain
  * operation happens on the given user account.
  *
@@ -3136,35 +3172,28 @@
  *  The user object of the account being notified.  Must contain at
  *  least the fields 'uid', 'name', and 'mail'.
  *
- * @param $password
- *  Optional string containing the user's current password (if known).
- *
+ * @param $language
+ *  Optional anguage to use for the notification, overriding account language
  * @return
  *  The return value from drupal_mail(), if ends up being called.
  */
-function _user_mail_notify($op, $account, $password = NULL) {
-  $mail_id = 'user-'. strtr($op, '_', '-');
-  if ($op == 'register_pending_approval') {
-    // Special case, since we need to distinguish what we send to the
-    // user and what we send to the administrator, handled below.
-    $mail_id .= '-user';
-  }
+function _user_mail_notify($op, $account, $language = NULL) {
   // By default, we always notify except for deleted and blocked.
   $default_notify = ($op != 'status_deleted' && $op != 'status_blocked');
   $notify = variable_get('user_mail_'. $op .'_notify', $default_notify);
   $result = NULL;
   if ($notify) {
+    $params['account'] = $account;
+    $language = $language ? $language : user_language($account);
     $from = variable_get('site_mail', ini_get('sendmail_from'));
-    $variables = user_mail_tokens($account, $password);
-    $subject = _user_mail_text($op .'_subject', $variables);
-    $body = drupal_wrap_mail(_user_mail_text($op .'_body', $variables));
-    $result = drupal_mail($mail_id, $account->mail, $subject, $body, $from);
+    $mail = drupal_get_mail('user_mail_'.$op, $account->mail, $from, $language, $params, TRUE);
     if ($op == 'register_pending_approval') {
       // If a user registered requiring admin approval, notify the admin, too.
-      drupal_mail('user-register-approval-admin', $from, $subject, t("!username has applied for an account.\n\n!edit_uri", $variables), $from);
+      // We use the site default language for this
+      drupal_get_mail('user_mail_register_pending_approval_admin', $from, $from, language_default(), $params, TRUE);
     }
   }
-  return $result;
+  return empty($mail) ? NULL : $mail['#result'];
 }
 
 /**
