From 4315b0086b14cd5266b4cb824c3bd95aa550240c Mon Sep 17 00:00:00 2001
From: svncommit <devs@roundcube.net>
Date: Mon, 10 Dec 2007 23:20:01 -0500
Subject: [PATCH] added ability to insert attached images in HTML editor

---
 program/steps/mail/sendmail.inc |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/program/steps/mail/sendmail.inc b/program/steps/mail/sendmail.inc
index 6f4744d..c2f9ff7 100644
--- a/program/steps/mail/sendmail.inc
+++ b/program/steps/mail/sendmail.inc
@@ -248,8 +248,21 @@
 
 // add stored attachments, if any
 if (is_array($_SESSION['compose']['attachments']))
-  foreach ($_SESSION['compose']['attachments'] as $attachment)
-    $MAIL_MIME->addAttachment($attachment['path'], $attachment['mimetype'], $attachment['name'], true, 'base64', 'attachment', $message_charset);
+  foreach ($_SESSION['compose']['attachments'] as $id => $attachment)
+  {
+    $dispurl = '/\ssrc\s*=\s*[\'"]?\S+display-attachment\S+file=rcmfile' . $id . '[\'"]?/';
+    $match = preg_match($dispurl, $message_body);
+    if ($isHtml && ($match > 0))
+    {
+      $message_body = preg_replace($dispurl, ' src="'.$attachment['name'].'"', $message_body);
+      $MAIL_MIME->setHTMLBody($message_body);
+      $MAIL_MIME->addHTMLImage($attachment['path'], $attachment['mimetype'], $attachment['name']);
+    }
+    else
+    {
+      $MAIL_MIME->addAttachment($attachment['path'], $attachment['mimetype'], $attachment['name'], true, 'base64', 'attachment', $message_charset);
+    }
+  }
 
 // add submitted attachments
 if (is_array($_FILES['_attachments']['tmp_name']))
@@ -381,6 +394,5 @@
   $OUTPUT->command('sent_successfully', rcube_label('messagesent'));
   $OUTPUT->send('iframe');
   }
-
 
 ?>

--
Gitblit v1.9.1