From 37b9e026486a5e487bcc1fc502b71ad817c32427 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Mon, 17 Feb 2014 11:40:07 -0500
Subject: [PATCH] Fix regression in handling of 'attachments' result in message_compose hook (#1489627)

---
 CHANGELOG                      |    1 
 program/steps/mail/compose.inc |   60 +++++++++++++++---------------
 2 files changed, 31 insertions(+), 30 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 3dc197e..3ea41ed 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -8,6 +8,7 @@
 - Fix Opera > 15 detection (#1489562)
 - Fix security issue in DomainFactory driver of Password plugin
 - Fix invalid X-Draft-Info on forwarded message draft (#1489587)
+- Fix regression in handling of 'attachments' result in message_compose hook (#1489627)
 
 RELEASE 1.0-rc
 --------------
diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc
index 8504d02..c76da14 100644
--- a/program/steps/mail/compose.inc
+++ b/program/steps/mail/compose.inc
@@ -62,36 +62,6 @@
 
     rcmail_process_compose_params($COMPOSE);
 
-    // add attachments listed by message_compose hook
-    if (is_array($plugin['attachments'])) {
-        foreach ($plugin['attachments'] as $attach) {
-            // we have structured data
-            if (is_array($attach)) {
-                $attachment = $attach;
-            }
-            // only a file path is given
-            else {
-                $filename   = basename($attach);
-                $attachment = array(
-                    'group'    => $COMPOSE_ID,
-                    'name'     => $filename,
-                    'mimetype' => rcube_mime::file_content_type($attach, $filename),
-                    'path'     => $attach,
-                );
-            }
-
-            // save attachment if valid
-            if (($attachment['data'] && $attachment['name']) || ($attachment['path'] && file_exists($attachment['path']))) {
-                $attachment = rcmail::get_instance()->plugins->exec_hook('attachment_save', $attachment);
-            }
-
-            if ($attachment['status'] && !$attachment['abort']) {
-                unset($attachment['data'], $attachment['status'], $attachment['abort']);
-                $COMPOSE['attachments'][$attachment['id']] = $attachment;
-            }
-        }
-    }
-
     // check if folder for saving sent messages exists and is subscribed (#1486802)
     if ($sent_folder = $COMPOSE['param']['sent_mbox']) {
         rcmail_check_sent_folder($sent_folder, true);
@@ -498,6 +468,36 @@
     // pipe compose parameters thru plugins
     $plugin = $RCMAIL->plugins->exec_hook('message_compose', $COMPOSE);
     $COMPOSE['param'] = array_merge($COMPOSE['param'], $plugin['param']);
+
+    // add attachments listed by message_compose hook
+    if (is_array($plugin['attachments'])) {
+        foreach ($plugin['attachments'] as $attach) {
+            // we have structured data
+            if (is_array($attach)) {
+                $attachment = $attach;
+            }
+            // only a file path is given
+            else {
+                $filename   = basename($attach);
+                $attachment = array(
+                    'group'    => $COMPOSE_ID,
+                    'name'     => $filename,
+                    'mimetype' => rcube_mime::file_content_type($attach, $filename),
+                    'path'     => $attach,
+                );
+            }
+
+            // save attachment if valid
+            if (($attachment['data'] && $attachment['name']) || ($attachment['path'] && file_exists($attachment['path']))) {
+                $attachment = rcmail::get_instance()->plugins->exec_hook('attachment_save', $attachment);
+            }
+
+            if ($attachment['status'] && !$attachment['abort']) {
+                unset($attachment['data'], $attachment['status'], $attachment['abort']);
+                $COMPOSE['attachments'][$attachment['id']] = $attachment;
+            }
+        }
+    }
 }
 
 function rcmail_compose_headers($attrib)

--
Gitblit v1.9.1