### Eclipse Workspace Patch 1.0
#P CVS simplenews HEAD
Index: simplenews.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simplenews/simplenews.install,v
retrieving revision 1.3
diff -u -r1.3 simplenews.install
--- simplenews.install	19 Dec 2006 20:34:41 -0000	1.3
+++ simplenews.install	28 Mar 2007 16:51:57 -0000
@@ -2,6 +2,10 @@
 // $Id: simplenews.install,v 1.3 2006/12/19 20:34:41 robroy Exp $
 
 function simplenews_install() {
+  // Ensure that simplenews is processed after upload module
+  $weight = db_result(db_query("SELECT weight FROM {system} WHERE name = 'upload'")); 
+  db_query("UPDATE {system} SET weight = %s WHERE name = 'simplenews'", $weight + 1);
+  
   $result = array();
   switch ($GLOBALS['db_type']) {
     case 'mysqli':
Index: simplenews.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simplenews/simplenews.module,v
retrieving revision 1.56
diff -u -r1.56 simplenews.module
--- simplenews.module	20 Feb 2007 18:47:01 -0000	1.56
+++ simplenews.module	28 Mar 2007 16:52:01 -0000
@@ -339,7 +339,7 @@
     }
     foreach ($mails as $mail) {
       $mail = trim($mail);
-      if ($mail == '') {
+      if (empty($mail)) {
         form_set_error('', t('Cannot send test newsletter: no valid test e-mail address specified.'));
       }
       elseif (!valid_email_address($mail)) {
@@ -395,7 +395,7 @@
   //since simplenews_cron() also calls _simplenews_send().
   $s_status = ($node->send == 1 && user_access('send newsletter')) ? 1 : 0;
   db_query("INSERT INTO {simplenews_newsletters} (nid, tid, s_status, s_format, priority, receipt)
-		  VALUES (%d, %d, %d, '%s', %d, %d)", $node->nid, $node->simplenews_tid, $s_status, $node->s_format, $node->priority, $node->receipt);
+    VALUES (%d, %d, %d, '%s', %d, %d)", $node->nid, $node->simplenews_tid, $s_status, $node->s_format, $node->priority, $node->receipt);
 }
 
 /**
@@ -407,7 +407,7 @@
   $node->simplenews_tid = $tid ? $tid[0] : 0;
   $s_status = ($node->send == 1 && user_access('send newsletter')) ? 1 : 0;
   db_query("UPDATE {simplenews_newsletters} SET tid = %d, s_status = %d, s_format = '%s', priority = %d, receipt = %d
-		  WHERE nid = %d", $node->simplenews_tid, $s_status, $node->s_format, $node->priority, $node->receipt, $node->nid);
+    WHERE nid = %d", $node->simplenews_tid, $s_status, $node->s_format, $node->priority, $node->receipt, $node->nid);
 }
 
 /**
@@ -977,8 +977,10 @@
 
   // To play well with other modules that add content to the node,
   // simplenews_node_prepare() must mimic node_view() as far as possible.
-  // Following is adapted from node_view().
   $node = node_build_content($node, false, true);
+
+  unset($node->content['files']);
+
   $content = drupal_render($node->content);
   $node->body = $content;
   unset($node->teaser);
@@ -1043,8 +1045,9 @@
       $user_node = drupal_clone($node);
       $user_node = theme('simplenews_newsletter_footer', $user_node, $hash);
 
+      $attachments = simplenews_get_attachments($node);
       $user_node->to = $mail->mail;
-      if (simplenews_mail_send($user_node)) {
+      if (simplenews_mail_send($user_node, $attachments)) {
         // TODO: This looks like it may choke if you were sending multiple
         // newsletters through cron. Should move s_status to snid_tid table
         // or somewhere else to see which newsletter has been sent.
@@ -1096,10 +1099,11 @@
   $term = $tid ? taxonomy_get_term($tid) : FALSE;
   $name = $term ? $term->name : 'Unassigned newsletter';
   $node->body .= "\n\n-- \n". t('Footer will be appended here');
+  $attachments = simplenews_get_attachments($node);
   $recipients = $input->test_address;
   foreach ($recipients as $to) {
     $node->to = $to;
-    if (simplenews_mail_send($node)) {
+    if (simplenews_mail_send($node, $attachments)) {
       drupal_set_message(t('Test newsletter sent to %recipient.', array('%recipient' => $to)));
     }
   }
@@ -1126,13 +1130,38 @@
 }
 
 /**
- * Mail engine to send newsletter. If you want to send HTML newsletters you need
- * to plug in an extra module
+ * Get attachement data if the newsletter node has some
+ *  
+ * @param $node The node array of the newsletter issue.
+ * @return array of arrays. Empty array if no attachements
+ *   array ('filepath', 'filemime') match mimemail requirements
+ **/
+function simplenews_get_attachments($node) {
+  //Attachment List setting is ignored
+  //user_access('view uploaded files') is not used
+
+  $files = array();
+  if (isset($node->files)) {
+    foreach ($node->files as $file) {
+      $files[] = array(
+        'filepath' => $file->filepath,
+        'filemime' => $file->filemime,
+      );
+    }
+  }
+  
+  return $files;
+}
+
+/**
+ * Mail engine to send newsletter. HTML newsletters require mimemail module.
  *
  * @param $mail
  *   An object with at least $mail->to, $mail->subject, and $mail->message.
+ * @param $attachments
+ *   Array of arrays with attachment data. 
  */
-function simplenews_mail_send($mail) {
+function simplenews_mail_send($mail, $attachments = array()) {
   $from_email = isset($mail->from_address) ? $mail->from_address : variable_get('site_mail', ini_get('sendmail_from'));
   $from = isset($mail->from_name) ? '"'. addslashes($mail->from_name).'" <'. $from_email .'>' : $from_email;
 
@@ -1193,8 +1222,7 @@
       $plain_text_only = FALSE;
       $plain_text_body = NULL;
     }
-
-    return mimemail($from, $mail->to, $mail->subject, $mail->body, $plain_text_only, $headers, $plain_text_body);
+    return mimemail($from, $mail->to, $mail->subject, $mail->body, $plain_text_only, $headers, $plain_text_body, $attachments);
   }
   else {
     return drupal_mail('simplenews-send-mail', $mail->to, $mail->subject, $mail->body, $from_email, $headers);
@@ -2363,4 +2391,4 @@
 
   $mail->body .= $footer;
   return $mail;
-}
\ No newline at end of file
+}
