SM_PATH already defined
[squirrelmail.git] / src / redirect.php
index eb23e0bfe9ee5ad005597ebf1c16b0cb2c00a491..c570974339cc64f775ab5273f7ff92268fbf3da3 100644 (file)
@@ -27,15 +27,12 @@ require_once(SM_PATH . 'functions/page_header.php');
 require_once(SM_PATH . 'functions/global.php');
 
 // Remove slashes if PHP added them
+$REQUEST_METHOD = $_SERVER['REQUEST_METHOD'];
 if (get_magic_quotes_gpc()) {
-    global $REQUEST_METHOD;
-
     if ($REQUEST_METHOD == 'POST') {
-        global $HTTP_POST_VARS;
-        RemoveSlashes($HTTP_POST_VARS);
+        RemoveSlashes($_POST);
     } else if ($REQUEST_METHOD == 'GET') {
-        global $HTTP_GET_VARS;
-        RemoveSlashes($HTTP_GET_VARS);
+        RemoveSlashes($_GET);
     }
 }
 
@@ -52,13 +49,28 @@ $location = get_location();
 session_set_cookie_params (0, $base_uri);
 session_start();
 
-session_unregister ('user_is_logged_in');
-session_register ('base_uri');
+sqsession_unregister ('user_is_logged_in');
+sqsession_register ($base_uri, 'base_uri');
 
-if (! isset($squirrelmail_language) ||
+/* get globals we me need */
+if (isset($_POST['login_username'])) {
+    $login_username = $_POST['login_username'];
+}
+if (!isset($_COOKIE['squirrelmail_language']) ||
     $squirrelmail_language == '' ) {
     $squirrelmail_language = $squirrelmail_default_language;
 }
+else {
+    $squirrelmail_language = $_COOKIE['squirrelmail_language'];
+}
+if (isset($_POST['secretkey'])) {
+    $secretkey = $_POST['secretkey'];
+}
+if (isset($_POST['js_autodetect_results'])) {
+    $js_autodetect_results = $_POST['js_autodetect_results'];
+}
+/* end of get globals */
+
 set_up_language($squirrelmail_language, true);
 /* Refresh the language cookie. */
 setcookie('squirrelmail_language', $squirrelmail_language, time()+2592000, 
@@ -70,12 +82,12 @@ if (!isset($login_username)) {
     exit;
 }
 
-if (!session_is_registered('user_is_logged_in')) {
+if (!sqsession_is_registered('user_is_logged_in')) {
     do_hook ('login_before');
 
     $onetimepad = OneTimePadCreate(strlen($secretkey));
     $key = OneTimePadEncrypt($secretkey, $onetimepad);
-    session_register('onetimepad');
+    sqsession_register($onetimepad, 'onetimepad');
 
     /* remove redundant spaces */
     $login_username = trim($login_username);
@@ -95,14 +107,14 @@ if (!session_is_registered('user_is_logged_in')) {
         exit;
     } else {
         $sqimap_capabilities = sqimap_capability($imapConnection);
-       session_register('sqimap_capabilities');
+       sqsession_register($sqimap_capabilities, 'sqimap_capabilities');
         $delimiter = sqimap_get_delimiter ($imapConnection);
     }
     sqimap_logout($imapConnection);
-    session_register('delimiter');
-    global $username;    
+    sqsession_register($delimiter, 'delimiter');
+
     $username = $login_username;
-    session_register ('username');
+    sqsession_register ($username, 'username');
     setcookie('key', $key, 0, $base_uri);
     do_hook ('login_verified');
 
@@ -113,23 +125,24 @@ $user_is_logged_in = true;
 $just_logged_in = true;
 
 /* And register with them with the session. */
-session_register ('user_is_logged_in');
-session_register ('just_logged_in');
+sqsession_register ($user_is_logged_in, 'user_is_logged_in');
+sqsession_register ($just_logged_in, 'just_logged_in');
 
 /* parse the accepted content-types of the client */
 $attachment_common_types = array();
 $attachment_common_types_parsed = array();
-session_register('attachment_common_types');
-session_register('attachment_common_types_parsed');
+sqsession_register($attachment_common_types, 'attachment_common_types');
+sqsession_register($attachment_common_types_parsed, 'attachment_common_types_parsed');
 
 $debug = false;
-if (isset($HTTP_SERVER_VARS['HTTP_ACCEPT']) &&
-    !isset($attachment_common_types_parsed[$HTTP_SERVER_VARS['HTTP_ACCEPT']])) {
-    attachment_common_parse($HTTP_SERVER_VARS['HTTP_ACCEPT'], $debug);
+
+if (isset($_SERVER['HTTP_ACCEPT']) &&
+    !isset($attachment_common_types_parsed[$_SERVER['HTTP_ACCEPT']])) {
+    attachment_common_parse($_SERVER['HTTP_ACCEPT'], $debug);
 }
-if (isset($HTTP_ACCEPT) &&
-    !isset($attachment_common_types_parsed[$HTTP_ACCEPT])) {
-    attachment_common_parse($HTTP_ACCEPT, $debug);
+if (isset($_SERVER['HTTP_ACCEPT']) &&
+    !isset($attachment_common_types_parsed[$_SERVER['HTTP_ACCEPT']])) {
+    attachment_common_parse($_SERVER['HTTP_ACCEPT'], $debug);
 }
 
 /* Complete autodetection of Javascript. */
@@ -151,10 +164,12 @@ if ($javascript_setting != SMPREF_JS_ON){
 /* Update the prefs */
 setPref($data_dir, $username, 'javascript_on', $js_pref);
 
-global $attachments;
-$attachments = unserialize(getPref($data_dir, $username, 'attachments', 0));
 /* Compute the URL to forward the user to. */
-    global $session_expired_location, $session_expired_post;
+    if (isset($_SESSION['session_expired_location'])) {
+       $session_expired_location= $_SESSION['session_expired_location'];
+    } else {
+       $session_expired_location=false;
+    }
     if (isset($session_expired_location) && $session_expired_location) {
        $compose_new_win = getPref($data_dir, $username, 'compose_new_win', 0);
        if ($compose_new_win) {
@@ -162,26 +177,14 @@ $attachments = unserialize(getPref($data_dir, $username, 'attachments', 0));
        } else {
           $redirect_url = 'webmail.php?right_frame='.urldecode($session_expired_location);
        }
-       session_unregister('session_expired_location');
+       sqsession_unregister('session_expired_location');
        unset($session_expired_location);
-       if (is_array($attachments)) {
-          session_register('attachments');
-       }
     } else {
-       if (is_array($attachments)) {
-          $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
-          foreach ($attachments as $attachment) {
-            $attached_file = $hashed_attachment_dir.'/'.$attachment['localfilename'];
-            if (file_exists($attached_file)) {
-                unlink($attached_file);
-            }
-          }
-          removePref($data_dir, $username, 'attachments');
-       }
        $redirect_url = 'webmail.php';
     }
 
-/* Send them off to the appropriate page. */
+/* Write session data and send them off to the appropriate page. */
+session_write_close();
 header("Location: $redirect_url");
 
 /* --------------------- end main ----------------------- */
@@ -201,6 +204,7 @@ function attachment_common_parse($str, $debug) {
             $attachment_common_types[$val] = true;
         }
     }
+    $_SESSION['attachment_common_types'] = $attachment_common_types;
 }