Fixing Mail Importer when using HTML mail templates

Permalink
On one of my C5 sites, I added HTML to the "private message notification" email template by copying /ROOT/concrete/mail/private_message_response_enabled.php to /ROOT/mail/private_message_response_enabled.php and adding:
$bodyHTML .= ' HTML GOES HERE ';

at the bottom. It worked great... until I replied to a private message by email and got back an email from the importer email account saying "Unable to process email. Check that your email contains the validation hash present in the original message."

Apparently the line that Concrete5's Mail Importer adds to outgoing PM notification emails
--- Reply ABOVE. Do not alter this line --- [xyxyxyxyxyxy] ---

is only added to the text version of the email. If you use HTML emails, the line is missing and the Mail Imported can't figure out which PM or Discussion Post you're replying to.

My solution (tested and works) is to create the file /ROOT/helpers/mail.php and add the following code:
<?php
defined('C5_EXECUTE') or die("Access Denied.");
class MailHelper extends Concrete5_Helper_Mail {
   /**
    * @param MailImporter $importer
    * @param array $data
    * @return void
    */
   public function enableMailResponseProcessing($importer, $data) {
      foreach($this->to as $em) {
         $importer->setupValidation($em[0], $data);
      }
      $this->from($importer->getMailImporterEmail());
      $this->body = $importer->setupBody($this->body);
      if($this->bodyHTML!='') $this->bodyHTML = $importer->setupBody('<br /><br />'.$this->bodyHTML);


This basically overrides the enableMailResponseProcessing() function of C5's core MailHelper class and adds the validation hash line at the top of the HTML message.

I thought I'd post this solution in case if helps anyone.

It would be nice if the validation hash could be "hidden" in the HTML message template (perhaps enclosed in <div style="display:none">...</div>) so it wouldn't disturb the top of the nice clean HTML template. But the solution outlined above works.

tomreitz