diff -ruN original/htmlmail.admin.inc mod/htmlmail.admin.inc
--- original/htmlmail.admin.inc	2011-06-05 03:36:41.000000000 +0700
+++ mod/htmlmail.admin.inc	2011-06-10 16:15:35.000000000 +0700
@@ -9,16 +9,32 @@
  * Implements hook_admin_settings().
  */
 function htmlmail_admin_settings() {
-  $formats = array('0' => 'Unfiltered');
+  $formats = array('0' => t('Unfiltered'));
   foreach (filter_formats() as $id => $filter) {
     $formats[$id] = $filter->name;
   }
-  $form['Step 1'] = array(
+  
+  $form['pre-filter'] = array(
     '#type' => 'fieldset',
     '#title' => '<h3>' . t('Step 1') . '</h3>',
     '#collapsible' => FALSE,
   );
-  $form['Step 1']['htmlmail_template'] = array(
+  $form['pre-filter']['htmlmail_prefilter'] = array(
+    '#type' => 'select',
+    '#title' => t('Pre-filtering'),
+    '#default_value' => variable_get('htmlmail_prefilter', 0),
+    '#options' => $formats,
+    '#suffix' => '<p>'
+    . t('You may choose an <a href="!formats">input format</a> to be used for filtering message body <em>before</em> theming.')
+    . '</p>',
+  );
+  
+  $form['template'] = array(
+    '#type' => 'fieldset',
+    '#title' => '<h3>' . t('Step 2') . '</h3>',
+    '#collapsible' => FALSE,
+  );
+  $form['template']['htmlmail_template'] = array(
     '#type' => 'fieldset',
     '#prefix' => '<strong>' . t('Template file') . ':</strong><br />'
     . t('A template file is applied to your message header, subject, and body text.  You may copy the <a href="!uri">!template</a> file to your default theme directory and use it to customize your messages.',
@@ -31,7 +47,7 @@
     '#collapsible' => TRUE,
     '#collapsed' => TRUE,
   );
-  $form['Step 1']['htmlmail_template']['instructions'] = array(
+  $form['template']['htmlmail_template']['instructions'] = array(
     '#type' => 'item',
     '#suffix' => t('!Instructions
 <p>When formatting an email message with a given <code>$module</code> and <code>$key</code>, <a href="http://drupal.org/project/htmlmail">HTML Mail</a> will use the first template file it finds from the following list:</p>
@@ -132,19 +148,19 @@
       array('!Instructions' => '')
     ),
   );
-  $form['Step 1']['htmlmail_debug'] = array(
+  $form['template']['htmlmail_debug'] = array(
     '#type' => 'checkbox',
     '#prefix' => '<br />',
     '#title' => '<em>' . t('(Optional)') . '</em> ' . t('Debug'),
     '#default_value' => variable_get('htmlmail_debug', '0'),
     '#description' => t('Add debugging info (Set <code>$debug</code> to <code>TRUE</code>).'),
   );
-  $form['Step 2'] = array(
+  $form['theme'] = array(
     '#type' => 'fieldset',
     '#title' => '<h3>' . t('Step 2') . '</h3>',
     '#collapsible' => FALSE,
   );
-  $form['Step 2']['htmlmail_theme'] = array(
+  $form['theme']['htmlmail_theme'] = array(
     '#type' => 'select',
     '#title' => t('Email theme'),
     '#default_value' => variable_get('htmlmail_theme', ''),
@@ -175,12 +191,12 @@
     )
     . '</p>',
   );
-  $form['Step 3'] = array(
+  $form['post-filter'] = array(
     '#type' => 'fieldset',
     '#title' => '<h3>' . t('Step 3') . '</h3>',
     '#collapsible' => FALSE,
   );
-  $form['Step 3']['htmlmail_postfilter'] = array(
+  $form['post-filter']['htmlmail_postfilter'] = array(
     '#type' => 'select',
     '#title' => t('Post-filtering'),
     '#default_value' => variable_get('htmlmail_postfilter', ''),
diff -ruN original/htmlmail.mail.inc mod/htmlmail.mail.inc
--- original/htmlmail.mail.inc	2011-06-05 03:36:41.000000000 +0700
+++ mod/htmlmail.mail.inc	2011-06-10 16:44:17.000000000 +0700
@@ -48,6 +48,7 @@
       if (is_array($message['body'])) {
         $message['body'] = implode("$eol$eol", $message['body']);
       }
+      $message['body'] = $this->preFilter($message['body']);
       $body = theme('htmlmail', $message);
       // @todo Change to drupal_html_to_text when issue #299138 gets resolved.
       $plain = mailsystem_html_to_text($body);
@@ -103,6 +104,7 @@
   public function formatMailMIME(array &$message) {
     $eol = variable_get('mail_line_endings', MAIL_LINE_ENDINGS);
     $message['body'] = MailMIME::concat($message['body']);
+    $message['body'] = $this->preFilter($message['body']);
     // Build a full email message string.
     $email = MailMIME::encodeEmail($message['headers'], $message['body']);
     // Parse it into MIME parts.
@@ -138,7 +140,22 @@
     $message['MailMIME'] = &$mime;
     return $body;
   }
-
+  
+  /**
+   * Applies pre-filtering to message body after concatenation it to
+   * single string.
+   * 
+   * @param string $body Message body
+   */
+  protected function preFilter($body) {
+    if ($format = variable_get('htmlmail_prefilter', 0)) {
+      return check_markup($body, $format, FALSE);
+    }
+    else {
+      return $body;
+    }
+  }
+  
   /**
    * Send an email message.
    *
