Index: simplenews.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simplenews/simplenews.module,v
retrieving revision 1.118
diff -u -p -r1.118 simplenews.module
--- simplenews.module	5 Jul 2008 14:23:32 -0000	1.118
+++ simplenews.module	6 Jul 2008 15:38:38 -0000
@@ -1470,6 +1470,9 @@ function simplenews_mail_send($nid = NUL
   $limit = isset($limit) ? $limit : variable_get('simplenews_throttle', 20);
   if ($messages = simplenews_mail_spool_get(SIMPLENEWS_SPOOL_PENDING, $nid, $vid, $limit)) {
     $mail_sent = array();
+    // We send the newsletter the permissions of the node author.
+    // First record current user to be able to switch back later.
+    simplenews_switch_user();
 
     foreach($messages as $key => $message) {
       // Get subscription data for recipient and language
@@ -1478,8 +1481,12 @@ function simplenews_mail_send($nid = NUL
       $subscription = simplenews_get_subscription($account);
       $params['context']['account'] = $subscription;
 
+      // Switch to the node author user to use the correct permissions.
+      // After loading the node we switch back to the original user.
+      simplenews_switch_user($message['nid'], $message['vid']);
       // Get node data for the mail
       $node = node_load(array('nid' => $message['nid'], 'vid' => $message['vid']));
+      simplenews_switch_user();
       $params['from'] = _simplenews_set_from($node);
       $params['context']['node'] = $node;
   
@@ -1767,6 +1774,44 @@ function simplenews_private_key() {
 }
 
 /**
+ * Switch from original user to node author uaser and back.
+ *
+ * Note: You first need to run simplenews_switch_user without
+ * argument to store the current user. Call simplenews_switch_user
+ * without argument to set the user back to the original user.
+ * Based on mailhandler_switch_user();
+ *
+ * @param $uid The user ID to switch to
+ *
+ */
+function simplenews_switch_user($nid = NULL, $vid = NULL) {
+  global $user;
+  static $orig_user = array();
+
+  if (isset($nid)) {
+    session_save_session(FALSE);
+    // Get user who is author of the node;
+    if (isset($vid)) {
+      $uid = db_result(db_query('SELECT n.uid FROM {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = %d WHERE n.nid = %d', $vid, $nid));
+    }
+    else {
+      $uid = db_result(db_query('SELECT n.uid FROM {node} n INNER JOIN {node_revisions} r ON r.vid = n.vid WHERE n.nid = %d', $nid));
+    }
+    $user = user_load(array('uid' => $uid));
+  }
+  // retrieve the initial user, can be called multiple times
+  else if (count($orig_user)) {
+    $user = array_shift($orig_user);
+    session_save_session(TRUE);
+    array_unshift($orig_user, $user);
+  }
+  // store the initial user
+  else {
+    $orig_user[] = $user;
+  }
+}
+
+/**
  * Implementation of hook_help.
  */
 function simplenews_help($path, $arg) {
