Index: simplenews-newsletter-footer.tpl.php
===================================================================
--- simplenews-newsletter-footer.tpl.php	(revision 31252)
+++ simplenews-newsletter-footer.tpl.php	(working copy)
@@ -27,7 +27,7 @@
 <?php if ($format == 'html'): ?>
   <p class="newsletter-footer"><a href="!confirm_unsubscribe_url"><?php print $unsubscribe_text ?></a></p>
 <?php else: ?>
--- <?php print $unsubscribe_text ?>: !confirm_unsubscribe_url
+-- <?php print $unsubscribe_text ?>: [simplenews-unsubscribe-url]
 <?php endif ?>
 
 <?php if ($key == 'test'): ?>
Index: simplenews.admin.inc
===================================================================
--- simplenews.admin.inc	(revision 31252)
+++ simplenews.admin.inc	(working copy)
@@ -950,15 +950,11 @@
     '#description' => t('When checked subscriptions will be synchronized with site accounts. When accounts are deteted, subscriptions with the same email address will be removed. When site accounts are blocked/unblocked, subscriptions will be deactivated/activated. When not checked subscriptions will be unchanged when associated accounts are deleted or blocked.'),
   );
 
-  // These email tokens are shared for all settings, so just define
-  // the list once to help ensure they stay in sync.
-  $email_token_help = t('Available variables are:') .' !site, !uri, !uri_brief, !mailto, !date, !newsletter_name, !confirm_subscribe_url, !confirm_unsubscribe_url.';
-
   $form['simplenews_subscription']['subscription_mail'] = array(
     '#type' => 'fieldset',
     '#title' => t('Confirmation emails'),
     '#collapsible' => FALSE,
-    '#description' => t('Customize the confimation email which is sent to (un)subscribing visitors.') .' '. $email_token_help,
+    '#description' => t('Customize the confimation email which is sent to (un)subscribing visitors with the tokens you can see by Replacement patterns.'),
   );
   $form['simplenews_subscription']['subscription_mail']['simplenews_confirm_subscribe_subject'] = array(
     '#type' => 'textfield',
@@ -990,6 +986,15 @@
     '#default_value' => _simplenews_subscription_confirmation_text('unsubscribe_unsubscribed'),
     '#rows' => 5,
   );
+  $form['simplenews_subscription']['subscription_mail']['token_help'] = array(
+    '#title' => t('Replacement patterns'),
+    '#type' => 'fieldset',
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+  );
+  $form['simplenews_subscription']['subscription_mail']['token_help']['help'] = array(
+    '#value' => theme('token_help', 'simplenews_subscribe'),
+  );
 
   return system_settings_form($form);
 }
Index: simplenews.module
===================================================================
--- simplenews.module	(revision 31252)
+++ simplenews.module	(working copy)
@@ -334,13 +334,9 @@
       if (!isset($node->simplenews_mail)) {
         global $language;
         $context['node'] = $node;
-        $variables = simplenews_mail_tokens($user, $context, $language);
-        if (isset($node->body)) {
-          $node->body = strtr($node->body, $variables);
-        }
-        if (isset($node->teaser)) {
-          $node->teaser = strtr($node->teaser, $variables);
-        }
+        
+        $node->body = token_replace($node->body, 'node', $node);
+        
       }
       break;
     case 'validate':
@@ -511,8 +507,18 @@
       // Available variables are based on user_mail_tokens().
       // But uses only those which can be used with uid = 0 since simplenews also sends to anonymous users.
       if (isset($form['body_field'])) {
-        $form['body_field']['body']['#description'] = t("This will be the body of your newsletter. Available variables are: !site (the name of your website), !uri (a link to your homepage), !uri_brief (homepage link without the http://), !date (today's date), !login_uri (link to login page), !confirm_subscribe_url (subscription confirmation link), !confirm_unsubscribe_url (unsubscription link), !newsletter_url (link to this newsletter issue), !newsletter_name (name of this newsletter series).");
+        $form['body_field']['body']['#description'] = t("This will be the body of your newsletter. You can see all available variables under 'Replacement patterns')");
       }
