diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php
index 92863db2fd331d0b5cbb5b239e6b9a8555ea219d..55020e192d99bdaa255917b6bdfde1d2f1cb402d 100644
--- a/include/class.dynamic_forms.php
+++ b/include/class.dynamic_forms.php
@@ -567,6 +567,10 @@ class DynamicFormEntryAnswer extends VerySimpleModel {
         return $this->getField()->toString($this->getValue());
     }
 
+    function asVar() {
+        return $this->toString();
+    }
+
     function __toString() {
         return $this->toString();
     }
diff --git a/include/class.format.php b/include/class.format.php
index 251b1b1f96045de0a38cae3fd79240e517b50f4d..7b80dc97bff94aba13eda8ccb6eb590b94afad2d 100644
--- a/include/class.format.php
+++ b/include/class.format.php
@@ -142,10 +142,12 @@ class Format {
                 'safe' => 1, //Exclude applet, embed, iframe, object and script tags.
                 'balance' => 1, //balance and close unclosed tags.
                 'comment' => 1, //Remove html comments (OUTLOOK LOVE THEM)
-                'tidy' => -1, // Clean extra whitspace
                 'schemes' => 'href: aim, feed, file, ftp, gopher, http, https, irc, mailto, news, nntp, sftp, ssh, telnet; *:file, http, https; src: cid, http, https, data'
                 );
 
+        if (!preg_match('/style="[^"]*white-space:\s*pre/i', $html) !== false)
+            $config['tidy'] = -1; // Clean extra whitspace
+
         return Format::html($html, $config);
     }
 
