Index: simplenews.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simplenews/simplenews.admin.inc,v
retrieving revision 1.58
diff -u -p -r1.58 simplenews.admin.inc
--- simplenews.admin.inc	30 Jul 2009 19:56:47 -0000	1.58
+++ simplenews.admin.inc	6 Aug 2009 12:21:51 -0000
@@ -772,6 +772,12 @@ function simplenews_admin_settings(&$for
     '#description' => t('This vocabulary identifies newsletter series. Note that changing this vocabulary will require existing newsletters to be re-tagged and activated newsletter blocks to be re-activated.'),
     '#default_value' => variable_get('simplenews_vid', ''),
   );
+  $form['simplenews_general_settings']['simplenews_multiple'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Multiple select'),
+    '#default_value' => variable_get('simplenews_multiple', ''),
+    '#description' => t('Allows newsletter issues to be sent to multiple newsletters.'),
+  );
 
   // Node type settings require pre-processing.
   // simplenews_admin_settings_submit() is called before system_settings_form_submit().
@@ -786,7 +792,7 @@ function simplenews_admin_settings_submi
   $vocabulary['nodes'] = $form_state['values']['simplenews_content_types'];
 
   // Set vocabulary required values
-  $vocabulary['multiple'] = FALSE;
+  $vocabulary['multiple'] = $form_state['values']['simplenews_multiple'];
   $vocabulary['required'] = TRUE;
   $vocabulary['tags'] = FALSE;
 
Index: simplenews.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simplenews/simplenews.install,v
retrieving revision 1.33
diff -u -p -r1.33 simplenews.install
--- simplenews.install	30 Jul 2009 19:56:47 -0000	1.33
+++ simplenews.install	6 Aug 2009 12:26:07 -0000
@@ -70,9 +70,10 @@ function simplenews_schema() {
       ),
       'tid' => array(
         'description' => t('The {term_data}.tid (= newsletter series) this issue belongs to.'),
-        'type' => 'int',
+        'type' => 'varchar',
+        'length' => 255,
         'not null' => TRUE,
-        'default' => 0,
+        'default' => '',
       ),
       's_status' => array(
         'description' => t('Send status of the newsletter issue (0 = not send; 1 = pending; 2 = send). '),
@@ -637,4 +638,22 @@ function simplenews_update_6100() {
     )
   );
   return $ret;
