Index: action_email_role.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/action_email_role/action_email_role.info,v
retrieving revision 1.2.2.1
diff -u -r1.2.2.1 action_email_role.info
--- action_email_role.info	5 Jun 2008 14:33:51 -0000	1.2.2.1
+++ action_email_role.info	25 Aug 2008 03:48:42 -0000
@@ -2,5 +2,5 @@
 
 name = Action email role
 description = "Provides an action to email all users in selected role(s)"
-dependencies = actions
-package = Actions
\ No newline at end of file
+package = Actions
+core = 6.x
Index: action_email_role.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/action_email_role/action_email_role.module,v
retrieving revision 1.2.2.1
diff -u -r1.2.2.1 action_email_role.module
--- action_email_role.module	5 Jun 2008 14:33:51 -0000	1.2.2.1
+++ action_email_role.module	25 Aug 2008 03:48:42 -0000
@@ -35,7 +35,7 @@
 function action_email_role_send_email_action_form($context) {
   // Set default values for form.
   if (!isset($context['recipient'])) {
-    $context['recipient'] = '';
+    $context['recipient'] = array();
   }
   if (!isset($context['subject'])) {
     $context['subject'] = '';
@@ -85,13 +85,13 @@
 /**
  * Process action_email_role_send_email_action form submissions.
  */
-function action_email_role_send_email_action_submit($form_id, $form_values) {
+function action_email_role_send_email_action_submit($form, &$form_state) {
   // Process the HTML form to store configuration. The keyed array that
   // we return will be serialized to the database.
   $params = array(
-    'recipient' => $form_values['recipient'],
-    'subject'   => $form_values['subject'],
-    'message'   => $form_values['message'],
+    'recipient' => $form_state['values']['recipient'],
+    'subject'   => $form_state['values']['subject'],
+    'message'   => $form_state['values']['message'],
   );
   return $params;
 }
@@ -101,31 +101,11 @@
  * Implementation of a configurable Drupal action. Sends an email to specified role(s).
  */
 function action_email_role_send_email_action($object, $context) {
-  $node = $object;
-
   $from = variable_get('site_mail', ini_get('sendmail_from'));
-  $recipient = $context['recipient'];
-  $subject = $context['subject'];
-  $message = $context['message'];  
-  $site_name = variable_get('site_name', 'Drupal');
-  
-  if (isset($node) && is_object($node)) {
-    $variables = array(
-      '%site_name' => $site_name,
-      '%uid' => $node->uid,
-      '%node_url' => url('node/' . $node->nid, NULL, NULL, TRUE),
-      '%node_type' => node_get_types('name', $node),
-      '%title' => check_plain($node->title),
-      '%teaser' => check_markup($node->teaser),
-      '%body' => check_markup($node->body)
-    );
-
-    $subject = strtr($subject, $variables);
-    $subject = str_replace(array("\r", "\n"), '', $subject);
-    $message = strtr($message, $variables);
-  }
-  
-  foreach($recipient as $rid => $rname) {
+  $params['object'] = $object;
+  $params['context'] = $context;
+
+  foreach ($context['recipient'] as $rid => $rname) {
     if (!empty($rname)) {
       $roles[]=$rid;
     }
@@ -133,13 +113,39 @@
 
   $emailed = 0;
   $result = db_query("SELECT ur.*, u.mail, u.name FROM {users_roles} ur LEFT JOIN {users} u ON ur.uid = u.uid WHERE ur.rid IN (%s) AND u.status = 1", implode(',', $roles));
-  while($role = db_fetch_object($result)) {
-    if (drupal_mail('action_email_role', $role->mail, $subject, $message, $from)) {
-      watchdog('action_email_role', t('Sent email to %recipient', array('%recipient' => $role->mail)));
+  while ($account = db_fetch_object($result)) {
+    if (drupal_mail('action_email_role', 'email_roles', $account->mail, 'en', $params, $from)) {
+      watchdog('action_email_role', 'Sent email to %recipient', array('%recipient' => $account->mail));
       $emailed++;
-    } else {
-      watchdog('error', t('Unable to send email to %recipient from action_email_role', array('%recipient' => $role->mail)));
+    }
+    else {
+      watchdog('error', 'Unable to send email to %recipient from action_email_role', array('%recipient' => $account->mail));
     }
   }
-  watchdog('action_email_role',"$emailed users emailed successfuly.");
-}
\ No newline at end of file
+  watchdog('action_email_role', "!emailed users emailed successfuly.", array('!emailed' => $emailed));
+}
+
+/**
+ * Implementation of hook_mail().
+ */
+function action_email_role_mail($key, &$message, $params) {
+  $node = $params['object'];
+
+  $recipient = $params['context']['recipient'];
+  $subject = $params['context']['subject'];
+  $message_body = $params['context']['message'];
+
+  $variables = array(
+    '%site_name' => variable_get('site_name', 'Drupal'),
+    '%uid' => $node->uid,
+    '%node_url' => url('node/' . $node->nid, array('absolute' => TRUE)),
+    '%node_type' => node_get_types('name', $node),
+    '%title' => check_plain($node->title),
+    '%teaser' => check_markup($node->teaser),
+    '%body' => check_markup($node->body)
+  );
+
+  $subject = strtr($subject, $variables);
+  $message['subject'] = str_replace(array("\r", "\n"), '', $subject);
+  $message['body'] = strtr($message_body, $variables);
+}
