From 21ed28ebde5e7f9ec2f0d5435c7733daa0695c65 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Thu, 6 Mar 2014 09:26:13 -0600
Subject: [PATCH] mailer: Pick content_ids that Mail_Mime will enjoy

---
 include/class.mailer.php | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/include/class.mailer.php b/include/class.mailer.php
index 7e305f7b6..92b612781 100644
--- a/include/class.mailer.php
+++ b/include/class.mailer.php
@@ -161,10 +161,14 @@ class Mailer {
             $isHtml = false;
         }
 
-        $domain = 'local';
         if ($isHtml && $cfg && $cfg->isHtmlThreadEnabled()) {
-            // TODO: Lookup helpdesk domain
-            $domain = substr(md5($ost->getConfig()->getURL()), -12);
+            // Pick a domain compatible with pear Mail_Mime
+            $matches = array();
+            if (preg_match('#(@[0-9a-zA-Z\-\.]+)#', $this->getFromAddress(), $matches)) {
+                $domain = $matches[1];
+            } else {
+                $domain = '@localhost';
+            }
             // Format content-ids with the domain, and add the inline images
             // to the email attachment list
             $self = $this;
@@ -174,10 +178,10 @@ class Mailer {
                         return $match[0];
                     $mime->addHTMLImage($file->getData(),
                         $file->getType(), $file->getName(), false,
-                        $file->getHash().'@'.$domain);
+                        $match[1].$domain);
                     // Don't re-attach the image below
                     unset($self->attachments[$file->getId()]);
-                    return $match[0].'@'.$domain;
+                    return $match[0].$domain;
                 }, $message);
             // Add an HTML body
             $mime->setHTMLBody($message);
-- 
GitLab