--- /sites/all/modules/htmlmail/htmlmail.admin.inc.orig	Mon Jul 13 10:25:29 2009
+++ /sites/all/modules/htmlmail/htmlmail.admin.inc	Fri Aug 21 02:46:51 2009
@@ -2,6 +2,8 @@
 // $Id: htmlmail.admin.inc,v 1.1.2.3 2009/07/13 08:25:29 chrisherberte Exp $
 
 function htmlmail_admin_settings() {
+  $token_module_exists = module_exists('token');
+  
   $form['htmlmail_autop'] = array(
     '#type' => 'checkbox',
     '#title' => t('Line break converter'),
@@ -14,6 +16,13 @@
     '#default_value' => variable_get('htmlmail_urlfilter', '1'),
     '#description' => t('Automatically converts text web addresses (URLs, e-mail addresses, ftp links, etc.) into hyperlinks.'),
   );
+  $form['htmlmail_token'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Token support'),
+    '#default_value' => variable_get('htmlmail_token', '0'),
+    '#description' => t('Make use of the <strong><a href="http://drupal.org/project/token">Token</a></strong> module in order to tune up your mail header and footer. <em>You need to have the module installed.</em>'),
+    '#disabled' => !$token_module_exists,
+  );
   $form['htmlmail_emogrifier'] = array(
     '#type' => 'checkbox',
     '#title' => t('Emogrifier'),
@@ -35,11 +44,33 @@
     '#title' => t('Header HTML'),
     '#default_value' => variable_get('htmlmail_header', ''),
   );
+  
+  if (module_exists('token') && variable_get('htmlmail_token', '0')) {
+    $form['htmlmail_header_tokens'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Replacement patterns'),
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE,
+      '#description' => theme('htmlmail_token_help'),
+    );
+  }
+  
   $form['htmlmail_footer'] = array(
     '#type' => 'textarea',
     '#title' => t('Footer HTML'),
     '#default_value' => variable_get('htmlmail_footer', ''),
   );
+
+  if (module_exists('token') && variable_get('htmlmail_token', '0')) {
+    $form['htmlmail_footer_tokens'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Replacement patterns'),
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE,
+      '#description' => theme('htmlmail_token_help'),
+    );
+  }
+  
   $form['htmlmail_css'] = array(
     '#type' => 'textarea',
     '#title' => t('CSS'),