+      $form['simplenews_subscription']['subscription_mail']['token_help'] = array(
+        '#title' => t('Replacement patterns'),
+    	'#type' => 'fieldset',
+    	'#collapsible' => TRUE,
+    	'#collapsed' => TRUE,
+        '#weight' => -20,
+      );
+      $form['simplenews_subscription']['subscription_mail']['token_help']['help'] = array(
+    	'#value' => theme('token_help', 'simplenews'),
+      );
 
       if (isset($form['#node']->simplenews)) {
         $simplenews_values = $form['#node']->simplenews;
@@ -1457,6 +1463,10 @@
 function simplenews_mail($key, &$message, $params) {
   $context = $params['context'];
 
+  $object =  new stdClass();
+  $object->tid = $params['context']['newsletter']->tid;
+  $object->uid = $params['context']['account']->uid;
+  
   switch ($key) {
     case 'node':
     case 'test':
@@ -1565,48 +1575,54 @@
         $footer             = $messages[$nid][$langcode]['footer'];
       }
 
-      // Build message body.
-      // Replace tokens with user specific data and
       // Convert to plain text if required.
-      $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));
       }
+      // Build message body.
+      // Replace tokens with user specific data and
       $message['body']['body'] = $body;
-
+      $message['body']['body'] = token_replace($message['body']['body'], 'simplenews', $object);
+      
       // Build message footer.
       // Replace tokens with user specific data
-      $message['body']['footer'] = strtr($footer, $variables);
+      $message['body']['footer'] = $footer;
+      $message['body']['footer'] = token_replace($message['body']['footer'], 'simplenews', $object);
 
       // Add user specific header data.
-      $message['headers']['List-Unsubscribe'] = strtr('<!confirm_unsubscribe_url>', $variables);
-
+      $message ['headers']['List-Unsubscribe'] = token_replace('[simplenews-unsubscribe-url]', 'simplenews', $object);
+      
       break;
     case 'subscribe':
       // Use formatted from address "name" <mail_address>
       $message['headers']['From'] = $params['from']['formatted'];
 
-      $variables =  simplenews_mail_tokens($context['account'], $context, is_object($context['account']->language) ? $context['account']->language : language_default());
-      $message['subject'] = _simplenews_subscription_confirmation_text('subscribe_subject', $context['account']->language, $variables);
+      $message['subject'] = _simplenews_subscription_confirmation_text('subscribe_subject', $langcode);
+      $message['subject'] = token_replace($message['subject'], 'simplenews_subscribe', $params);
+      
       if (simplenews_user_is_subscribed($context['account']->mail, $context['newsletter']->tid)) {
-        $message['body'] = _simplenews_subscription_confirmation_text('subscribe_subscribed', $context['account']->language, $variables);
+        $message['body'] = _simplenews_subscription_confirmation_text('subscribe_subscribed', $langcode);
+        $message['body'] = token_replace($message['body'], 'simplenews_subscribe', $params);
       }
       else {
-        $message['body'] = _simplenews_subscription_confirmation_text('subscribe_unsubscribed', $context['account']->language, $variables);
+        $message['body'] = _simplenews_subscription_confirmation_text('subscribe_unsubscribed', $langcode);
+        $message['body'] = token_replace($message['body'], 'simplenews_subscribe', $params);
       }
       break;
     case 'unsubscribe':
       // Use formatted from address "name" <mail_address>
       $message['headers']['From'] = $params['from']['formatted'];
 
-      $variables =  simplenews_mail_tokens($context['account'], $context, is_object($context['account']->language) ? $context['account']->language : language_default());
-      $message['subject'] = _simplenews_subscription_confirmation_text('subscribe_subject', $context['account']->language, $variables);
+      $message['subject'] = _simplenews_subscription_confirmation_text('subscribe_subject', $langcode);
+      $message['subject'] = token_replace($message['subject'], 'simplenews_subscribe', $params);
+      
       if (simplenews_user_is_subscribed($context['account']->mail, $context['newsletter']->tid)) {
-        $message['body'] = _simplenews_subscription_confirmation_text('unsubscribe_subscribed', $context['account']->language, $variables);
+        $message['body'] = _simplenews_subscription_confirmation_text('unsubscribe_subscribed', $langcode);
+        $message['body'] = token_replace($message['body'], 'simplenews_subscribe', $params);
       }
       else {
-        $message['body'] = _simplenews_subscription_confirmation_text('unsubscribe_unsubscribed', $context['account']->language, $variables);
+        $message['body'] = _simplenews_subscription_confirmation_text('unsubscribe_unsubscribed', $langcode);
+        $message['body'] = token_replace($message['body'], 'simplenews_subscribe', $params);
       }
       break;
   }
