-if (isset($composenew) && $composenew) {
- $comp_uri = '../src/compose.php?mailbox='. urlencode($mailbox).
- "&session=$composesession";
- displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri');", false);
+$aMailbox = sqm_api_mailbox_select($imapConnection,$mailbox,$aConfig,$aMailboxPref);
+
+
+/*
+ * 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) {
+ // 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();
+ sqsession_is_active();
+ $comp_uri = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox).
+ '&session='.$aMailbox['FORWARD_SESSION'];
+ displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri');", false);
+ } else {
+ // save mailboxstate
+ sqsession_register($aMailbox,'aLastSelectedMailbox');
+ session_write_close();
+ // we have to redirect to the compose page
+ $location = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox).
+ '&session='.$aMailbox['FORWARD_SESSION'];
+ header("Location: $location");
+ exit;
+ }