support for picking up attachments in case of a expired session
[squirrelmail.git] / src / redirect.php
CommitLineData
7392739d 1<?php
895905c0 2
35586184 3/**
cab99c3a 4* redirect.php
5* Derived from webmail.php by Ralf Kraudelt <kraude@wiwi.uni-rostock.de>
6*
7* Copyright (c) 1999-2002 The SquirrelMail Project Team
8* Licensed under the GNU GPL. For full terms see the file COPYING.
9*
10* Prevents users from reposting their form data after a successful logout.
11*
12* $Id$
13*/
35586184 14
15require_once('../functions/i18n.php');
16require_once('../functions/strings.php');
17require_once('../config/config.php');
18require_once('../functions/prefs.php');
19require_once('../functions/imap.php');
20require_once('../functions/plugin.php');
21require_once('../functions/constants.php');
5a545dda 22require_once('../functions/page_header.php');
cb48c245 23
26707265 24// Remove slashes if PHP added them
25if (get_magic_quotes_gpc()) {
26 global $REQUEST_METHOD;
cab99c3a 27
5cc0b70e 28 if ($REQUEST_METHOD == 'POST') {
26707265 29 global $HTTP_POST_VARS;
30 RemoveSlashes($HTTP_POST_VARS);
5cc0b70e 31 } else if ($REQUEST_METHOD == 'GET') {
26707265 32 global $HTTP_GET_VARS;
33 RemoveSlashes($HTTP_GET_VARS);
34 }
35}
36
5c3b0995 37/* Before starting the session, the base URI must be known. Assuming */
38/* that this file is in the src/ subdirectory (or something). */
f3bc099d 39if (!function_exists('sqm_baseuri')){
40 require_once('../functions/display_messages.php');
41}
42$base_uri = sqm_baseuri();
5c3b0995 43
44header('Pragma: no-cache');
45$location = get_location();
46
47session_set_cookie_params (0, $base_uri);
48session_start();
49
50session_unregister ('user_is_logged_in');
51session_register ('base_uri');
52
53if (! isset($squirrelmail_language) ||
54 $squirrelmail_language == '' ) {
55 $squirrelmail_language = $squirrelmail_default_language;
56}
57set_up_language($squirrelmail_language, true);
58/* Refresh the language cookie. */
85b454a0 59setcookie('squirrelmail_language', $squirrelmail_language, time()+2592000,
60 $base_uri);
5c3b0995 61
62if (!isset($login_username)) {
9be8198d 63 include_once( '../functions/display_messages.php' );
64 logout_error( _("You must be logged in to access this page.") );
5c3b0995 65 exit;
66}
67
68if (!session_is_registered('user_is_logged_in')) {
69 do_hook ('login_before');
70
71 $onetimepad = OneTimePadCreate(strlen($secretkey));
72 $key = OneTimePadEncrypt($secretkey, $onetimepad);
73 session_register('onetimepad');
74
75 /* Verify that username and password are correct. */
76 if ($force_username_lowercase) {
77 $login_username = strtolower($login_username);
23d6bd09 78 }
79
5c3b0995 80 $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
81 if (!$imapConnection) {
9be8198d 82 $errTitle = _("There was an error contacting the mail server.");
83 $errString = $errTitle . "<br>\n".
84 _("Contact your administrator for help.");
85 include_once( '../functions/display_messages.php' );
86 logout_error( _("You must be logged in to access this page.") );
5c3b0995 87 exit;
23d6bd09 88 } else {
8e54a58b 89 $sqimap_capabilities = sqimap_capability($imapConnection);
90 session_register('sqimap_capabilities');
5c3b0995 91 $delimiter = sqimap_get_delimiter ($imapConnection);
23d6bd09 92 }
5c3b0995 93 sqimap_logout($imapConnection);
94 session_register('delimiter');
8e54a58b 95 global $username;
5c3b0995 96 $username = $login_username;
97 session_register ('username');
98 setcookie('key', $key, 0, $base_uri);
99 do_hook ('login_verified');
100
101}
102
103/* Set the login variables. */
104$user_is_logged_in = true;
105$just_logged_in = true;
106
107/* And register with them with the session. */
108session_register ('user_is_logged_in');
109session_register ('just_logged_in');
110
111/* parse the accepted content-types of the client */
112$attachment_common_types = array();
113$attachment_common_types_parsed = array();
114session_register('attachment_common_types');
115session_register('attachment_common_types_parsed');
116
117$debug = false;
118if (isset($HTTP_SERVER_VARS['HTTP_ACCEPT']) &&
9be8198d 119 !isset($attachment_common_types_parsed[$HTTP_SERVER_VARS['HTTP_ACCEPT']])) {
5c3b0995 120 attachment_common_parse($HTTP_SERVER_VARS['HTTP_ACCEPT'], $debug);
9be8198d 121}
5c3b0995 122if (isset($HTTP_ACCEPT) &&
9be8198d 123 !isset($attachment_common_types_parsed[$HTTP_ACCEPT])) {
5c3b0995 124 attachment_common_parse($HTTP_ACCEPT, $debug);
9be8198d 125}
5c3b0995 126
127/* Complete autodetection of Javascript. */
165829a3 128$javascript_setting = getPref
129 ($data_dir, $username, 'javascript_setting', SMPREF_JS_AUTODETECT);
130$js_autodetect_results = (isset($js_autodetect_results) ?
131 $js_autodetect_results : SMPREF_JS_OFF);
18f734b9 132/* See if it's set to "Always on" */
133$js_pref = SMPREF_JS_ON;
134if ($javascript_setting != SMPREF_JS_ON){
135 if ($javascript_setting == SMPREF_JS_AUTODETECT) {
136 if ($js_autodetect_results == SMPREF_JS_OFF) {
137 $js_pref = SMPREF_JS_OFF;
138 }
23d6bd09 139 } else {
18f734b9 140 $js_pref = SMPREF_JS_OFF;
23d6bd09 141 }
5c3b0995 142}
18f734b9 143/* Update the prefs */
144setPref($data_dir, $username, 'javascript_on', $js_pref);
5c3b0995 145
146/* Compute the URL to forward the user to. */
147if(isset($rcptemail)) {
148 $redirect_url = 'webmail.php?right_frame=compose.php&rcptaddress=';
594d29a1 149 $redirect_url .= $rcptemail;
5c3b0995 150} else {
8e54a58b 151 global $session_expired_location, $session_expired_post;
152 if (isset($session_expired_location) && $session_expired_location) {
153 $compose_new_win = getPref($data_dir, $username, 'compose_new_win', 0);
154 if ($compose_new_win) {
155 $redirect_url = $session_expired_location;
156 } else {
157 $redirect_url = 'webmail.php?right_frame='.urldecode($session_expired_location);
158 }
159 session_unregister('session_expired_location');
160 unset($session_expired_location);
161 } else {
162 $redirect_url = 'webmail.php';
163 }
5c3b0995 164}
5c3b0995 165/* Send them off to the appropriate page. */
166header("Location: $redirect_url");
7baf86a9 167
cab99c3a 168/* --------------------- end main ----------------------- */
169
170function attachment_common_parse($str, $debug) {
171 global $attachment_common_types, $attachment_common_types_parsed;
172
173 $attachment_common_types_parsed[$str] = true;
174 $types = explode(', ', $str);
175
176 foreach ($types as $val) {
177 // Ignore the ";q=1.0" stuff
178 if (strpos($val, ';') !== false)
179 $val = substr($val, 0, strpos($val, ';'));
180
181 if (! isset($attachment_common_types[$val])) {
182 $attachment_common_types[$val] = true;
183 }
184 }
185}
186
187
9be8198d 188?>