@@ -2080,54 +2096,110 @@
 }
 
 /**
- * Build array of mail tokens.
- *
- * Depending on the context in which this function is called, some tokens
- * may return an empty value. e.g. !newsletter_url is empty when called
- * while building a confirmation email.
- *
- * @param $subscription
- *  Subscription or user object
- * @param $context
- *  [newsletter] newsletter term object
- *  [node] node object
- * @param $language
- *  Language object
- *
- * @return array of tokens and token values.
+ * Implementation of hook_token_list().
  */
-function simplenews_mail_tokens($subscription, $context, $language) {
-  // Build hash for (un)subscription confirmation link for subscribed user.
-  $hash = '';
-  if (isset($subscription->snid) && isset($context['newsletter']->tid)) {
-    $hash = _simplenews_generate_hash($subscription->mail, $subscription->snid, $context['newsletter']->tid);
+function simplenews_token_list($type = 'simplenews') {
+
+  $tokens = array();
+  
+  if ($type == 'simplenews_subscribe') {
+    $tokens['simplenews']['simplenews-subscribe-url'] = t('Site URL of subscription page');
+    $tokens['simplenews']['simplenews-category'] = t('Shows the Category of the newsletter');
+    $tokens['simplenews']['simplenews-uri'] = t('The URL of the site');
+    $tokens['simplenews']['simplenews-rec_email'] = t('The email-address of the newsletter receiver');
   }
+  
+  else if ( $type == 'all' || $type == 'global' ||$type == 'node' || $type == 'user' || $type == 'simplenews') {
+    $tokens['simplenews']['simplenews-subscribe-url']  = t('Site URL of subscription page');
+    $tokens['simplenews']['simplenews-unsubscribe-url']= t('Site URL of unsubscription page');
+    $tokens['simplenews']['simplenews-category'] = t('Shows the Category of the newsletter');
+    $tokens['simplenews']['simplenews-receiver'] = t('The name of the newsletter receiver');
+    $tokens['simplenews']['simplenews-rec_email'] = t('The email-address of the newsletter receiver');
+    $tokens['simplenews']['simplenews-uri'] = t('The URL of the site');
+    $tokens['simplenews']['simplenews-category-all'] = t('A list of the last newsletters from this category');
+  }
+  return $tokens;
+}
+
+/**
+ * Implementation of hook_token_value().
+ */
+function simplenews_token_values($type, $object = NULL, $options = array()) {
+  
+  $uid = $object->uid;
+  $tid = $object->tid;
+    
+  if ($type == 'simplenews_subscribe') {
+    global $base_url;
 
-  // 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'])) {
-        // 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);
+    $users->snid = $object['context']['account']->snid;
+    $users->tid = $object['context']['newsletter']->tid;
+    $users->email = $object['context']['account']->mail;
+    
+    $hash = '';
+    if (isset($users->snid) && isset($users->tid)) {
+      $hash = _simplenews_generate_hash($users->email, $users->snid, $users->tid);
+    }    
+    $values['simplenews-subscribe-url']      = l('Confirm Subscribe' ,'newsletter/confirm/add/'. $hash, array('absolute' => TRUE, 'language' => $language));      
+    $values['simplenews-category']           = $object['context']['newsletter']->name;
+    $values['simplenews-uri']                = url($base_url);
+    $values['simplenews-rec_email']          = $users->email;
+  }
+  else if ($type == 'all' || $type == 'global'|| $type == 'node' || $type == 'user' || $type == 'simplenews') {
+    global $base_url;
+    
+    $sql = "SELECT distinct users.name as u_name, ss.mail as email, t.name as t_name, t.tid, ss.snid
+    		FROM {users},
+    			 {simplenews_subscriptions} as ss, 
+    			 {simplenews_snid_tid} as st, 
+    			 {term_data} as t, 
+    			 {simplenews_newsletters} as sn
+    		WHERE ss.snid = st.snid
+    		AND sn.tid = t.tid
+    		AND st.tid = t.tid
+    		AND st.tid = %d
+    		AND ss.uid = %d
+    		AND ss.uid = users.uid
+    		AND activated = 1
+    		ORDER BY ss.snid";    
+    
+    $result = db_query($sql, $tid, $uid);
+    while ($object = db_fetch_object($result)) {
+      $users->u_name = $object->u_name;
+      $users->email = $object->email;
+      $users->t_name = $object->t_name;
+      $users->tid = $object->tid;
+      $users->snid = $object->snid;
+    }
+    
+    $hash = '';
+    if (isset($users->snid) && isset($users->tid)) {
+      $hash = _simplenews_generate_hash($users->email, $users->snid, $users->tid);
+    }
+    // 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'])) {
+          // 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);
+          }
         }
       }
-    }
+    } 
+    $values['simplenews-uri']                = l('Visit us', $base_url);
+    $values['simplenews-subscribe-url']      = l('Confirm Subscribe' ,'newsletter/confirm/add/'. $hash, array('absolute' => TRUE, 'language' => $language));      
+    $values['simplenews-unsubscribe-url']    = l('Confirm Unsubscribe', 'newsletter/confirm/remove/'. $hash, array('absolute' => TRUE, 'language' => $language));
+    $values['simplenews-category']		     = $users->t_name;      
+    $values['simplenews-rec_email']          = $users->email;
+    $values['simplenews-receiver']           = $users->u_name;
+    $values['simplenews-category-all']       = l('Older Newsletters' ,$base_url . '/'.taxonomy_term_path($terms). $users->tid); 
+    
   }
