? webform.353748.patch
Index: webform.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform.module,v
retrieving revision 1.196.2.54
diff -u -p -r1.196.2.54 webform.module
--- webform.module	8 Sep 2010 05:23:47 -0000	1.196.2.54
+++ webform.module	23 Sep 2010 21:05:57 -0000
@@ -2613,8 +2613,11 @@ function _webform_safe_name($name) {
  * @param $format
  *   The e-mail format, defaults to the site-wide setting. May be either "short"
  *   or "long".
+ * @param $filter_tokens
+ *   Whether or not to process the email for webform tokens. Used when presenting
+ *   token-based email address in the administrative UI. Defaults to TRUE.
  */
-function webform_format_email_address($address, $name, $node = NULL, $submission = NULL, $encode = TRUE, $single = TRUE, $format = NULL) {
+function webform_format_email_address($address, $name, $node = NULL, $submission = NULL, $encode = TRUE, $single = TRUE, $format = NULL, $filter_tokens = TRUE) {
   if (!isset($format)) {
     $format = variable_get('webform_email_address_format', 'long');
   }
@@ -2654,13 +2657,15 @@ function webform_format_email_address($a
   }
 
   // Address may be an array if a component value was used on checkboxes.
-  if (is_array($address)) {
-    foreach ($address as $key => $individual_address) {
-      $address[$key] = _webform_filter_values($individual_address, $node, $submission, NULL, FALSE, TRUE);
+  if ($filter_tokens) {
+    if (is_array($address)) {
+      foreach ($address as $key => $individual_address) {
+        $address[$key] = _webform_filter_values($individual_address, $node, $submission, NULL, FALSE, TRUE);
+      }
+    }
+    else {
+      $address = _webform_filter_values($address, $node, $submission, NULL, FALSE, TRUE);
     }
-  }
-  else {
-    $address = _webform_filter_values($address, $node, $submission, NULL, FALSE, TRUE);
   }
 
   if ($format == 'long' && !empty($name)) {
@@ -2677,8 +2682,18 @@ function webform_format_email_address($a
 
 /**
  * Given an email subject, format it with any needed replacements.
+ * 
+ * @param $subject
+ *  The raw subject string.
+ * @param $node
+ *   The webform node if replacements will be done.
+ * @param $submission
+ *   The webform submission values if replacements will be done.
+ * @param $filter_tokens
+ *   Whether or not to process the subject for webform tokens. Used when presenting
+ *   token-based subject in administrative UI. Defaults to TRUE.
  */
-function webform_format_email_subject($subject, $node = NULL, $submission = NULL) {
+function webform_format_email_subject($subject, $node = NULL, $submission = NULL, $filter_tokens = TRUE) {
   if ($subject == 'default') {
     $subject = webform_variable_get('webform_default_subject');
   }
@@ -2708,7 +2723,7 @@ function webform_format_email_subject($s
     $subject = reset($subject);
   }
 
-  return _webform_filter_values($subject, $node, $submission, NULL, FALSE, TRUE);
+  return $filter_tokens ? _webform_filter_values($subject, $node, $submission, NULL, FALSE, TRUE) : $subject;
 }
 
 /**
Index: includes/webform.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/includes/webform.admin.inc,v
retrieving revision 1.4.2.4
diff -u -p -r1.4.2.4 webform.admin.inc
--- includes/webform.admin.inc	30 Aug 2010 20:22:15 -0000	1.4.2.4
+++ includes/webform.admin.inc	23 Sep 2010 21:05:57 -0000
@@ -53,21 +53,27 @@ function webform_admin_settings() {
     '#type' => 'textfield',
     '#title' => t('From address'),
     '#default_value' => variable_get('webform_default_from_address', variable_get('site_mail', ini_get('sendmail_from'))),
-    '#description' => t('The default sender address for emailed webform results; often the e-mail address of the maintainer of your forms.'),
+    '#description' => t('The default sender address for emailed webform results; often the e-mail address of the maintainer of your forms. You may configure this using the tokens listed below.'),
   );
 
   $form['email']['webform_default_from_name']  = array(
     '#type' => 'textfield',
     '#title' => t('From name'),
     '#default_value' => variable_get('webform_default_from_name', variable_get('site_name', '')),
-    '#description' => t('The default sender name which is used along with the default from address.'),
+    '#description' => t('The default sender name which is used along with the default from address. You may configure this using the tokens listed below.'),
   );
 
   $form['email']['webform_default_subject']  = array(
     '#type' => 'textfield',
     '#title' => t('Default subject'),
     '#default_value' => variable_get('webform_default_subject', t('Form submission from: %title')),
-    '#description' => t('The default subject line of any e-mailed results.'),
+    '#description' => t('The default subject line of any e-mailed results. You may configure this using the tokens listed below.'),
+  );
+
+  $form['email']['tokens'] = array(
+    // While we theoretically could use node tokens here, the only webform node tokens currently available are very specific to an individual webform. This
+    // eliminates there usability for global webform settings. If more traditional node tokens are added, such as author email were added, the story would change.
+    '#value' => theme('webform_token_help'),
   );
 
   $form['email']['webform_default_format']  = array(
Index: includes/webform.emails.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/includes/webform.emails.inc,v
retrieving revision 1.9.2.10
diff -u -p -r1.9.2.10 webform.emails.inc
--- includes/webform.emails.inc	30 Aug 2010 20:22:15 -0000	1.9.2.10
+++ includes/webform.emails.inc	23 Sep 2010 21:05:57 -0000
@@ -28,17 +28,17 @@ function webform_emails_form($form_state
   foreach ($node->webform['emails'] as $eid => $email) {
     $email_addresses = array_filter(explode(',', check_plain($email['email'])));
     foreach ($email_addresses as $key => $email_address) {
-      $email_addresses[$key] = webform_format_email_address($email_address, NULL, $node, NULL, FALSE);
+      $email_addresses[$key] = webform_format_email_address($email_address, NULL, $node, NULL, FALSE, TRUE, NULL, FALSE);
     }
-
     $form['emails'][$eid]['email'] = array(
       '#value' => implode('<br />', $email_addresses),
     );
     $form['emails'][$eid]['subject'] = array(
-      '#value' => check_plain(webform_format_email_subject($email['subject'], $node)),
+      '#value' => check_plain(webform_format_email_subject($email['subject'], $node, NULL, FALSE)),
     );
+
     $form['emails'][$eid]['from'] = array(
-      '#value' => check_plain(webform_format_email_address($email['from_address'], $email['from_name'], $node, NULL, FALSE)),
+      '#value' => check_plain(webform_format_email_address($email['from_address'], $email['from_name'], $node, NULL, FALSE, TRUE, NULL, FALSE)),
     );
   }
 
@@ -193,19 +193,19 @@ function webform_email_edit_form($form_s
         $description = t('Form submissions will be e-mailed to this address. Any email, select, or hidden form element may be selected as the recipient address. Multiple e-mail addresses may be separated by commas.');
         break;
       case 'subject':
-        $default_value = _webform_filter_values(webform_variable_get('webform_default_subject'), $node);
+        $default_value = webform_variable_get('webform_default_subject');
         $title = t('E-mail subject');
-        $description = t('Any textfield, select, or hidden form element may be selected as the subject for e-mails.');
+        $description = t('Any textfield, select, or hidden form element may be selected as the subject for e-mails. See the email template for available token values.');
         break;
       case 'from_address':
-        $default_value = _webform_filter_values(webform_variable_get('webform_default_from_address'), $node);
+        $default_value = webform_variable_get('webform_default_from_address');
         $title = t('E-mail from address');
-        $description = t('Any email, select, or hidden form element may be selected as the sender\'s e-mail address.');
+        $description = t("Any email, select, or hidden form element may be selected as the sender's e-mail address. See the email template for available token values.");
         break;
       case 'from_name':
-        $default_value = _webform_filter_values(webform_variable_get('webform_default_from_name'), $node);
+        $default_value = webform_variable_get('webform_default_from_name');
         $title = t('E-mail from name');
-        $description = t('Any textfield, select, or hidden form element may be selected as the sender\'s name for e-mails.');
+        $description = t("Any textfield, select, or hidden form element may be selected as the sender's name for e-mails. See the email template for available token values.");
         break;
     }
 
@@ -390,8 +390,16 @@ function webform_email_address_validate(
  * Validate handler for webform_email_edit_form().
  */
 function webform_email_edit_form_validate($form, &$form_state) {
-  if ($form_state['values']['from_address_option'] == 'custom' && !valid_email_address($form_state['values']['from_address_custom'])) {
-    form_set_error('from_address_custom', t('The entered e-mail address "@email" does not appear valid.', array('@email' => $form_state['values']['from_address_custom'])));
+  // Because tokens might be used in place of a valid email address, the address must be checked for tokens before validating.
+  $filtered_from_address = _webform_filter_values($form_state['values']['from_address_custom'], $form['node']);
+
+  if ($form_state['values']['from_address_option'] == 'custom' && !valid_email_address($filtered_from_address)) {
+    if ($filtered_from_address != $form_state['values']['from_address_custom']) {
+      form_set_error('from_address_custom', t('The entered e-mail address "@raw" is rendered as "@email", which does not appear valid.', array('@raw' =>  $form_state['values']['from_address_custom'], '@email' => $filtered_from_address)));
+    }
+    else {
+      form_set_error('from_address_custom', t('The entered e-mail address "@email" does not appear valid.', array('@email' => $filtered_from_address)));
+    }
   }
 }
 
