93d61fc6968adb04f59ff57e057910aa8454599f
5 * Derived from webmail.php by Ralf Kraudelt <kraude@wiwi.uni-rostock.de>
7 * Copyright (c) 1999-2003 The SquirrelMail Project Team
8 * Licensed under the GNU GPL. For full terms see the file COPYING.
10 * Prevents users from reposting their form data after a successful logout.
13 * @package squirrelmail
16 /** Path for SquirrelMail required files. */
17 define('SM_PATH','../');
19 /* SquirrelMail required files. */
20 require_once(SM_PATH
. 'functions/global.php');
21 require_once(SM_PATH
. 'functions/i18n.php');
22 require_once(SM_PATH
. 'functions/strings.php');
23 require_once(SM_PATH
. 'config/config.php');
24 require_once(SM_PATH
. 'functions/prefs.php');
25 require_once(SM_PATH
. 'functions/imap.php');
26 require_once(SM_PATH
. 'functions/plugin.php');
27 require_once(SM_PATH
. 'functions/constants.php');
28 require_once(SM_PATH
. 'functions/page_header.php');
30 /* Before starting the session, the base URI must be known. Assuming */
31 /* that this file is in the src/ subdirectory (or something). */
32 if (!function_exists('sqm_baseuri')){
33 require_once(SM_PATH
. 'functions/display_messages.php');
35 $base_uri = sqm_baseuri();
37 header('Pragma: no-cache');
38 $location = get_location();
40 session_set_cookie_params (0, $base_uri);
41 sqsession_is_active();
43 sqsession_unregister ('user_is_logged_in');
44 sqsession_register ($base_uri, 'base_uri');
46 /* get globals we me need */
47 sqGetGlobalVar('login_username', $login_username);
48 sqGetGlobalVar('secretkey', $secretkey);
49 sqGetGlobalVar('js_autodetect_results', $js_autodetect_results);
50 if(!sqGetGlobalVar('squirrelmail_language', $squirrelmail_language) ||
$squirrelmail_language == '') {
51 $squirrelmail_language = $squirrelmail_default_language;
53 if (!sqgetGlobalVar('mailto', $mailto)) {
57 /* end of get globals */
59 set_up_language($squirrelmail_language, true);
60 /* Refresh the language cookie. */
61 setcookie('squirrelmail_language', $squirrelmail_language, time()+
2592000,
64 if (!isset($login_username)) {
65 include_once(SM_PATH
. 'functions/display_messages.php' );
66 logout_error( _("You must be logged in to access this page.") );
70 if (!sqsession_is_registered('user_is_logged_in')) {
71 do_hook ('login_before');
73 $onetimepad = OneTimePadCreate(strlen($secretkey));
74 $key = OneTimePadEncrypt($secretkey, $onetimepad);
75 sqsession_register($onetimepad, 'onetimepad');
77 /* remove redundant spaces */
78 $login_username = trim($login_username);
80 /* Verify that username and password are correct. */
81 if ($force_username_lowercase) {
82 $login_username = strtolower($login_username);
85 $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
87 $sqimap_capabilities = sqimap_capability($imapConnection);
88 sqsession_register($sqimap_capabilities, 'sqimap_capabilities');
89 $delimiter = sqimap_get_delimiter ($imapConnection);
91 sqimap_logout($imapConnection);
92 sqsession_register($delimiter, 'delimiter');
94 $username = $login_username;
95 sqsession_register ($username, 'username');
96 setcookie('key', $key, 0, $base_uri);
98 switch ($allow_frames) {
99 case 4: // if $use_frames unset, fall through to case 2
100 if (isset($_POST['set_use_frames'])) {
101 $use_frames = $_POST['set_use_frames'];
104 case 2: // Do not use frames
107 case 3: // if $use_frames unset, fall through to case 1
108 if (isset($_POST['set_use_frames'])) {
109 $use_frames = $_POST['set_use_frames'];
112 default: // default is also to use frames
113 case 1: // use frames
118 setcookie('use_frames', $use_frames, time()+
2592000, $base_uri);
119 do_hook ('login_verified');
123 /* Set the login variables. */
124 $user_is_logged_in = true;
125 $just_logged_in = true;
127 /* And register with them with the session. */
128 sqsession_register ($user_is_logged_in, 'user_is_logged_in');
129 sqsession_register ($just_logged_in, 'just_logged_in');
131 /* parse the accepted content-types of the client */
132 $attachment_common_types = array();
133 $attachment_common_types_parsed = array();
134 sqsession_register($attachment_common_types, 'attachment_common_types');
135 sqsession_register($attachment_common_types_parsed, 'attachment_common_types_parsed');
139 if ( sqgetGlobalVar('HTTP_ACCEPT', $http_accept, SQ_SERVER
) &&
140 !isset($attachment_common_types_parsed[$http_accept]) ) {
141 attachment_common_parse($http_accept, $debug);
144 /* Complete autodetection of Javascript. */
145 $javascript_setting = getPref
146 ($data_dir, $username, 'javascript_setting', SMPREF_JS_AUTODETECT
);
147 $js_autodetect_results = (isset($js_autodetect_results) ?
148 $js_autodetect_results : SMPREF_JS_OFF
);
149 /* See if it's set to "Always on" */
150 $js_pref = SMPREF_JS_ON
;
151 if ($javascript_setting != SMPREF_JS_ON
){
152 if ($javascript_setting == SMPREF_JS_AUTODETECT
) {
153 if ($js_autodetect_results == SMPREF_JS_OFF
) {
154 $js_pref = SMPREF_JS_OFF
;
157 $js_pref = SMPREF_JS_OFF
;
160 /* Update the prefs */
161 setPref($data_dir, $username, 'javascript_on', $js_pref);
163 /* Compute the URL to forward the user to. */
164 $redirect_url = $location . '/webmail.php';
166 if ( sqgetGlobalVar('session_expired_location', $session_expired_location, SQ_SESSION
) ) {
167 sqsession_unregister('session_expired_location');
168 $compose_new_win = getPref($data_dir, $username, 'compose_new_win', 0);
169 if ($compose_new_win) {
170 // do not prefix $location here because $session_expired_location is set to PHP_SELF
172 $redirect_url = $session_expired_location;
173 } elseif ( strpos($session_expired_location, 'webmail.php') === FALSE ) {
174 $redirect_url = $location.'/webmail.php?right_frame='.urldecode($session_expired_location);
176 unset($session_expired_location);
179 $redirect_url = $location . '/webmail.php?right_frame=compose.php&mailto=';
180 $redirect_url .= $mailto;
183 /* Write session data and send them off to the appropriate page. */
184 session_write_close();
185 header("Location: $redirect_url");
187 /* --------------------- end main ----------------------- */
189 function attachment_common_parse($str, $debug) {
190 global $attachment_common_types, $attachment_common_types_parsed;
192 $attachment_common_types_parsed[$str] = true;
195 * Replace ", " with "," and explode on that as Mozilla 1.x seems to
196 * use "," to seperate whilst IE, and earlier versions of Mozilla use
200 $str = str_replace( ', ' , ',' , $str );
201 $types = explode(',', $str);
203 foreach ($types as $val) {
204 // Ignore the ";q=1.0" stuff
205 if (strpos($val, ';') !== false)
206 $val = substr($val, 0, strpos($val, ';'));
208 if (! isset($attachment_common_types[$val])) {
209 $attachment_common_types[$val] = true;
212 $_SESSION['attachment_common_types'] = $attachment_common_types;