@@ -241,7 +243,7 @@ class Format {
 
         $token = $ost->getLinkToken();
         //Not perfect but it works - please help improve it.
-        $text=preg_replace_callback('/(?<!")(((f|ht){1}tp(s?):\/\/)[-a-zA-Z0-9@:%_\+.~#?&;\/\/=]+)/',
+        $text=preg_replace_callback('/(?<!"|>)(((f|ht)tp(s?):\/\/)[-a-zA-Z0-9@:%_\+.~#?&;\/\/=]+)/',
                 create_function('$matches', # nolint
                     sprintf('return "<a href=\"l.php?url=".urlencode($matches[1])."&auth=%s\" target=\"_blank\">".$matches[1]."</a>";', # nolint
                         $token)),
diff --git a/include/class.mailfetch.php b/include/class.mailfetch.php
index 07a3aa27fc46db8fe6644f7926f29c11822404cf..283c1aee4d7adb591178f30668989caa37bd730e 100644
--- a/include/class.mailfetch.php
+++ b/include/class.mailfetch.php
@@ -504,7 +504,8 @@ class MailFetcher {
             }
         }
 
-        if (($thread = ThreadEntry::lookupByEmailHeaders($vars))
+        $seen = false;
+        if (($thread = ThreadEntry::lookupByEmailHeaders($vars, $seen))
                 && ($message = $thread->postEmail($vars))) {
             if (!$message instanceof ThreadEntry)
                 // Email has been processed previously
diff --git a/include/class.thread.php b/include/class.thread.php
index e1840c78728250c7eef98fdf7bfaf07710599ccf..eca16c58e595f57d597c4535658e36fb13e8e163 100644
--- a/include/class.thread.php
+++ b/include/class.thread.php
@@ -426,7 +426,14 @@ Class ThreadEntry {
         if(!($fileId=is_numeric($file)?$file:AttachmentFile::save($file)))
             return 0;
 
-        $sql ='INSERT INTO '.TICKET_ATTACHMENT_TABLE.' SET created=NOW() '
+        // TODO: Add a unique index to TICKET_ATTACHMENT_TABLE (file_id,
+        // ticket_id), and remove this block
+        if ($id = db_result(db_query('SELECT attach_id FROM '.TICKET_ATTACHMENT_TABLE
+                .' WHERE file_id='.db_input($fileId).' AND ticket_id='
+                .db_input($this->getTicketId()))))
+            return $id;
+
+        $sql ='INSERT IGNORE INTO '.TICKET_ATTACHMENT_TABLE.' SET created=NOW() '
              .' ,file_id='.db_input($fileId)
              .' ,ticket_id='.db_input($this->getTicketId())
              .' ,ref_id='.db_input($this->getId())
diff --git a/include/class.ticket.php b/include/class.ticket.php
index 596254830eb8b4536bcee86df05d25d975643897..3a5a639496169d08da85c7f7a0e409a83d47a919 100644
--- a/include/class.ticket.php
+++ b/include/class.ticket.php
@@ -221,7 +221,7 @@ class Ticket {
     }
 
     function getSubject() {
-        return $this->_answers['subject'];
+        return (string) $this->_answers['subject'];
     }
 
     /* Help topic title  - NOT object -> $topic */
@@ -774,7 +774,7 @@ class Ticket {
                     );
 
             if($cfg->stripQuotedReply() && ($tag=$cfg->getReplySeparator()))
-                $msg['body'] ="\n$tag\n\n".$msg['body'];
+                $msg['body'] = "<p style=\"display:none\">$tag<p>".$msg['body'];
 
             $email->sendAutoReply($this->getEmail(), $msg['subj'], $msg['body'],
                 null, $options);
@@ -906,7 +906,7 @@ class Ticket {
 
             //Reply separator tag.
             if($cfg->stripQuotedReply() && ($tag=$cfg->getReplySeparator()))
-                $msg['body'] ="\n$tag\n\n".$msg['body'];
+                $msg['body'] = "<p style=\"display:none\">$tag<p>".$msg['body'];
 
             if (!$message)
                 $message = $this->getLastMessage();
@@ -1098,7 +1098,7 @@ class Ticket {
                     // The answer object is retrieved here which will
                     // automatically invoke the toString() method when the
                     // answer is coerced into text
-                    return $this->_answers[$tag];
+                    return (string)$this->_answers[$tag];
         }
 
         return false;
@@ -1434,7 +1434,7 @@ class Ticket {
                 array('response' => $response, 'signature' => $signature));
 
             if($cfg->stripQuotedReply() && ($tag=$cfg->getReplySeparator()))
-                $msg['body'] ="\n$tag\n\n".$msg['body'];
+                $msg['body'] = "<p style=\"display:none\">$tag<p>".$msg['body'];
 
             $options = array('references' => $response->getEmailMessageId());
             $email->sendAutoReply($this->getEmail(), $msg['subj'], $msg['body'], $attachments,
@@ -1492,7 +1492,7 @@ class Ticket {
                     array('response' => $response, 'signature' => $signature, 'staff' => $thisstaff));
 
             if($cfg->stripQuotedReply() && ($tag=$cfg->getReplySeparator()))
-                $msg['body'] ="\n$tag\n\n".$msg['body'];
+                $msg['body'] = "<p style=\"display:none\">$tag<p>".$msg['body'];
 
             $options = array('references' => $response->getEmailMessageId());
             //TODO: setup  5 param (options... e.g mid trackable on replies)
@@ -2049,6 +2049,7 @@ class Ticket {
         // Save the (common) dynamic form
         $form->setTicketId($id);
         $form->save();
+        $ticket->loadDynamicData();
 
         $dept = $ticket->getDept();
 
@@ -2179,7 +2180,7 @@ class Ticket {
                     array('message' => $message, 'signature' => $signature));
 
             if($cfg->stripQuotedReply() && ($tag=trim($cfg->getReplySeparator())))
-                $msg['body'] ="\n$tag\n\n".$msg['body'];
+                $msg['body'] = "<p style=\"display:none\">$tag<p>".$msg['body'];
 
             $references = $ticket->getLastMessage()->getEmailMessageId();
             if (isset($response))
diff --git a/include/html2text.php b/include/html2text.php
index 944c62f19b2472bed206b8bfeed6b3e8219d241e..ba1e1389d9d4243b8c19a00be57c31b570c9b73e 100644
--- a/include/html2text.php
+++ b/include/html2text.php
@@ -361,7 +361,8 @@ class HtmlHeadlineElement extends HtmlBlockElement {
             default:
                 return $headline;
         }
-        $headline .= "\n" . str_repeat($line, strpos($headline, "\n", 1) - 1) . "\n";
+        $length = max(array_map('strlen', explode("\n", $headline)));
+        $headline .= "\n" . str_repeat($line, $length) . "\n";
         return $headline;
     }
 }
diff --git a/include/i18n/en_US/templates/email/ticket.alert.yaml b/include/i18n/en_US/templates/email/ticket.alert.yaml
index 97e2a5dfbe904ebb1171cf6ac9932823894dcbfc..46f1aac5616d454ba233910c1568648efc06a68d 100644
--- a/include/i18n/en_US/templates/email/ticket.alert.yaml
+++ b/include/i18n/en_US/templates/email/ticket.alert.yaml
@@ -48,6 +48,7 @@ body: |
     <p>
         <em>Your friendly Customer Support System
         <br/>
-        <a href="http://osticket.com/"><img width="126" height="23"
-            alt="Powered By osTicket" src="cid:b56944cb4722cc5cda9d1e23a3ea7fbc"/></a>
+        <a href="http://osticket.com/"><img width="126" height="19"
+            style="width: 126px; " alt="Powered By osTicket"
+            src="cid:b56944cb4722cc5cda9d1e23a3ea7fbc"/></a>
     </p>
diff --git a/include/i18n/en_US/templates/email/ticket.overdue.yaml b/include/i18n/en_US/templates/email/ticket.overdue.yaml
index 7a1b07a5e934b4170735b1e4a59ab37975c452b2..0af97373f90ea919eb9e6dab0d0dcc61c29f95a4 100644
--- a/include/i18n/en_US/templates/email/ticket.overdue.yaml
+++ b/include/i18n/en_US/templates/email/ticket.overdue.yaml
@@ -42,6 +42,6 @@ body: |
         to a team or department of which you're a member.</span>
     </p>
     <p>
-        <img src="cid:b56944cb4722cc5cda9d1e23a3ea7fbc"
-        alt="Powered by osTicket" width="146" height="0" style="width: 146px;">
+        <img src="cid:b56944cb4722cc5cda9d1e23a3ea7fbc" height="19"
+            alt="Powered by osTicket" width="126" style="width: 146px;">
     </p>
diff --git a/include/i18n/en_US/templates/email/ticket.reply.yaml b/include/i18n/en_US/templates/email/ticket.reply.yaml
index a73a75ff0ba6a64e84886e952950ed95b5f9756f..50278d6221eac6cfb611030ebe185b6f21352ea6 100644
--- a/include/i18n/en_US/templates/email/ticket.reply.yaml
+++ b/include/i18n/en_US/templates/email/ticket.reply.yaml
@@ -36,5 +36,5 @@ body: |
     </p>
     <p style="text-align: center;">
         <img src="cid:b56944cb4722cc5cda9d1e23a3ea7fbc" alt="Powered by osTicket"
-        width="133" height="20" style="width: 133px;">
+        width="126" height="19" style="width: 133px;">
     </p>