Fix for #1093360.
[squirrelmail.git] / src / compose.php
index c2ed4e2254a47dc927ce1412610b63d5b345b584..1678bfd73d588225a7c5fdaf9eeb8eaa1a9b70ad 100644 (file)
@@ -48,6 +48,11 @@ sqgetGlobalVar('delimiter', $delimiter,     SQ_SESSION);
 
 sqgetGlobalVar('composesession',    $composesession,    SQ_SESSION);
 sqgetGlobalVar('compose_messages',  $compose_messages,  SQ_SESSION);
+sqgetGlobalVar('delayed_errors',  $delayed_errors,  SQ_SESSION);
+if (is_array($delayed_errors)) {
+    $oErrorHandler->AssignDelayedErrors($delayed_errors);
+    sqsession_unregister("delayed_errors");
+}
 
 /** SESSION/POST/GET VARS */
 sqgetGlobalVar('session',$session);
@@ -386,6 +391,9 @@ if ($draft) {
             }
             sqimap_logout($imap_stream);
         }
+        if (count($oErrorHandler->aErrors)) {
+            sqsession_register($oErrorHandler->aErrors,"delayed_errors");
+        }
         session_write_close();
         if ($compose_new_win == '1') {
             if ( !isset($pageheader_sent) || !$pageheader_sent ) {
@@ -461,6 +469,7 @@ if ($send) {
         $composeMessage=$compose_messages[$session];
 
         $Result = deliverMessage($composeMessage);
+
         do_hook('compose_send_after', $Result, $composeMessage);
         if (! $Result) {
             showInputForm($session);
@@ -481,6 +490,12 @@ if ($send) {
             }
             sqimap_logout($imap_stream);
         }
+        /*
+         * Store the error array in the session because they will be lost on a redirect
+         */
+        if (count($oErrorHandler->aErrors)) {
+            sqsession_register($oErrorHandler->aErrors,"delayed_errors");
+        }
         session_write_close();
         if ($compose_new_win == '1') {
             if ( !isset($pageheader_sent) || !$pageheader_sent ) {
@@ -1695,15 +1710,17 @@ function deliverMessage($composeMessage, $draft=false) {
         $composeMessage->purgeAttachments();
         if ($action == 'reply' || $action == 'reply_all') {
             $aMailbox = sqm_api_mailbox_select($imap_stream, $iAccount, $mailbox,array('setindex' => $what, 'offset' => $startMessage),array());
-            //sqimap_mailbox_select ($imap_stream, $mailbox);
-            $aUpdatedMsgs = sqimap_toggle_flag($imap_stream, array($passed_id), '\\Answered', true, false);
-             if (isset($aUpdatedMsgs[$passed_id]['FLAGS'])) {
-                /**
-                 * Only update the cached headers if the header is
-                 * cached.
-                 */
-                if (isset($aMailbox['MSG_HEADERS'][$passed_id])) {
-                    $aMailbox['MSG_HEADERS'][$passed_id]['FLAGS'] = $aMsg['FLAGS'];
+            // check if we are allowed to set the \\Answered flag
+            if (in_array('\\answered',$aMailbox['PERMANENTFLAGS'], true)) {
+                $aUpdatedMsgs = sqimap_toggle_flag($imap_stream, array($passed_id), '\\Answered', true, false);
+                if (isset($aUpdatedMsgs[$passed_id]['FLAGS'])) {
+                    /**
+                     * Only update the cached headers if the header is
+                     * cached.
+                     */
+                    if (isset($aMailbox['MSG_HEADERS'][$passed_id])) {
+                        $aMailbox['MSG_HEADERS'][$passed_id]['FLAGS'] = $aMsg['FLAGS'];
+                    }
                 }
             }
             /**