5 * Derived from webmail.php by Ralf Kraudelt <kraude@wiwi.uni-rostock.de>
7 * Copyright (c) 1999-2002 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.
15 require_once('../functions/i18n.php');
16 require_once('../functions/strings.php');
17 require_once('../config/config.php');
18 require_once('../functions/prefs.php');
19 require_once('../functions/imap.php');
20 require_once('../functions/plugin.php');
21 require_once('../functions/constants.php');
22 require_once('../functions/page_header.php');
24 // Remove slashes if PHP added them
25 if (get_magic_quotes_gpc()) {
26 global $REQUEST_METHOD;
28 if ($REQUEST_METHOD == 'POST') {
29 global $HTTP_POST_VARS;
30 RemoveSlashes($HTTP_POST_VARS);
31 } else if ($REQUEST_METHOD == 'GET') {
32 global $HTTP_GET_VARS;
33 RemoveSlashes($HTTP_GET_VARS);
37 /* Before starting the session, the base URI must be known. Assuming */
38 /* that this file is in the src/ subdirectory (or something). */
39 if (!function_exists('sqm_baseuri')){
40 require_once('../functions/display_messages.php');
42 $base_uri = sqm_baseuri();
44 header('Pragma: no-cache');
45 $location = get_location();
47 session_set_cookie_params (0, $base_uri);
50 session_unregister ('user_is_logged_in');
51 session_register ('base_uri');
53 if (! isset($squirrelmail_language) ||
54 $squirrelmail_language == '' ) {
55 $squirrelmail_language = $squirrelmail_default_language;
57 set_up_language($squirrelmail_language, true);
58 /* Refresh the language cookie. */
59 setcookie('squirrelmail_language', $squirrelmail_language, time()+
2592000,
62 if (!isset($login_username)) {
63 include_once( '../functions/display_messages.php' );
64 logout_error( _("You must be logged in to access this page.") );
68 if (!session_is_registered('user_is_logged_in')) {
69 do_hook ('login_before');
71 $onetimepad = OneTimePadCreate(strlen($secretkey));
72 $key = OneTimePadEncrypt($secretkey, $onetimepad);
73 session_register('onetimepad');
75 /* Verify that username and password are correct. */
76 if ($force_username_lowercase) {
77 $login_username = strtolower($login_username);
80 $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
81 if (!$imapConnection) {
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.") );
89 $delimiter = sqimap_get_delimiter ($imapConnection);
91 sqimap_logout($imapConnection);
92 session_register('delimiter');
94 $username = $login_username;
95 session_register ('username');
96 setcookie('key', $key, 0, $base_uri);
97 do_hook ('login_verified');
101 /* Set the login variables. */
102 $user_is_logged_in = true;
103 $just_logged_in = true;
105 /* And register with them with the session. */
106 session_register ('user_is_logged_in');
107 session_register ('just_logged_in');
109 /* parse the accepted content-types of the client */
110 $attachment_common_types = array();
111 $attachment_common_types_parsed = array();
112 session_register('attachment_common_types');
113 session_register('attachment_common_types_parsed');
116 if (isset($HTTP_SERVER_VARS['HTTP_ACCEPT']) &&
117 !isset($attachment_common_types_parsed[$HTTP_SERVER_VARS['HTTP_ACCEPT']])) {
118 attachment_common_parse($HTTP_SERVER_VARS['HTTP_ACCEPT'], $debug);
120 if (isset($HTTP_ACCEPT) &&
121 !isset($attachment_common_types_parsed[$HTTP_ACCEPT])) {
122 attachment_common_parse($HTTP_ACCEPT, $debug);
125 /* Complete autodetection of Javascript. */
126 $javascript_setting = getPref
127 ($data_dir, $username, 'javascript_setting', SMPREF_JS_AUTODETECT
);
128 $js_autodetect_results = (isset($js_autodetect_results) ?
129 $js_autodetect_results : SMPREF_JS_OFF
);
130 /* See if it's set to "Always on" */
131 $js_pref = SMPREF_JS_ON
;
132 if ($javascript_setting != SMPREF_JS_ON
){
133 if ($javascript_setting == SMPREF_JS_AUTODETECT
) {
134 if ($js_autodetect_results == SMPREF_JS_OFF
) {
135 $js_pref = SMPREF_JS_OFF
;
138 $js_pref = SMPREF_JS_OFF
;
141 /* Update the prefs */
142 setPref($data_dir, $username, 'javascript_on', $js_pref);
144 /* Compute the URL to forward the user to. */
145 if(isset($rcptemail)) {
146 $redirect_url = 'webmail.php?right_frame=compose.php&rcptaddress=';
147 $redirect_url .= $rcptemail;
149 $redirect_url = 'webmail.php';
152 /* Send them off to the appropriate page. */
153 header("Location: $redirect_url");
155 /* --------------------- end main ----------------------- */
157 function attachment_common_parse($str, $debug) {
158 global $attachment_common_types, $attachment_common_types_parsed;
160 $attachment_common_types_parsed[$str] = true;
161 $types = explode(', ', $str);
163 foreach ($types as $val) {
164 // Ignore the ";q=1.0" stuff
165 if (strpos($val, ';') !== false)
166 $val = substr($val, 0, strpos($val, ';'));
168 if (! isset($attachment_common_types[$val])) {
169 $attachment_common_types[$val] = true;