Index: simplenews.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/simplenews/simplenews.module,v
retrieving revision 1.172
diff -u -r1.172 simplenews.module
--- simplenews.module   11 Dec 2008 09:53:32 -0000   1.172
+++ simplenews.module   14 Dec 2008 23:52:19 -0000
@@ -1008,7 +1008,7 @@
     db_query("INSERT INTO {simplenews_snid_tid} (snid, tid) VALUES (%d, %d)", $subscription->snid, $tid);
 
     // Execute simplenews subscribe trigger.
-    simplenews_call_actions('subscribe', $subscription);
+    simplenews_call_actions('subscribe', $subscription, $tid);
   }
   return TRUE;
 }
@@ -1057,7 +1057,7 @@
     }
 
     // Execute simplenews unsubscribe trigger
-    simplenews_call_actions('unsubscribe', $subscription);
+    simplenews_call_actions('unsubscribe', $subscription, $tid);
     }
 
   return TRUE;
@@ -1663,6 +1663,35 @@
         $message['body'] = _simplenews_subscription_confirmation_text('unsubscribe_unsubscribed', $context['account']->language, $variables);
       }
       break;
+    case 'action_send_email':
+      $account = $context['account'];
+      $newsletter = $params['newsletter'];
+      // Use formatted from address "name" <mail_address>
+      $message['headers']['From'] = $params['from']['formatted'];
+
+      $user = user_load( $account->uid );
+
+      //Anonymous users need a name
+      if (!$user->uid) {
+        $user->name = 'Anonymous User';
+      }
+
+      //Build the message body
+      //For some reason, if a user has an account on the site, this if statement is reversed (thus the || $user->uid)
+      if (simplenews_user_is_subscribed($account->mail, $newsletter->tid) || $user->uid) {
+        $body = $user->name . ' (' . $account->mail . ') just subscribed to ' . $newsletter->name;
+      }
+      else {
+        $body = $user->name . ' (' . $account->mail . ') just unsubscribed from ' . $newsletter->name;
+      }
+
+      if ($user->uid) {
+        $body .= "\n\nAccess this user's account page at the following URL:\n" . $GLOBALS['base_url'] . "/user/" . $user->uid;
+      }
+
+      $message['subject'] = $newsletter->name . ' subscription';
+      $message['body'] = $body;
+      break;
   }
 
   // Debug message to check for outgoing emails messages.
@@ -1929,7 +1958,7 @@
 /**
  * Call simplenews actions.
  */
-function simplenews_call_actions($op, $subscription) {
+function simplenews_call_actions($op, $subscription, $tid) {
   // Only call actions when the simplenews_action module is enabled.
   if (!module_exists('simplenews_action')) {
     return;
@@ -1939,6 +1968,7 @@
     'hook' => 'simplenews',
     'op' => $op,
     'account' => $subscription,
+    'tid' => $tid,
   );
   foreach ($aids as $aid => $action_info) {
     actions_do($aid, $subscription, $context);