From b169de8fcde5587f49863ffe99c1f915a9e96ba8 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Sun, 05 Aug 2012 06:41:16 -0400
Subject: [PATCH] - Fix order of attachments in sent mail (#1488423)

---
 program/steps/mail/sendmail.inc |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/program/steps/mail/sendmail.inc b/program/steps/mail/sendmail.inc
index 4790d35..70f1af7 100644
--- a/program/steps/mail/sendmail.inc
+++ b/program/steps/mail/sendmail.inc
@@ -458,6 +458,19 @@
   $message_body .= "\r\n</body></html>\r\n";
 }
 
+// sort attachments to make sure the order is the same as in the UI (#1488423)
+$files = get_input_value('_attachments', RCUBE_INPUT_POST);
+if ($files) {
+  $files = explode(',', $files);
+  $files = array_flip($files);
+  foreach ($files as $idx => $val) {
+    $files[$idx] = $COMPOSE['attachments'][$idx];
+    unset($COMPOSE['attachments'][$idx]);
+  }
+
+  $COMPOSE['attachments'] = array_merge(array_filter($files), $COMPOSE['attachments']);
+}
+
 // set line length for body wrapping
 $LINE_LENGTH = $RCMAIL->config->get('line_length', 72);
 

--
Gitblit v1.9.1