-$aLastSelectedMailbox['NAME'] = $mailbox;
-$aLastSelectedMailbox['EXISTS'] = $aMbxResponse['EXISTS'];
-$aLastSelectedMailbox['UIDVALIDITY'] = $aMbxResponse['UIDVALIDITY'];
-$aLastSelectedMailbox['UIDNEXT'] = $aMbxResponse['UIDNEXT'];
-$aLastSelectedMailbox['PERMANENTFLAGS'] = $aMbxResponse['PERMANENTFLAGS'];
-$aLastSelectedMailbox['OFFSET'] = (isset($startMessage) && $startMessage) ? $startMessage -1 : 0;
-$aLastSelectedMailbox['PAGEOFFSET'] = (isset($startMessage) && $startMessage) ? $startMessage : 1;
-$aLastSelectedMailbox['SORT'] = ($sort !== false) ? $sort : 0;
-$aLastSelectedMailbox['LIMIT'] = $show_num;
-
-$aLastSelectedMailbox['UIDSET'] = $aMbxResponse['SORT_ARRAY'];
-$aLastSelectedMailbox['SEEN'] = (isset($aMbxResponse['SEEN'])) ? $aMbxResponse['SEEN'] : $aMbxResponse['EXISTS'];
-$aLastSelectedMailbox['RECENT'] = (isset($aMbxResponse['RECENT'])) ? $aMbxResponse['RECENT'] : 0;
-
-$aLastSelectedMailbox['AUTO_EXPUNGE'] = $auto_expunge;
-
-/* decide if we are thread sorting or not */
-$aLastSelectedMailbox['ALLOW_THREAD'] = $allow_thread_sort;
-if ($allow_thread_sort == TRUE) {
- if (isset($set_thread)) {
- $aLastSelectedMailbox['SORT_ARRAY'] = false;
- if (sqsession_is_registered('indent_array')) {
- sqsession_unregister('indent_array');
- }
- if (sqsession_is_registered('server_sort_array')) {
- sqsession_unregister('server_sort_array');
+/*
+ * After initialisation of the mailbox array it's time to handle the FORM data
+ */
+$sError = handleMessageListForm($imapConnection,$aMailbox);
+if ($sError) {
+ $note = $sError;
+}
+
+
+
+/*
+ * If we try to forward messages as attachment we have to open a new window
+ * in case of compose in new window or redirect to compose.php
+ */
+if (isset($aMailbox['FORWARD_SESSION'])) {
+ if ($compose_new_win) {
+ /* add the mailbox to the cache */
+ $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
+ sqsession_register($mailbox_cache,'mailbox_cache');
+ // write the session in order to make sure that the compose window has
+ // access to the composemessages array which is stored in the session
+ session_write_close();
+ // restart the session. Do not use sqsession_is_active because the session_id
+ // isn't empty after a session_write_close
+ sqsession_start();
+ if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
+ $compose_width = '640';