Index: simplenews_action.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/simplenews/simplenews_action/simplenews_action.module,v
retrieving revision 1.4
diff -u -r1.4 simplenews_action.module
--- simplenews_action.module   4 Aug 2008 06:10:21 -0000   1.4
+++ simplenews_action.module   14 Dec 2008 21:05:52 -0000
@@ -47,6 +47,14 @@
         'user' => array('update', 'delete'),
       ),
     ),
+    'simplenews_send_email_action' => array(
+      'description' => t('Send email upon subscription'),
+      'type' => 'simplenews',
+      'configurable' => TRUE,
+      'hooks' => array(
+        'simplenews' => array('subscribe', 'unsubscribe'),
+      ),
+    ),
   );
 }
 
@@ -296,6 +304,70 @@
 }
 
 /**
+ * A configurable Drupal action. Send an email when someone subscribes or unsubscribes from a newsletter.
+ *
+ *   Available context:
+ *    $context['recipient']     email recipient
+ *
+ *   @see simplenews_send_email_action_form()
+ *   @see simplenews_send_email_action_submit()
+ */
+function simplenews_send_email_action($object, $context) {
+  $params['from'] = _simplenews_set_from();
+  $params['newsletter'] = taxonomy_get_term( $context['tid'] );
+  $params['context']['account'] = $object;
+
+  drupal_mail('simplenews', 'action_send_email', $context['recipient'], $object->language, $params, $params['from']['address']);
+}
+
+/**
+ * Implementation of a configurable Drupal action.
+ */
+function simplenews_send_email_action_form($context) {
+
+  //TODO: add field for specific newsletters to be notified of
+
+  // Set default values for form.
+  if (!isset($context['recipient'])) {
+    $context['recipient'] = '';
+  }
+
+  $form['recipient'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Recipient'),
+    '#default_value' => $context['recipient'],
+    '#maxlength' => '254',
+    '#description' => t('The email address to which the message should be sent.'),
+  );
+
+  return $form;
+}
+
+/**
+ * Process simplenews_send_email_action form submissions.
+ */
+function simplenews_send_email_action_submit($form, $form_state) {
+  $form_values = $form_state['values'];
+
+  $params = array(
+    'recipient' => $form_values['recipient'],
+  );
+  return $params;
+}
+
+/**
+ * Validate simplenews_send_email_action form submissions.
+ */
+function simplenews_send_email_action_validate($form, $form_state) {
+  $form_values = $form_state['values'];
+  // Validate the configuration form.
+  if (!valid_email_address($form_values['recipient'])) {
+    form_set_error('recipient', t('Please enter a valid email address.'));
+  }
+}
+
+
+/**
  * Implementation of hook_hook_info().
  */
 function simplenews_hook_info() {