-}
\ No newline at end of file
+}
+
+/**
+ * Change field type of tid from int to varchar
+ */
+function simplenews_update_6101() {
+  $ret = array();
+ 
+  db_change_field($ret, 'simplenews_newsletters', 'tid', 'tid', array(
+        'description' => t('The {term_data}.tid (= newsletter series) this issue belongs to.'),
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+      )
+  );
+  
+  return $ret;
+}
Index: simplenews.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simplenews/simplenews.module,v
retrieving revision 1.212
diff -u -p -r1.212 simplenews.module
--- simplenews.module	5 Aug 2009 20:12:42 -0000	1.212
+++ simplenews.module	6 Aug 2009 12:21:51 -0000
@@ -366,7 +366,7 @@ function simplenews_nodeapi(&$node, $op,
       $node->simplenews = array_merge(_simplenews_get_node_form_defaults(), is_array($node->simplenews) ? $node->simplenews : array());
       $term = simplenews_validate_taxonomy($node->taxonomy);
       $tid = is_array($term) ? array_values($term) : FALSE;
-      $node->simplenews['tid'] = $tid ? $tid[0] : 0;
+      $node->simplenews['tid'] = $tid ? $tid : 0;
       break;
     case 'insert':
     case 'update':
@@ -380,17 +380,17 @@ function simplenews_nodeapi(&$node, $op,
         // Insert node
         $s_status = $send_with_permission ? SIMPLENEWS_STATUS_SEND_PENDING : SIMPLENEWS_STATUS_SEND_NOT;
         db_query("INSERT INTO {simplenews_newsletters} (nid, vid, tid, s_status, s_format, priority, receipt)
-                  VALUES (%d, %d, %d, %d, '%s', %d, %d)", $node->nid, $node->vid, $node->simplenews['tid'], $s_status, $node->simplenews['s_format'], $node->simplenews['priority'], $node->simplenews['receipt']);
+                  VALUES (%d, %d, '%s', %d, '%s', %d, %d)", $node->nid, $node->vid, serialize($node->simplenews['tid']), $s_status, $node->simplenews['s_format'], $node->simplenews['priority'], $node->simplenews['receipt']);
         }
       else {
         // Update node
         if ($send_with_permission) {
-          db_query("UPDATE {simplenews_newsletters} SET vid = %d, tid = %d, s_status = %d, s_format = '%s', priority = %d, receipt = %d
-          WHERE nid = %d", $node->vid, $node->simplenews['tid'], SIMPLENEWS_STATUS_SEND_PENDING, $node->simplenews['s_format'], $node->simplenews['priority'], $node->simplenews['receipt'], $node->nid);
+          db_query("UPDATE {simplenews_newsletters} SET vid = %d, tid = '%s', s_status = %d, s_format = '%s', priority = %d, receipt = %d
+          WHERE nid = %d", $node->vid, serialize($node->simplenews['tid']), SIMPLENEWS_STATUS_SEND_PENDING, $node->simplenews['s_format'], $node->simplenews['priority'], $node->simplenews['receipt'], $node->nid);
         }
         else {
-          db_query("UPDATE {simplenews_newsletters} SET tid = %d, s_format = '%s', priority = %d, receipt = %d
-          WHERE nid = %d", $node->simplenews['tid'], $node->simplenews['s_format'], $node->simplenews['priority'], $node->simplenews['receipt'], $node->nid);
+          db_query("UPDATE {simplenews_newsletters} SET tid = '%s', s_format = '%s', priority = %d, receipt = %d
+          WHERE nid = %d", serialize($node->simplenews['tid']), $node->simplenews['s_format'], $node->simplenews['priority'], $node->simplenews['receipt'], $node->nid);
         }
       }
 
@@ -426,6 +426,7 @@ function simplenews_nodeapi(&$node, $op,
       break;
     case 'load':
       $node->simplenews = db_fetch_array(db_query('SELECT * FROM {simplenews_newsletters} WHERE nid = %d', $node->nid));
+      $node->simplenews['tid'] = unserialize($node->simplenews['tid']);
       break;
   }
 }
@@ -1392,7 +1393,7 @@ function simplenews_send_node($node, $ac
     $node = node_load($node);
   }
   if (is_object($node)) {
-    $from = _simplenews_set_from($node);
+    $from = _simplenews_set_from($node); // TODO: These three lines are not used.
     $params['context']['node'] = $node;
     $params['from'] = $from;
 
@@ -1403,19 +1404,19 @@ function simplenews_send_node($node, $ac
 
     if (empty($accounts)) {
       // No accounts specified. Get email address of all accounts subscribed to this newsletter.
-      $result = db_query('SELECT s.mail FROM {simplenews_subscriptions} s
+      $result = db_query('SELECT s.mail, t.tid FROM {simplenews_subscriptions} s
                          INNER JOIN {simplenews_snid_tid} t ON s.snid = t.snid
-                         WHERE s.activated = %d AND t.tid = %d AND t.status = %d',
-                         1, $node_data['tid'], SIMPLENEWS_SUBSCRIPTION_STATUS_SUBSCRIBED);
+                         WHERE s.activated = %d AND t.tid IN (%s) AND t.status = %d',
+                         1, implode(',', $node_data['tid']), SIMPLENEWS_SUBSCRIPTION_STATUS_SUBSCRIBED);
       while ($account = db_fetch_object($result)) {
-        $mails[] = array('mail' => $account->mail);
+        $mails[] = array('mail' => $account->mail, 'tid' => $account->tid); // Added tid. It's used later, we can't use $node->simplenews['tid'] anymore because it is an array now.
       }
     }
     else {
       // Get email address of specified accounts.
       foreach ($accounts as $account) {
         $account = simplenews_get_subscription($account);
-        $mails[] = array('mail' => $account->mail);
+        $mails[] = array('mail' => $account->mail, 'tid' => current($account->tids)); // TODO: it's taken the first tid, that's wrong.
       }
     }
 
@@ -1509,6 +1510,7 @@ function simplenews_mail($key, &$message
       // and when available the translation of the preferred language is selected.
       $nid = $context['node']->nid;
       $langcode = $message['language']->language;
+      $tid = $context['newsletter']->tid;
       if (module_exists('translation')) {
         // If the node has translations and a translation is required
         // the equivalent of the node in the required langugage is used
@@ -1535,27 +1537,27 @@ function simplenews_mail($key, &$message
         }
         // If a translation of the node is used and this node is not available in
         // the message buffer, then load this node.
-        if ($nid != $context['node']->nid && !isset($messages[$nid][$langcode])) {
+        if ($nid != $context['node']->nid && !isset($messages[$nid][$langcode][$tid])) {
           $context['node'] = node_load($nid);
         }
       }
 
       // Check if this node-language pair has been buffered.
       // If not, build the message and store it for later use.
-      if (!isset($messages[$nid][$langcode])) {
+      if (!isset($messages[$nid][$langcode][$tid])) {
         $node = drupal_clone($context['node']);
 
         // Add simplenews specific header data
         $headers = array_merge($message['headers'], _simplenews_headers($node, $params['from']['address']));
         $headers['From'] = $params['from']['formatted'];
-        $message['headers'] = $messages[$nid][$langcode]['headers'] = $headers;
+        $message['headers'] = $messages[$nid][$langcode][$tid]['headers'] = $headers;
 
         // Build email subject
-        if ($tid = $node->simplenews['tid']) {
-          $term = taxonomy_get_term($tid);
+        if (!empty($context['newsletter'])) {
+          $term = $context['newsletter'];
           // Translate the newsletter term name if simplenews vocabulary uses Localized terms.
           if (module_exists('i18ntaxonomy') && i18ntaxonomy_vocabulary(variable_get('simplenews_vid', '')) == I18N_TAXONOMY_LOCALIZE) {
-            $name = tt('taxonomy:term:'. $tid .':name', $term->name, $langcode);
+            $name = tt('taxonomy:term:'. $term->tid .':name', $term->name, $langcode);
           }
           else {
             $name = $term->name;
@@ -1566,7 +1568,7 @@ function simplenews_mail($key, &$message
         }
         $subject = theme('simplenews_newsletter_subject', $name, $node->title, $message['language']);
         $subject = str_replace(array("\r", "\n"), '', $subject);
-        $message['subject'] = $messages[$nid][$langcode]['subject'] = $subject;
+        $message['subject'] = $messages[$nid][$langcode][$tid]['subject'] = $subject;
 
         // Build message body
         // Processing node body mimics node_view() with full node view
@@ -1580,22 +1582,22 @@ function simplenews_mail($key, &$message
         node_invoke_nodeapi($node, 'alter', FALSE, TRUE);
         unset($node->simplenews_mail);
 
-        $body = theme(array('simplenews_newsletter_body__'. $context['node']->simplenews['tid'], 'simplenews_newsletter_body'), $node, $message['language']);
+        $body = theme(array('simplenews_newsletter_body__'. $tid, 'simplenews_newsletter_body'), $node, $message['language']);
 
         // Buffer body text node and language specific
-        $messages[$nid][$langcode]['body'] = $body;
+        $messages[$nid][$langcode][$tid]['body'] = $body;
 
         // Build and buffer message footer
-        $footer = theme(array('simplenews_newsletter_footer__'. $context['node']->simplenews['tid'], 'simplenews_newsletter_footer'), $context['node'], $key, $message['language']);
-        $messages[$nid][$langcode]['footer'] = $footer;
+        $footer = theme(array('simplenews_newsletter_footer__'. $tid, 'simplenews_newsletter_footer'), $context['node'], $key, $message['language']);
+        $messages[$nid][$langcode][$tid]['footer'] = $footer;
 
       }
       else {
         // Get message data from buffer
-        $message['headers'] = $messages[$nid][$langcode]['headers'];
-        $message['subject'] = $messages[$nid][$langcode]['subject'];
-        $body               = $messages[$nid][$langcode]['body'];
-        $footer             = $messages[$nid][$langcode]['footer'];
+        $message['headers'] = $messages[$nid][$langcode][$tid]['headers'];
+        $message['subject'] = $messages[$nid][$langcode][$tid]['subject'];
+        $body               = $messages[$nid][$langcode][$tid]['body'];
+        $footer             = $messages[$nid][$langcode][$tid]['footer'];
       }
 
       // Build message body.
@@ -1604,7 +1606,7 @@ function simplenews_mail($key, &$message
       $variables =  simplenews_mail_tokens($context['account'], $context, is_object($context['account']->language) ? $context['account']->language : language_default());
       $body = strtr($body, $variables);
       if ($context['node']->simplenews['s_format'] == 'plain') {
-        $body = simplenews_html_to_text($body, variable_get('simplenews_hyperlinks_'. $context['node']->simplenews['tid'], 1));
+        $body = simplenews_html_to_text($body, variable_get('simplenews_hyperlinks_'. $tid, 1));
       }
       $message['body']['body'] = $body;
 
@@ -1662,7 +1664,7 @@ function simplenews_mail($key, &$message
  *
  * @return TRUE if email is succesfully delivered by php mail()
  */
-function simplenews_mail_mail($nid, $vid, $mail, $key = 'node') {
+function simplenews_mail_mail($nid, $vid, $mail, $key = 'node', $tid = NULL) {
   // Get subscription data for recipient and language
   $account = new stdClass();
   $account->mail = $mail;
@@ -1672,8 +1674,8 @@ function simplenews_mail_mail($nid, $vid
   // Get node data for the mail
   $node = node_load($nid, $vid);
   if (is_object($node)) {
-    $params['from'] = _simplenews_set_from($node);
-    $params['context']['newsletter'] = taxonomy_get_term($node->simplenews['tid']);
+    $params['from'] = _simplenews_set_from($node, $tid);
+    $params['context']['newsletter'] = taxonomy_get_term(empty($tid) ? $node->simplenews['tid'][0] : $tid);
     $params['context']['node'] = $node;
 
     // Send mail
@@ -1736,7 +1738,7 @@ function simplenews_mail_spool($nid = NU
     _simplenews_measure_usec(TRUE);
 
     foreach ($messages as $key => $message) {
-      $result = simplenews_mail_mail($message['nid'], $message['vid'], $message['mail']);
+      $result = simplenews_mail_mail($message['nid'], $message['vid'], $message['mail'], 'node', $message['tid']);
 
       // Update spool status if mail is sent succesfully.
       // This is not optimal for performance but prevents duplicate emails
@@ -1965,11 +1967,15 @@ function simplenews_call_actions($op, $s
  *
  * @return array [address] = from address; [formatted] = formatted from name and address
  */
-function _simplenews_set_from($node = NULL) {
+function _simplenews_set_from($node = NULL, $tid = NULL) {
   $address_default = variable_get('site_mail', ini_get('sendmail_from'));
   $name_default = variable_get('site_name', 'Drupal');
 
-  if (isset($node->simplenews['tid'])) {
+  if (isset($tid)) {
+    $address = variable_get('simplenews_from_address_'. $tid, variable_get('simplenews_from_address', $address_default));
+    $name = variable_get('simplenews_from_name_'. $tid, variable_get('simplenews_from_name', $name_default));
+  }
+  elseif (isset($node->simplenews['tid'][0])) {
     $address = variable_get('simplenews_from_address_'. $node->simplenews['tid'], variable_get('simplenews_from_address', $address_default));
     $name = variable_get('simplenews_from_name_'. $node->simplenews['tid'], variable_get('simplenews_from_name', $name_default));
   }
@@ -2142,12 +2148,12 @@ function simplenews_mail_tokens($subscri
   // Get newsletter name if not in newsletter object.
   $name = isset($context['newsletter']->name) ? $context['newsletter']->name : '';
   if (!$name) {
-    if (isset($context['node']->simplenews['tid'])) {
-      if ($term = taxonomy_get_term($context['node']->simplenews['tid'])) {
+    if (isset($context['node']->simplenews['tid'][0])) {
+      if ($term = taxonomy_get_term($context['node']->simplenews['tid'][0])) {
         // Translate newsletter name if required.
         $name = $term->name;
         if (module_exists('i18ntaxonomy') && i18ntaxonomy_vocabulary(variable_get('simplenews_vid', '')) == I18N_TAXONOMY_LOCALIZE) {
-          $name = tt('taxonomy:term:'. $context['node']->simplenews['tid'] .':name', $name, $language->language);
+          $name = tt('taxonomy:term:'. $context['node']->simplenews['tid'][0] .':name', $name, $language->language);
         }
       }
     }
@@ -2242,7 +2248,7 @@ function _simplenews_flatten_array($arra
   $return = array();
 
   foreach ($array as $key => $value) {
-    if (is_array($value)) {
+    if (is_array($value) && $key != 'tid') {
       $return += _simplenews_flatten_array($value);
     }
     else {
@@ -2480,3 +2486,4 @@ function template_preprocess_simplenews_
   $variables['unsubscribe_text'] = t('Unsubscribe from this newsletter', array(), $variables['language']->language);
   $variables['test_message'] = t('This is a test version of the newsletter.', array(), $variables['language']->language);
 }
+