-
-  // Get tokens from user_mail_tokens() and add simplenews variables.
-  $vars = $subscription->uid ? user_mail_tokens($subscription, $language) : array();
-  // Replace existing uri and uri_brief to cope with multilingual sites.
-  $vars['!uri'] = url('', array('absolute' => TRUE, 'language' => $language));
-  $vars['!uri_brief'] = preg_replace('!^https?://!', '', $vars['!uri']);
-  $vars['!confirm_subscribe_url'] = url('newsletter/confirm/add/'. $hash, array('absolute' => TRUE, 'language' => $language));
-  $vars['!confirm_unsubscribe_url'] = url('newsletter/confirm/remove/'. $hash, array('absolute' => TRUE, 'language' => $language));
-  $vars['!newsletter_url'] = isset($context['node']->nid) ? url('node/'. $context['node']->nid, array('absolute' => TRUE, 'language' => $language)) : '';
-  $vars['!newsletter_name'] = $name;
-
-  return $vars;
+  
+  return $values;
 }
 
 /**
@@ -2248,21 +2320,21 @@
 
   if ($admin_setting = variable_get('simplenews_confirm_'. $key, FALSE)) {
     // An admin setting overrides the default string.
-    return t($admin_setting, $variables, $langcode);
+    return $admin_setting;
   }
   else {
     // No override, return default string.
     switch ($key) {
       case 'subscribe_unsubscribed':
-        return t("We have received a request for subscription of !mailto to the !newsletter_name on !site website at !uri. To confirm this subscription please use the link below.\n\n!confirm_subscribe_url", $variables, $langcode);
+        return t("We have received a request from the email [simplenews-rec_email] for subscription to the [simplenews-category] newsletter on [site-name] website at [simplenews-uri]. To confirm this subscription please use the link below.\n\n[simplenews-subscribe-url]", $langcode);
       case 'subscribe_subscribed':
-        return t("We have received a request for subscription of !mailto to the !newsletter_name on !site website at !uri. However, this email is already subscribed to this newsletter. If you intended to unsubscribe please visit our site: !uri", $variables, $langcode);
+        return t("We have received a request from the email [simplenews-rec_email] for subscription to the [simplenews-category] newsletter on [site-name] website at [simplenews-uri]. However, this email is already subscribed to this newsletter. If you intended to unsubscribe please visit our site: [simplenews-uri]", $langcode);
       case 'unsubscribe_subscribed':
-        return t("We have received a request to unsubscribe !mailto from the !newsletter_name on !site website at !uri. To confirm this unsubscription please use the link below.\n\n!confirm_unsubscribe_url", $variables, $langcode);
+        return t("We have received a request from the email [simplenews-rec_email] to unsubscribe you from the [simplenews-category] on [site-name] website at [simplenews-uri]. To confirm this unsubscription please use the  below.\n\n[simplenews-unsubscribe-url]", $langcode);
       case 'unsubscribe_unsubscribed':
-        return t("We have received a request to unsubscribe !mailto from the !newsletter_name on !site website at !uri. However, this email is not subscribed to this newsletter. If you intended to subscribe please visit our site: !uri", $variables, $langcode);
+        return t("We have received a from the email [simplenews-rec_email] request to unsubscribe you from the [simplenews-category] on [site-name] website at [simplenews-uri]. However, this email is not subscribed to this newsletter. If you intended to subscribe please visit our site: [simplenews-uri]", $langcode);
       case 'subscribe_subject':
-        return t("Confirmation for !newsletter_name from !site", $variables, $langcode);
+        return t("Confirmation for [simplenews-category] from [site-name]", $langcode);
     }
   }
 }
