Index: simplenews.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simplenews/simplenews.module,v
retrieving revision 1.48.2.40
diff -u -p -r1.48.2.40 simplenews.module
--- simplenews.module	4 Jul 2008 14:08:43 -0000	1.48.2.40
+++ simplenews.module	6 Jul 2008 15:31:41 -0000
@@ -1201,11 +1201,18 @@ function _simplenews_send($timer = FALSE
     $throttle = variable_get('simplenews_throttle', 20);
     static $counter = 0;
   }
-  $result = db_query(db_rewrite_sql('SELECT n.nid, s.vid, s.tid, n.created FROM {node} n INNER JOIN {simplenews_newsletters} s ON n.nid = s.nid WHERE s.s_status = %d ORDER BY n.created ASC'), 1);
+  // We send the newsletter the permissions of the node author.
+  // First record current user to be able to switch back later.
+  simplenews_switch_user();
+  
+  $result = db_query('SELECT n.nid, s.vid, s.tid, n.created FROM {node} n INNER JOIN {simplenews_newsletters} s ON n.nid = s.nid WHERE s.s_status = %d ORDER BY n.created ASC', 1);
   while ($nid = db_fetch_object($result)) {
     $term = taxonomy_get_term($nid->tid);
+    // Switch user to the node author to use the correct permissions.
+    // After collecting the node data we switch back to the original user.
+    simplenews_switch_user($nid->nid, $nid->vid);
     $node = simplenews_node_prepare($nid->nid, $nid->vid, $nid->tid);
-
+    simplenews_switch_user();
     $result2 = db_query('SELECT s.mail, s.snid FROM {simplenews_subscriptions} s INNER JOIN {simplenews_snid_tid} t ON s.snid = t.snid WHERE s.s_status = %d AND s.a_status = %d AND t.tid = %d ORDER BY s.snid ASC', 0, 1, $nid->tid);
     while ($mail = db_fetch_object($result2)) {
       $hash = _simplenews_generate_hash($mail->mail, $mail->snid, $nid->tid);
@@ -1277,6 +1284,44 @@ function simplenews_send_test($input) {
 }
 
 /**
+ * Switch from original user to node author user 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;
+  }
+}
+
+/**
 * Send confirmation email
 */
 function simplenews_mail_confirm($email, $newsletter, $snid = NULL, $op = NULL) {
