Index: commentmail.module
===================================================================
--- commentmail.module	(revision 1183)
+++ commentmail.module	(working copy)
@@ -196,16 +196,7 @@
 
         // Only send a mail if a recipient has been specified
         if ($recipient) {
-          // Load the node to get the title
-          $node = node_load($comment_obj->nid);
 
-          if ($comment_obj->status == COMMENT_NOT_PUBLISHED) {
-            $text = variable_get('commentmail_mail_approve', t(COMMENTMAIL_DEFAULT_APPROVE));
-          }
-          else {
-            $text = variable_get('commentmail_mail_notify', t(COMMENTMAIL_DEFAULT_NOTIFY));
-          }
-
           // If the user is logged in, 
           if ($comment_obj->uid) {
             $account = user_load(array('uid' => $comment_obj->uid));
@@ -213,29 +204,13 @@
             $comment_obj->homepage = $account->homepage;
           }
 
-          $body = strtr($text, array(
-            '@site' => variable_get('site_name', 'Drupal'),
-            '@node' => $node->title,
-            '@approval_url' => url('comment/approve/'. $comment_obj->cid, NULL, NULL, TRUE),
-            '@delete_url' => url('comment/delete/'. $comment_obj->cid, NULL, NULL, TRUE),
-            '@ban_url' => url('comment/deleteban/'. $comment_obj->cid, NULL, NULL, TRUE),
-            '@edit_url' => url('comment/edit/'. $comment_obj->cid, NULL, NULL, TRUE),
-            '@queue_url' => url('admin/comment/list/approval', NULL, NULL, TRUE),
-            '@view_url' => url('node/'. $node->nid, NULL, 'comment-'. $comment_obj->cid, TRUE),
-            '@admin_url' => url('admin/content/comment', NULL, NULL, TRUE),
-            '@host' => $comment_obj->hostname,
-            '@user' => $comment_obj->name,
-            '@mail' => $comment_obj->mail,
-            '@homepage' => $comment_obj->homepage,
-            '@comment' => $comment_obj->comment,
-            '@subject' => $comment_obj->subject,
-          ));
+          $email = theme('comment_submit_mail', $comment_obj, $recipient);
 
           drupal_mail(
             'commentmail-notify-'. $comment_obj->cid,
-            $recipient,
-            t('[@site] New Comment posted on "@title"', array('@title' => check_plain($node->title), '@site' => variable_get('site_name', 'Drupal'))),
-            $body,
+            $email['recipient'],
+            $email['subject'],
+            $email['body'],
             variable_get('site_mail', NULL)
           );
         }
@@ -246,8 +221,6 @@
   }
 }
 
-
-
 function commentmail_approve($cid) {
   if ($comment = _comment_load($cid)) {
     if ($comment->status == COMMENT_NOT_PUBLISHED) {
@@ -323,3 +296,43 @@
 
   drupal_goto('node/'. $comment->nid);
 }
+
+function theme_comment_submit_mail($comment_obj, $recipient)
+{
+  // Load the node to get the title
+  $node = node_load($comment_obj->nid);
+
+  if ($comment_obj->status == COMMENT_NOT_PUBLISHED) {
+    $text = variable_get('commentmail_mail_approve', t(COMMENTMAIL_DEFAULT_APPROVE));
+  }
+  else {
+    $text = variable_get('commentmail_mail_notify', t(COMMENTMAIL_DEFAULT_NOTIFY));
+  }
+
+  $subject = t('[@site] New Comment posted on "@title"', array('@title' => check_plain($node->title), '@site' => variable_get('site_name', 'Drupal')));
+
+  $body = strtr($text, array(
+    '@site' => variable_get('site_name', 'Drupal'),
+    '@node' => $node->title,
+    '@approval_url' => url('comment/approve/'. $comment_obj->cid, NULL, NULL, TRUE),
+    '@delete_url' => url('comment/delete/'. $comment_obj->cid, NULL, NULL, TRUE),
+    '@ban_url' => url('comment/deleteban/'. $comment_obj->cid, NULL, NULL, TRUE),
+    '@edit_url' => url('comment/edit/'. $comment_obj->cid, NULL, NULL, TRUE),
+    '@queue_url' => url('admin/comment/list/approval', NULL, NULL, TRUE),
+    '@view_url' => url('node/'. $node->nid, NULL, 'comment-'. $comment_obj->cid, TRUE),
+    '@admin_url' => url('admin/content/comment', NULL, NULL, TRUE),
+    '@host' => $comment_obj->hostname,
+    '@user' => $comment_obj->name,
+    '@mail' => $comment_obj->mail,
+    '@homepage' => $comment_obj->homepage,
+    '@comment' => $comment_obj->comment,
+    '@subject' => $comment_obj->subject,
+  ));
+
+  return array(
+    'recipient'      => $recipient,
+    'subject' => $subject,
+    'body'    => $body,
+  );
+}
+
