### Eclipse Workspace Patch 1.0
#P simplenews

Index: includes/simplenews.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simplenews/includes/simplenews.admin.inc,v
retrieving revision 1.4
diff -u -r1.4 simplenews.admin.inc
--- includes/simplenews.admin.inc	5 Jan 2011 11:40:28 -0000	1.4
+++ includes/simplenews.admin.inc	6 Jan 2011 14:56:38 -0000
@@ -234,7 +234,7 @@
       switch ($form_state['input']['operation']) {
         case 'send':
         //@todo If 'send': check if selected items are un-sent.
-        
+
       }
     }
   }
@@ -255,7 +255,7 @@
       $args = array($nids);
     }
     call_user_func_array($function, $args);
-    
+
     drupal_set_message(t('The update has been performed.'));
   }
   else {
@@ -281,7 +281,7 @@
 function simplenews_issue_resend($nids) {
   //TODO
   // check if $nids are not pending: error
-  // send newsletter  
+  // send newsletter
 }
 
 /**
@@ -446,7 +446,7 @@
     '#default_value' => $edit['new_account'],
     '#description' => t('None: This newsletter is not listed on the user registration page.<br />Default on: This newsletter is listed on the user registion page and is selected by default.<br />Default off: This newsletter is listed on the user registion page and is not selected by default.<br />Silent: A new user is automatically subscribed to this newsletter. The newsletter is not listed on the user registration page.'),
   );
-  
+
   // Type of (un)subsribe confirmation
   $options = array(
     SIMPLENEWS_OPT_INOUT_HIDDEN => t('Hidden'),
@@ -577,7 +577,7 @@
     '#value' => t('Save'),
     '#weight' => 50,
   );
-  
+
   if ($edit['tid']) {
     $form['actions']['delete'] = array(
       '#type' => 'submit',
@@ -617,7 +617,7 @@
   $term->weight       = $form_state['values']['weight'];
   taxonomy_term_save($term);
   $category->tid = $term->tid;
-  
+
   switch (simplenews_category_save($category)) {
     case SAVED_NEW:
       drupal_set_message(t('Created new newsletter category %name.', array('%name' => $category->name)));
@@ -650,11 +650,11 @@
     '#markup' => '<p><strong>' . t('Note: All subscriptions associated with this newsletter will be lost.') . '</strong></p>',
   );
 
-  return confirm_form($form, 
-    t('Are you sure you want to delete category %name?', array('%name' => $category->name)), 
-    'admin/structure/simplenews', 
-    t('This action cannot be undone.'), 
-    t('Delete'), 
+  return confirm_form($form,
+    t('Are you sure you want to delete category %name?', array('%name' => $category->name)),
+    'admin/structure/simplenews',
+    t('This action cannot be undone.'),
+    t('Delete'),
     t('Cancel')
   );
 }
@@ -705,10 +705,10 @@
   $confirm_question = format_plural(count($snids),
                                   'Are you sure you want to delete this subscription?',
                                   'Are you sure you want to delete these subscriptions?');
-  return confirm_form($form, 
-                      $confirm_question, 
-                      'admin/people/simplenews', 
-                      t('This action cannot be undone.'), 
+  return confirm_form($form,
+                      $confirm_question,
+                      'admin/people/simplenews',
+                      t('This action cannot be undone.'),
                       t('Delete'), t('Cancel'));
 }
 
@@ -758,7 +758,7 @@
     $languages = language_list('enabled');
     foreach ($languages[1] as $langcode => $item) {
       $name = t($item->name);
-      $options[$langcode] = $name . ($item->native != $name ? ' ('. $item->native .')' : ''); 
+      $options[$langcode] = $name . ($item->native != $name ? ' (' . $item->native . ')' : '');
     }
     $form['language'] = array(
       '#type' => 'radios',
@@ -1127,7 +1127,7 @@
       $args = array($snids);
     }
     call_user_func_array($function, $args);
-    
+
     drupal_set_message(t('The update has been performed.'));
   }
   else {
@@ -1146,7 +1146,7 @@
  *   Status of the subscription (0, 1).
  */
 function simplenews_subscription_activate($snids, $status) {
-  foreach($snids as $snid) {
+  foreach ($snids as $snid) {
     $subscriber = simplenews_subscriber_load($snid);
     $subscriber->activated = $status;
     simplenews_subscriber_save($subscriber);
@@ -1738,6 +1738,6 @@
     SIMPLENEWS_PRIORITY_HIGH => t('high'),
     SIMPLENEWS_PRIORITY_NORMAL => t('normal'),
     SIMPLENEWS_PRIORITY_LOW => t('low'),
-    SIMPLENEWS_PRIORITY_LOWEST => t('lowest'),  
+    SIMPLENEWS_PRIORITY_LOWEST => t('lowest'),
   );
 }
\ No newline at end of file
Index: includes/simplenews.subscription.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simplenews/includes/simplenews.subscription.inc,v
retrieving revision 1.2
diff -u -r1.2 simplenews.subscription.inc
--- includes/simplenews.subscription.inc	31 Dec 2010 11:37:49 -0000	1.2
+++ includes/simplenews.subscription.inc	6 Jan 2011 14:56:39 -0000
@@ -103,7 +103,7 @@
   $arguments = func_get_args();
   $op = array_shift($arguments);
   $code = array_shift($arguments);
-  
+
   $md5 = drupal_substr($code, 0, 10);
   list($snid, $tid) = explode('t', drupal_substr($code, 10));
 
@@ -131,7 +131,7 @@
       if ($op == 'remove') {
         simplenews_unsubscribe_user($subscriber->mail, $tid, FALSE, 'website');
         if ($path = variable_get('simplenews_confirm_unsubscribe_page', '')) {
-          $path = $path .'/'. implode('/', $arguments);
+          $path = $path . '/' . implode('/', $arguments);
           drupal_goto($path);
         }
         drupal_set_message(t('%user was unsubscribed from the %newsletter mailing list.', array('%user' => $subscriber->mail, '%newsletter' => $category->name)));
@@ -140,7 +140,7 @@
       elseif ($op == 'add') {
         simplenews_subscribe_user($subscriber->mail, $tid, FALSE, 'website');
         if ($path = variable_get('simplenews_confirm_subscribe_page', '')) {
-          $path = $path .'/'. implode('/', $arguments);
+          $path = $path . '/' . implode('/', $arguments);
           drupal_goto($path);
         }
         drupal_set_message(t('%user was added to the %newsletter mailing list.', array('%user' => $subscriber->mail, '%newsletter' => $category->name)));
@@ -175,18 +175,18 @@
   );
   $form['#redirect'] = variable_get('simplenews_confirm_subscribe_page', '');
 
-  return confirm_form($form, 
-    t('Confirm subscription'), 
+  return confirm_form($form,
+    t('Confirm subscription'),
     '',
-    t('You can always unsubscribe later.'), 
-    t('Subscribe'), 
+    t('You can always unsubscribe later.'),
+    t('Subscribe'),
     t('Cancel')
   );
 }
 
 function simplenews_confirm_add_form_submit($form, &$form_state) {
   simplenews_subscribe_user($form_state['values']['mail'], $form_state['values']['newsletter']->tid, FALSE, 'website');
-  
+
   // Display message if user is directed to the front page.
   if (!$form['#redirect']) {
     drupal_set_message(t('%user was added to the %newsletter mailing list.', array('%user' => $form_state['values']['mail'], '%newsletter' => $form_state['values']['newsletter']->name)));
@@ -214,11 +214,11 @@
   );
   $form['#redirect'] = variable_get('simplenews_confirm_unsubscribe_page', '');
 
-  return confirm_form($form, 
-    t('Confirm remove subscription'), 
+  return confirm_form($form,
+    t('Confirm remove subscription'),
     '',
-    t('This action will unsubscribe you from the newsletter mailing list.'), 
-    t('Unsubscribe'), 
+    t('This action will unsubscribe you from the newsletter mailing list.'),
+    t('Unsubscribe'),
     t('Cancel')
   );
 }
Index: simplenews.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simplenews/simplenews.js,v
retrieving revision 1.4
diff -u -r1.4 simplenews.js
--- simplenews.js	20 Feb 2010 09:23:04 -0000	1.4
+++ simplenews.js	6 Jan 2011 14:56:35 -0000
@@ -1,30 +1,30 @@
-// $Id: simplenews.js,v 1.4 2010/02/20 09:23:04 sutharsan Exp $
+//$Id: simplenews.js,v 1.4 2010/02/20 09:23:04 sutharsan Exp $
+(function ($) {
 
 /**
  * Set text of Save button dependent on the selected send option.
- * @todo Changed Drupal.behaviors: http://drupal.org/node/224333#drupal_behaviors
- * @todo Wrap jQuery code: http://drupal.org/node/224333#javascript_compatibility
- * @todo behaviors settings passed locally: http://drupal.org/node/224333#local_settings_behaviors
  */
-// TODO This does not work
-Drupal.behaviors.simplenewsCommandSend = function (context) {
-  var simplenewsSendButton = function () {
-    switch ($(".simplenews-command-send :radio:checked").val()) {
+Drupal.behaviors.simplenewsCommandSend = {
+  attach: function (context) {
+    var commandSend = $(".simplenews-command-send", context);
+    var sendButton = function () {
+      switch ($(":radio:checked", commandSend).val()) {
       case '0':
-        $('#edit-submit').attr({value: Drupal.t('Save')});
+        $('#edit-submit', context).attr({value: Drupal.t('Save')});
         break;
       case '1':
-        $('#edit-submit').attr({value: Drupal.t('Save and send')});
+        $('#edit-submit', context).attr({value: Drupal.t('Save and send')});
         break;
       case '2':
-        $('#edit-submit').attr({value: Drupal.t('Save and send test')});
+        $('#edit-submit', context).attr({value: Drupal.t('Save and send test')});
         break;
+      }
     }
+
+    // Update send button at page load and when a send option is selected.
+    sendButton();
+    commandSend.click( function() { sendButton(); });
   }
-  
-  // Update send button at page load and when a send option is selected.
-  $(function() { simplenewsSendButton(); });
-  $(".simplenews-command-send").click( function() { simplenewsSendButton(); });
-  
-  
-}
+};
+
+})(jQuery);
\ No newline at end of file
Index: simplenews.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simplenews/simplenews.module,v
retrieving revision 1.265
diff -u -r1.265 simplenews.module
--- simplenews.module	5 Jan 2011 11:37:23 -0000	1.265
+++ simplenews.module	6 Jan 2011 14:56:37 -0000
@@ -244,7 +244,7 @@
     'page callback' => 'system_admin_menu_block_page',
     'access arguments' => array('administer simplenews settings'),
     'file' => 'system.admin.inc',
-    'file path' => drupal_get_path('module', 'system'), 
+    'file path' => drupal_get_path('module', 'system'),
   );
 
   $items['admin/config/simplenews/general'] = array(
@@ -389,11 +389,11 @@
     $terms = simplenews_get_term_values($node);
     if (!$terms) {
       form_set_error($field['field_name'], t('A newsletter category term is required.'));
-      watchdog('simplenews', t('@todo ... newsletter taxonomy is required, change settings.'), array(), WATCHDOG_ERROR);
+      watchdog('simplenews', '@todo ... newsletter taxonomy is required, change settings.', array(), WATCHDOG_ERROR);
     }
     elseif (count($terms) > 1) {
       form_set_error($field['field_name'], t('Only one newsletter category term is allowed.'));
-      watchdog('simplenews', t('@todo ... newsletter taxonomy must be single value, change settings.'), array(), WATCHDOG_ERROR);
+      watchdog('simplenews', '@todo ... newsletter taxonomy must be single value, change settings.', array(), WATCHDOG_ERROR);
     }
   }
 
@@ -448,7 +448,7 @@
   $newsletter = (object)$node->simplenews;
   $send_with_permission = $newsletter->send == SIMPLENEWS_COMMAND_SEND_NOW && user_access('send newsletter');
   $status = $send_with_permission ? SIMPLENEWS_STATUS_SEND_PENDING : SIMPLENEWS_STATUS_SEND_NOT;
-  
+
   $newsletter->nid = $node->nid;
   $newsletter->vid = $node->vid;
   $newsletter->status = $status;
@@ -562,7 +562,7 @@
     $types = array($types);
   }
   if ($sn_types = simplenews_get_content_types()) {
-    foreach($types as $type) {
+    foreach ($types as $type) {
       if (in_array($type, $sn_types)) {
         return TRUE;
       }
@@ -582,7 +582,7 @@
  */
 function simplenews_get_content_types($reset = FALSE) {
   static $simplenews_types;
-  
+
   if (!isset($simplenews_types) || $reset) {
     foreach (node_type_get_types() as $name => $type) {
       if (variable_get('simplenews_content_type_' . $name, FALSE)) {
@@ -720,7 +720,7 @@
  * Implements hook_form_FORM_ID_alter().
  *
  * Add a warning message to taxonomy term delete form.
- * 
+ *
  * @todo move this function to a .inc file.
  */
 function simplenews_form_taxonomy_form_term_alter(&$form, $form_state) {
@@ -728,7 +728,7 @@
     if ($form['#term']->vid == variable_get('simplenews_vid', 0)) {
       $category = simplenews_category_load($form['#term']->tid);
       $form['description']['#markup'] = '<p>' . t('This taxonomy term is part of simplenews newsletter category %category_name. Deleting this term will delete the newsletter category and <strong>all subscriptions to category %category_name</strong>. This action cannot be undone.', array('%category_name' => $category->name)) . '</p>' . $form['description']['#markup'];
-    }    
+    }
   }
 }
 
@@ -736,7 +736,7 @@
  * Implements hook_taxonomy_term_delete().
  *
  * Delete simplenews category if taxonomy term is delete.
- * 
+ *
  * @todo move this function to a .inc file.
  */
 function simplenews_taxonomy_term_delete($term) {
@@ -749,9 +749,9 @@
 }
 
 /**
- * @todo
+ * Implements hook_form_alter().
  */
-function simplenews_form_alter(&$form, $form_state, $form_id) {
+function simplenews_form_alter(&$form, &$form_state, $form_id) {
   // Add Simplenews settings to simplenews newsletter node form.
   if (!empty($form['#node_edit_form'])) {
     if (in_array($form['type']['#value'], simplenews_get_content_types())) {
@@ -789,9 +789,9 @@
 
   // Translations of newsletters don't have the 'send' option. Only the
   // translation source (and non translated) newsletters will get these options.
-  if (module_exists('translation') && translation_supported_type($form['#node']->type) && 
+  if (module_exists('translation') && translation_supported_type($form['#node']->type) &&
       (isset($form['#node']->translation_source) || ($form['#node']->tnid && $form['#node']->tnid != $form['#node']->nid))) {
-    $form['simplenews']['#description'] = t('This newsletter issue is part of a translation set. Sending this set is controlled from the <a href="@link">translation source newsletter</a>.', array('@link' => url('node/'. $form['tnid']['#value'])));
+    $form['simplenews']['#description'] = t('This newsletter issue is part of a translation set. Sending this set is controlled from the <a href="@link">translation source newsletter</a>.', array('@link' => url('node/' . $form['tnid']['#value'])));
     // Send option of translated newsletters are not used, but a default is
     // required to prevent errors when data is stored in the database.
     $form['simplenews']['send'] = array(
@@ -959,7 +959,7 @@
   }
 
   if (count($options)) {
-    // TODO Change this text: use less words; 
+    // TODO Change this text: use less words;
     $form['simplenews'] = array(
       '#type' => 'fieldset',
       '#description' => t('Select the newsletter(s) to which you wish to subscribe.'),
@@ -999,7 +999,7 @@
     $subsription->language = $edit['language'];
     simplenews_subscriber_save($subscriber);
   }
-  
+
   // $edit['newsletter'] contains newsletters the user should be subscribed to.
   // But we leave this untouched because we only subscribe a new account
   // after account confirmation. In the meantime the content of $edit['newsletter']
@@ -1110,7 +1110,7 @@
   // TODO investigate if we perhaps /can/ use simplenews_get_subscription().
   $subscribers = simplenews_subscribers_load_multiple(array(), array('mail' => $account->mail));
   $subscriber = $subscribers ? reset($subscribers) : FALSE;
-  
+
   if ($subscriber) {
     if (variable_get('simplenews_sync_account', TRUE)) {
       simplenews_subscription_delete(array('snid' => $subscriber->snid));
@@ -1150,7 +1150,7 @@
     $subscription = simplenews_get_subscription((object)$form['#user']);
     $form += _simplenews_subscription_manager_form($subscription);
     $form['subscriptions']['#title'] =  t('Newsletter subscriptions');
-    unset($form['update'], $form['subscriptions']['mail']);    
+    unset($form['update'], $form['subscriptions']['mail']);
   }
 }
 
@@ -1197,7 +1197,7 @@
       $account->content['simplenews']['my_newsletters'] = array(
         '#type' => 'user_profile_item',
         '#title' => '',
-        '#markup' => t('Manage <a href="!url">subscriptions</a>', array('!url' => url('user/'. $account->uid .'/edit/simplenews'))),
+        '#markup' => t('Manage <a href="!url">subscriptions</a>', array('!url' => url('user/' . $account->uid . '/edit/simplenews'))),
       );
     }
   }
@@ -1220,7 +1220,7 @@
     $blocks[$category->tid] = array(
       'info' => t('Newsletter: @title', array('@title' => $category->name)),
       // TODO Use block's own settings?
-      'cache' => variable_get('simplenews_block_f_'. $category->tid, 1) ? DRUPAL_NO_CACHE : DRUPAL_CACHE_PER_ROLE,
+      'cache' => variable_get('simplenews_block_f_' . $category->tid, 1) ? DRUPAL_NO_CACHE : DRUPAL_CACHE_PER_ROLE,
     );
   }
   return $blocks;
@@ -1230,43 +1230,43 @@
  * Implements hook_block_configure().
  */
 function simplenews_block_configure($delta = '') {
-  $form['simplenews_block_'. $delta]['simplenews_block_m_'. $delta] = array(
+  $form['simplenews_block_' . $delta]['simplenews_block_m_' . $delta] = array(
     '#type' => 'textfield',
     '#title' => t('Block message'),
     '#size' => 60,
     '#maxlength' => 128,
-    '#default_value' => variable_get('simplenews_block_m_'. $delta, t('Stay informed on our latest news!')),
+    '#default_value' => variable_get('simplenews_block_m_' . $delta, t('Stay informed on our latest news!')),
   );
-  $form['simplenews_block_'. $delta]['simplenews_block_f_'. $delta] = array(
+  $form['simplenews_block_' . $delta]['simplenews_block_f_' . $delta] = array(
     '#type' => 'radios',
     '#title' => t('Subscription interface'),
     '#options' => array('1' => t('Subscription form'), '0' => t('Link to form')),
     '#description' => t("Note: this requires permission 'subscribe to newsletters'."),
-    '#default_value' => variable_get('simplenews_block_f_'. $delta, 1),
+    '#default_value' => variable_get('simplenews_block_f_' . $delta, 1),
   );
-  $form['simplenews_block_'. $delta]['simplenews_block_l_'. $delta] = array(
+  $form['simplenews_block_' . $delta]['simplenews_block_l_' . $delta] = array(
     '#type' => 'checkbox',
     '#title' => t('Display link to previous issues'),
     '#return_value' => 1,
-    '#default_value' => variable_get('simplenews_block_l_'. $delta, 1),
+    '#default_value' => variable_get('simplenews_block_l_' . $delta, 1),
   );
-  $form['simplenews_block_'. $delta]['simplenews_block_i_status_'. $delta] = array(
+  $form['simplenews_block_' . $delta]['simplenews_block_i_status_'.  $delta] = array(
     '#type' => 'checkbox',
     '#title' => t('Display previous issues'),
     '#return_value' => 1,
     '#default_value' => variable_get('simplenews_block_i_status_'. $delta, 0),
   );
-  $form['simplenews_block_'. $delta]['simplenews_block_i_'. $delta] = array(
+  $form['simplenews_block_' . $delta]['simplenews_block_i_' . $delta] = array(
     '#type' => 'select',
     '#title' => t('Number of issues to display'),
     '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)),
-    '#default_value' => variable_get('simplenews_block_i_'. $delta, 5),
+    '#default_value' => variable_get('simplenews_block_i_' . $delta, 5),
   );
-  $form['simplenews_block_'. $delta]['simplenews_block_r_'. $delta] = array(
+  $form['simplenews_block_' . $delta]['simplenews_block_r_' . $delta] = array(
     '#type' => 'checkbox',
     '#title' => t('Display RSS-feed icon'),
     '#return_value' => 1,
-    '#default_value' => variable_get('simplenews_block_r_'. $delta, 1),
+    '#default_value' => variable_get('simplenews_block_r_' . $delta, 1),
   );
   return $form;
 }
@@ -1275,12 +1275,12 @@
  * Implements hook_block_save().
  */
 function simplenews_block_save($delta = '', $edit = array()) {
-  variable_set('simplenews_block_m_'. $delta, $edit['simplenews_block_m_'. $delta]);
-  variable_set('simplenews_block_f_'. $delta, $edit['simplenews_block_f_'. $delta]);
-  variable_set('simplenews_block_l_'. $delta, $edit['simplenews_block_l_'. $delta]);
-  variable_set('simplenews_block_i_status_'. $delta, $edit['simplenews_block_i_status_'. $delta]);
-  variable_set('simplenews_block_i_'. $delta, $edit['simplenews_block_i_'. $delta]);
-  variable_set('simplenews_block_r_'. $delta, $edit['simplenews_block_r_'. $delta]);
+  variable_set('simplenews_block_m_' . $delta, $edit['simplenews_block_m_' . $delta]);
+  variable_set('simplenews_block_f_' . $delta, $edit['simplenews_block_f_' . $delta]);
+  variable_set('simplenews_block_l_' . $delta, $edit['simplenews_block_l_' . $delta]);
+  variable_set('simplenews_block_i_status_' . $delta, $edit['simplenews_block_i_status_' . $delta]);
+  variable_set('simplenews_block_i_' . $delta, $edit['simplenews_block_i_' . $delta]);
+  variable_set('simplenews_block_r_' . $delta, $edit['simplenews_block_r_' . $delta]);
 }
 
 /**
@@ -1295,7 +1295,7 @@
     // $delta is validated, the block can be displayed.
     $block = array(
       'subject' => check_plain($newsletters[$delta]->name),
-      'content' => theme(array('simplenews_block__'. $delta, 'simplenews_block'), array('tid' => $delta)),
+      'content' => theme(array('simplenews_block__' . $delta, 'simplenews_block'), array('tid' => $delta)),
     );
     return $block;
   }
@@ -1363,7 +1363,6 @@
  *    mass subscribe: mass admin UI
  *    mass unsubscribe: mass admin UI
  *    action: Drupal actions
- * @todo Replace time(): http://drupal.org/node/224333#time
  */
 function simplenews_subscribe_user($mail, $tid, $confirm = TRUE, $source = 'unknown', $preferred_language = NULL) {
   global $language;
@@ -1701,7 +1700,7 @@
       $query->condition('snid', $snids);
     }
     if ($conditions) {
-      foreach($conditions as $key => $condition) {
+      foreach ($conditions as $key => $condition) {
         $query->condition($key, $condition);
       }
     }
@@ -1757,7 +1756,7 @@
 function simplenews_subscriber_delete($subscriber) {
   if (!is_object($subscriber)) {
   }
-  
+
   if ($subscriber) {
     db_delete('simplenews_subscriber')
       ->condition('snid', $subscriber->snid)
@@ -2085,7 +2084,7 @@
     // We temporary clear the $custom_theme to prevent the admin theme
     // from being used when the newsletter is sent from the
     // node add/edit form and the admin theme is other than the
-    // default theme. When no $custom_theme is set, the 
+    // default theme. When no $custom_theme is set, the
     // After theming the email $custom_theme is restored.
     global $custom_theme;
     $org_custom_theme = $custom_theme;
@@ -2111,10 +2110,10 @@
     // TODO: restore the format selection.
     //$build = node_view($node, 'email_' . $category->format);
     // Supported view modes: 'email_plain', 'email_html', 'email_textalt'
-    $build = node_view($node, 'email_plain'); 
+    $build = node_view($node, 'email_plain');
     // TODO Use simplenews_newsletter_body as #theme?
     unset($build['#theme']);
-    foreach(element_children($build) as $child) {
+    foreach (element_children($build) as $child) {
       $build[$child]['#theme'] = 'simplenews_field';
     }
 // END move this code to a function.
@@ -2156,7 +2155,7 @@
   $message['body']['footer'] = token_replace($footer, $context, array('sanitize' => FALSE));
 
   // Add user specific header data.
-  $message['headers']['List-Unsubscribe'] = '<'. token_replace('[simplenews-subscriber:unsubscribe-url]', $context, array('sanitize' => FALSE)) .'>';
+  $message['headers']['List-Unsubscribe'] = '<' . token_replace('[simplenews-subscriber:unsubscribe-url]', $context, array('sanitize' => FALSE)) . '>';
 }
 
 /**
@@ -2252,7 +2251,7 @@
  * @return drupal path
  */
 function simplenews_category_path($category) {
-  return 'simplenews/category/'. $category->tid;
+  return 'simplenews/category/' . $category->tid;
 }
 
 /**
@@ -2321,7 +2320,7 @@
       $query->condition('sc.tid', $tids);
     }
     if ($conditions) {
-      foreach($conditions as $key => $condition) {
+      foreach ($conditions as $key => $condition) {
         if ($key == 'show_all') {
           if (!$condition) {
             $query->condition('new_account', SIMPLENEWS_OPT_INOUT_HIDDEN, '<>');
@@ -2377,7 +2376,7 @@
   if (!is_object($category)) {
     $category = simplenews_category_load($category);
   }
-  
+
   if ($category) {
     db_delete('simplenews_category')
       ->condition('tid', $category->tid)
@@ -2391,12 +2390,12 @@
  *
  * @param $show_all
  *   FALSE = Don't show mailing lists which are marked 'hidden'.
- *   TRUE  = Show all mailing lists. 
+ *   TRUE  = Show all mailing lists.
  */
 function simplenews_get_mailing_lists($show_all = FALSE) {
   static $lists;
   $all = $show_all ? 'all' : 'not_all';
- 
+
   if (!isset($lists[$all])) {
     $categories = simplenews_categories_load_multiple(array(), array('show_all' => $show_all));
     $lists[$all] = $categories;
@@ -2435,7 +2434,7 @@
       $query->condition('nid', $nids);
     }
     if ($conditions) {
-      foreach($conditions as $key => $condition) {
+      foreach ($conditions as $key => $condition) {
         $query->condition($key, $condition);
       }
     }
@@ -2475,7 +2474,7 @@
   if (!is_object($newsletter)) {
     $newsletter = simplenews_newsletter_load($newsletter);
   }
-  
+
   if ($newsletter) {
     db_delete('simplenews_newsletter')
       ->condition('nid', $newsletter->nid)
@@ -2554,7 +2553,7 @@
     'name' => t('Newsletter URL'),
     'description' => t('The URL of this newsletter.'),
   );
-  
+
   // Tokens for simplenews newsletter category.
   $category['name'] = array(
     'name' => t('Newsletter category'),
@@ -2590,20 +2589,20 @@
       $account = $data['account'];
       $category = $data['category'];
       $language = isset($account->language->language) ? $account->language->language : language_default()->language;
-  
+
       // Build hash for the URL of the (un)subscribe confirmation page.
       $hash = '';
       if (isset($account->snid) && isset($category->tid)) {
         $hash = simplenews_generate_hash($account->mail, $account->snid, $category->tid);
       }
-  
+
       foreach ($tokens as $name => $original) {
         switch ($name) {
           // Simple key values on the node.
           case 'subscribe-url':
             $replacements[$original] = url('newsletter/confirm/add/' . $hash, array('absolute' => TRUE, 'language' => $language));
             break;
-    
+
           case 'unsubscribe-url':
             $replacements[$original] = url('newsletter/confirm/remove/' . $hash, array('absolute' => TRUE, 'language' => $language));
             break;
@@ -2626,7 +2625,7 @@
         }
       }
       break;
-  
+
     case 'simplenews-category':
       $category = $data['category'];
       foreach ($tokens as $name => $original) {
@@ -2640,7 +2639,7 @@
               $replacements[$original] = t('Unassigned newsletter');
             }
             break;
-    
+
           case 'url':
             // TODO replace path
             $replacements[$original] = url('taxonomy/term/' . $category->tid);
@@ -2673,7 +2672,7 @@
   if (!function_exists($callback)) {
     return array_merge($array1, $array2);
   }
-  foreach($array1 as $key => $data) {
+  foreach ($array1 as $key => $data) {
     if (isset($array2[$key])) {
       if ($callback($data)) {
         $array1[$key] = $array2[$key];
@@ -2763,10 +2762,10 @@
         if (module_exists('i18nstrings')) {
           global $language;
           $language_default = variable_get('language_default', $language);
-          $help = '<p>'. t('This is a Multilingual website. Enter text for confirmation subject and body in the default site language (@language).', array('@language' => $language_default->name)) ."</p>\n";
+          $help = '<p>' . t('This is a Multilingual website. Enter text for confirmation subject and body in the default site language (@language).', array('@language' => $language_default->name)) . "</p>\n";
         }
         else {
-          $help = '<p>'. t('This is a Multilingual website. <a href="@url">Enable the String translation module</a> to enable translation of the confirmation subject and body.', array('@url' => url('admin/build/modules'))) ."</p>\n";
+          $help = '<p>' . t('This is a Multilingual website. <a href="@url">Enable the String translation module</a> to enable translation of the confirmation subject and body.', array('@url' => url('admin/build/modules'))) . "</p>\n";
         }
         return $help;
       }
@@ -2857,7 +2856,7 @@
     'subscribe_subject',
     );
   foreach ($keys as $key) {
-    i18nstrings_update('simplenews:'. $key, simplenews_subscription_confirmation_text($key, NULL, FALSE));
+    i18nstrings_update('simplenews:' . $key, simplenews_subscription_confirmation_text($key, NULL, FALSE));
   }
   return TRUE;
 }
@@ -2879,7 +2878,7 @@
 function simplenews_subscription_confirmation_text($key, $langcode = NULL, $translate = TRUE) {
   $langcode = isset($language) ? $language->language : NULL;
 
-  $text = variable_get('simplenews_confirm_'. $key, FALSE);
+  $text = variable_get('simplenews_confirm_' . $key, FALSE);
   // If administrator did not change the text, the variable is empty.
   // We get the default here.
   if (!$text) {
@@ -2927,7 +2926,7 @@
  */
 function simplenews_theme() {
   $path = drupal_get_path('module', 'simplenews');
-  
+
   return array(
     'simplenews_admin_categories' => array(
       'render element' => 'form',
@@ -2936,7 +2935,7 @@
       'render element' => 'tid',
       'template' => 'simplenews-block',
       'pattern' => 'simplenews_block__',
-      'path' => $path  . '/theme',
+      'path' => $path . '/theme',
     ),
     'simplenews_status' => array(
       'file' => 'simplenews.admin.inc',
@@ -2952,26 +2951,26 @@
         'category' => NULL,
         'language' => NULL,
       ),
-      'path' => $path  . '/theme',
+      'path' => $path . '/theme',
     ),
     'simplenews_newsletter_footer' => array(
       'variables' => array(
         'build' => NULL,
         'category' => NULL,
-        'key'=> NULL,
+        'key' => NULL,
         'language' => NULL,
       ),
-      'path' => $path  . '/theme',
+      'path' => $path . '/theme',
     ),
     'simplenews_subscription_list' => array(
       'render element' => 'form',
       'file' => 'simplenews.admin.inc',
-      'path' => $path  . '/includes',
+      'path' => $path . '/includes',
     ),
     'simplenews_filter_form' => array(
       'render element' => 'form',
       'file' => 'simplenews.admin.inc',
-      'path' => $path  . '/includes',
+      'path' => $path . '/includes',
     ),
     'simplenews_field' => array(
       'render element' => 'element',
@@ -3045,9 +3044,9 @@
       $variables['items'][$delta] = $element[$delta];
     }
   }
- 
+
   $variables['view_mode'] = $variables['element']['#view_mode'];
-  
+
   // Add specific suggestions that can override the default implementation.
   $variables['theme_hook_suggestions'] = array(
     'simplenews_field__' . $element['#field_name'],
Index: tests/simplenews.test
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simplenews/tests/simplenews.test,v
retrieving revision 1.6
diff -u -r1.6 simplenews.test
--- tests/simplenews.test	20 Dec 2010 08:37:36 -0000	1.6
+++ tests/simplenews.test	6 Jan 2011 14:56:39 -0000
@@ -14,7 +14,7 @@
 
   public function setUp() {
     parent::setUp('taxonomy', 'simplenews', 'simplenews_test');
-    
+
     //$this->simplenews_admin_user = $this->drupalCreateUser(array('administer newsletters', 'administer simplenews settings', 'administer simplenews subscriptions'));
     //$this->sender_user = $this->drupalCreateUser(array('create simplenews content', 'edit own simplenews content', 'send newsletter'));
 
@@ -31,11 +31,14 @@
   function setAnonymousUserSubscription($enabled) {
 
     if ($enabled) {
-      db_query("UPDATE {permission} SET perm = '%s' WHERE rid = %d", 'access content, subscribe to newsletters', DRUPAL_ANONYMOUS_RID);
-    }
-    else {
-      db_query("UPDATE {permission} SET perm = '%s' WHERE rid = %d", 'access content', DRUPAL_ANONYMOUS_RID);
+      db_insert('role_permission')
+        ->fields(array('rid', 'permission'), array(DRUPAL_ANONYMOUS_RID, 'subscribe to newsletters'))
+        ->execute();
     }
+    db_insert('role_permission')
+      ->fields(array('rid', 'permission'), array(DRUPAL_ANONYMOUS_RID, 'access content'))
+      ->execute();
+    // Throw an error message with tests: Duplicate entry.
   }
 
   /**
@@ -46,7 +49,7 @@
    * this correctly.
    */
   function randomEmail($number = 4, $prefix = 'simpletest_', $domain = 'example.com') {
-    return strtolower($this->randomName($number, $prefix) .'@'. $domain);
+    return strtolower($this->randomName($number, $prefix) . '@' . $domain);
   }
 
   /**
@@ -81,7 +84,11 @@
    *  ['rss feed'] = {1, 0} Display RSS-feed icon
    */
   function setupSubscriptionBlock($tid, $settings = array()) {
-    $bid = db_result(db_query("SELECT bid FROM {blocks} WHERE module = 'simplenews' AND delta = '%s'", array($tid)));
+    $bid = db_select('blocks')
+      ->fields('block', array('bid'))
+      ->condition('module', 'simplenews')
+      ->condition('delta', $tid)
+      ->execute();
 
     // Check to see if the box was created by checking that it's in the database..
     $this->assertNotNull($bid, t('Block found in database'));
@@ -92,7 +99,7 @@
     $block['delta'] = $tid;
     $edit[$block['module'] . '_' . $block['delta'] . '[region]'] = 'left';
     $this->drupalPost('admin/build/block', $edit, t('Save blocks'));
-    
+
     // Set block parameters
     $edit = array();
     if (isset($settings['message'])) {
@@ -136,18 +143,18 @@
    * Test basic subscription block functionality.
    */
   function testBlockBasic() {
-    
+
     /* Test code goes here */
-    
+
   }
-  
+
   /**
    * Test multiple blocks on one page.
    */
   function testBlockMultiple() {
-    
+
     /* Test code goes here */
-    
+
   }
 }
 
@@ -182,7 +189,7 @@
     $this->setAnonymousUserSubscription(TRUE);
 
     // Setup subscription block with subscription form.
-    $block_settings = array(    
+    $block_settings = array(
       'message' => $this->randomName(4),
       'form' => '1',
       'link to previous' => FALSE,
@@ -193,18 +200,18 @@
     $this->setupSubscriptionBlock($tid, $block_settings);
 
     $this->drupalLogout();
-    
+
     //file_put_contents('output.html', $this->drupalGetContent());
 
     // 1. Subscribe anonymous via block
     // Subscribe + submit
     // Assert confirmation message
     // Assert outgoing email
-    // 
+    //
     // Confirm using mail link
     // Confirm using mail link
     // Assert confirmation message
-  
+
     $mail = $this->randomEmail(8, 'testmail');
     $edit = array (
       'mail' => $mail,
@@ -220,7 +227,7 @@
     $match = array();
     preg_match($pattern, $content, $match);
     $confirm_url = $match[1];
-    
+
     $pattern = '@http:/.*/newsletter/confirm/add/[0-9,a-f]{10}[0-9]+t[0-9]+@';
     $this->assertPattern($pattern, t('Confirmation URL found: @url', array('@url' => $confirm_url)));
 
@@ -234,12 +241,12 @@
     $this->assertRaw(t('%user was added to the %newsletter mailing list.', array('%user' => $mail, '%newsletter' => $newsletter->name)), t('Anonymous subscriber added to newsletter'));;
 
     //file_put_contents('output2.html', $this->drupalGetContent());
-    
+
     // 2. Subscribe anonymous via subscription page
     // Subscribe + submit
     // Assert confirmation message
     // Assert outgoing email
-    // 
+    //
     // Confirm using mail link
     // Confirm using mail link
     // Assert confirmation message
@@ -259,7 +266,7 @@
     $match = array();
     preg_match($pattern, $content, $match);
     $confirm_url = $match[1];
-    
+
     $pattern = '@http:/.*/newsletter/confirm/add/[0-9,a-f]{10}[0-9]+t[0-9]+@';
     $this->assertPattern($pattern, t('Confirmation URL found: @url', array('@url' => $confirm_url)));
 
@@ -299,7 +306,7 @@
     $this->setAnonymousUserSubscription(TRUE);
 
     // Setup subscription block with subscription form.
-    $block_settings = array(    
+    $block_settings = array(
       'message' => $this->randomName(4),
       'form' => '1',
       'link to previous' => FALSE,
