s/Deliver_SentMail/Deliver_SendMail/
[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');
4d14fc00 23require_once('../functions/global.php');
cb48c245 24
26707265 25// Remove slashes if PHP added them
26if (get_magic_quotes_gpc()) {
27 global $REQUEST_METHOD;
cab99c3a 28
5cc0b70e 29 if ($REQUEST_METHOD == 'POST') {
26707265 30 global $HTTP_POST_VARS;
31 RemoveSlashes($HTTP_POST_VARS);
5cc0b70e 32 } else if ($REQUEST_METHOD == 'GET') {
26707265 33 global $HTTP_GET_VARS;
34 RemoveSlashes($HTTP_GET_VARS);
35 }
36}
37
5c3b0995 38/* Before starting the session, the base URI must be known. Assuming */
39/* that this file is in the src/ subdirectory (or something). */
f3bc099d 40if (!function_exists('sqm_baseuri')){
41 require_once('../functions/display_messages.php');
42}
43$base_uri = sqm_baseuri();
5c3b0995 44
45header('Pragma: no-cache');
46$location = get_location();
47
48session_set_cookie_params (0, $base_uri);
49session_start();
50
51session_unregister ('user_is_logged_in');
52session_register ('base_uri');
53
54if (! isset($squirrelmail_language) ||
55 $squirrelmail_language == '' ) {
56 $squirrelmail_language = $squirrelmail_default_language;
57}
58set_up_language($squirrelmail_language, true);
59/* Refresh the language cookie. */
85b454a0 60setcookie('squirrelmail_language', $squirrelmail_language, time()+2592000,
61 $base_uri);
5c3b0995 62
63if (!isset($login_username)) {
9be8198d 64 include_once( '../functions/display_messages.php' );
65 logout_error( _("You must be logged in to access this page.") );
5c3b0995 66 exit;
67}
68
69if (!session_is_registered('user_is_logged_in')) {
70 do_hook ('login_before');
71
72 $onetimepad = OneTimePadCreate(strlen($secretkey));
73 $key = OneTimePadEncrypt($secretkey, $onetimepad);
74 session_register('onetimepad');
75
76 /* Verify that username and password are correct. */
77 if ($force_username_lowercase) {
78 $login_username = strtolower($login_username);
23d6bd09 79 }
80
5c3b0995 81 $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
82 if (!$imapConnection) {
9be8198d 83 $errTitle = _("There was an error contacting the mail server.");
84 $errString = $errTitle . "<br>\n".
85 _("Contact your administrator for help.");
86 include_once( '../functions/display_messages.php' );
87 logout_error( _("You must be logged in to access this page.") );
5c3b0995 88 exit;
23d6bd09 89 } else {
8e54a58b 90 $sqimap_capabilities = sqimap_capability($imapConnection);
91 session_register('sqimap_capabilities');
5c3b0995 92 $delimiter = sqimap_get_delimiter ($imapConnection);
23d6bd09 93 }
5c3b0995 94 sqimap_logout($imapConnection);
95 session_register('delimiter');
8e54a58b 96 global $username;
5c3b0995 97 $username = $login_username;
98 session_register ('username');
99 setcookie('key', $key, 0, $base_uri);
100 do_hook ('login_verified');
101
102}
103
104/* Set the login variables. */
105$user_is_logged_in = true;
106$just_logged_in = true;
107
108/* And register with them with the session. */
109session_register ('user_is_logged_in');
110session_register ('just_logged_in');
111
112/* parse the accepted content-types of the client */
113$attachment_common_types = array();
114$attachment_common_types_parsed = array();
115session_register('attachment_common_types');
116session_register('attachment_common_types_parsed');
117
118$debug = false;
119if (isset($HTTP_SERVER_VARS['HTTP_ACCEPT']) &&
9be8198d 120 !isset($attachment_common_types_parsed[$HTTP_SERVER_VARS['HTTP_ACCEPT']])) {
5c3b0995 121 attachment_common_parse($HTTP_SERVER_VARS['HTTP_ACCEPT'], $debug);
9be8198d 122}
5c3b0995 123if (isset($HTTP_ACCEPT) &&
9be8198d 124 !isset($attachment_common_types_parsed[$HTTP_ACCEPT])) {
5c3b0995 125 attachment_common_parse($HTTP_ACCEPT, $debug);
9be8198d 126}
5c3b0995 127
128/* Complete autodetection of Javascript. */
165829a3 129$javascript_setting = getPref
130 ($data_dir, $username, 'javascript_setting', SMPREF_JS_AUTODETECT);
131$js_autodetect_results = (isset($js_autodetect_results) ?
132 $js_autodetect_results : SMPREF_JS_OFF);
18f734b9 133/* See if it's set to "Always on" */
134$js_pref = SMPREF_JS_ON;
135if ($javascript_setting != SMPREF_JS_ON){
136 if ($javascript_setting == SMPREF_JS_AUTODETECT) {
137 if ($js_autodetect_results == SMPREF_JS_OFF) {
138 $js_pref = SMPREF_JS_OFF;
139 }
23d6bd09 140 } else {
18f734b9 141 $js_pref = SMPREF_JS_OFF;
23d6bd09 142 }
5c3b0995 143}
18f734b9 144/* Update the prefs */
145setPref($data_dir, $username, 'javascript_on', $js_pref);
5c3b0995 146
177dde45 147global $attachments;
148$attachments = unserialize(getPref($data_dir, $username, 'attachments', 0));
5c3b0995 149/* Compute the URL to forward the user to. */
8e54a58b 150 global $session_expired_location, $session_expired_post;
151 if (isset($session_expired_location) && $session_expired_location) {
152 $compose_new_win = getPref($data_dir, $username, 'compose_new_win', 0);
153 if ($compose_new_win) {
154 $redirect_url = $session_expired_location;
155 } else {
156 $redirect_url = 'webmail.php?right_frame='.urldecode($session_expired_location);
157 }
158 session_unregister('session_expired_location');
159 unset($session_expired_location);
177dde45 160 if (is_array($attachments)) {
161 session_register('attachments');
162 }
8e54a58b 163 } else {
177dde45 164 if (is_array($attachments)) {
165 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
166 foreach ($attachments as $attachment) {
167 $attached_file = $hashed_attachment_dir.'/'.$attachment['localfilename'];
168 if (file_exists($attached_file)) {
169 unlink($attached_file);
170 }
171 }
172 removePref($data_dir, $username, 'attachments');
173 }
8e54a58b 174 $redirect_url = 'webmail.php';
175 }
177dde45 176
5c3b0995 177/* Send them off to the appropriate page. */
178header("Location: $redirect_url");
7baf86a9 179
cab99c3a 180/* --------------------- end main ----------------------- */
181
182function attachment_common_parse($str, $debug) {
183 global $attachment_common_types, $attachment_common_types_parsed;
184
185 $attachment_common_types_parsed[$str] = true;
186 $types = explode(', ', $str);
187
188 foreach ($types as $val) {
189 // Ignore the ";q=1.0" stuff
190 if (strpos($val, ';') !== false)
191 $val = substr($val, 0, strpos($val, ';'));
192
193 if (! isset($attachment_common_types[$val])) {
194 $attachment_common_types[$val] = true;
195 }
196 }
197}
198
199
9be8198d 200?>