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 ereg ("(^.*/)[^/]+/[^/]+$", $PHP_SELF, $regs);
42 header('Pragma: no-cache');
43 $location = get_location();
45 session_set_cookie_params (0, $base_uri);
48 session_unregister ('user_is_logged_in');
49 session_register ('base_uri');
51 if (! isset($squirrelmail_language) ||
52 $squirrelmail_language == '' ) {
53 $squirrelmail_language = $squirrelmail_default_language;
55 set_up_language($squirrelmail_language, true);
56 /* Refresh the language cookie. */
57 setcookie('squirrelmail_language', $squirrelmail_language, time()+
2592000,$base_uri);
59 if (!isset($login_username)) {
60 displayHtmlHeader( _("You must be logged in to access this page.") );
61 echo "<BODY BGCOLOR=\"#ffffff\">\n" .
64 '<B>' . _("You must be logged in to access this page.") . "</B><BR>" .
65 '<A HREF="../src/login.php">' . _("Go to the login page") . "</A>\n" .
71 if (!session_is_registered('user_is_logged_in')) {
72 do_hook ('login_before');
74 $onetimepad = OneTimePadCreate(strlen($secretkey));
75 $key = OneTimePadEncrypt($secretkey, $onetimepad);
76 session_register('onetimepad');
78 /* Verify that username and password are correct. */
79 if ($force_username_lowercase) {
80 $login_username = strtolower($login_username);
83 $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
84 if (!$imapConnection) {
85 displayHtmlHeader( _("There was an error contacting the mail server.") );
86 echo "<body bgcolor=\"#ffffff\">\n".
89 '<b>' . _("There was an error contacting the mail server.") . "</b><br>\n".
90 _("Contact your administrator for help.") . "\n".
95 $delimiter = sqimap_get_delimiter ($imapConnection);
97 sqimap_logout($imapConnection);
98 session_register('delimiter');
100 $username = $login_username;
101 session_register ('username');
102 setcookie('key', $key, 0, $base_uri);
103 do_hook ('login_verified');
107 /* Set the login variables. */
108 $user_is_logged_in = true;
109 $just_logged_in = true;
111 /* And register with them with the session. */
112 session_register ('user_is_logged_in');
113 session_register ('just_logged_in');
115 /* parse the accepted content-types of the client */
116 $attachment_common_types = array();
117 $attachment_common_types_parsed = array();
118 session_register('attachment_common_types');
119 session_register('attachment_common_types_parsed');
122 if (isset($HTTP_SERVER_VARS['HTTP_ACCEPT']) &&
123 !isset($attachment_common_types_parsed[$HTTP_SERVER_VARS['HTTP_ACCEPT']]))
124 attachment_common_parse($HTTP_SERVER_VARS['HTTP_ACCEPT'], $debug);
125 if (isset($HTTP_ACCEPT) &&
126 !isset($attachment_common_types_parsed[$HTTP_ACCEPT]))
127 attachment_common_parse($HTTP_ACCEPT, $debug);
130 /* Complete autodetection of Javascript. */
131 $javascript_setting = getPref
132 ($data_dir, $username, 'javascript_setting', SMPREF_JS_AUTODETECT
);
133 $js_autodetect_results = (isset($js_autodetect_results) ?
134 $js_autodetect_results : SMPREF_JS_OFF
);
135 /* See if it's set to "Always on" */
136 $js_pref = SMPREF_JS_ON
;
137 if ($javascript_setting != SMPREF_JS_ON
){
138 if ($javascript_setting == SMPREF_JS_AUTODETECT
) {
139 if ($js_autodetect_results == SMPREF_JS_OFF
) {
140 $js_pref = SMPREF_JS_OFF
;
143 $js_pref = SMPREF_JS_OFF
;
146 /* Update the prefs */
147 setPref($data_dir, $username, 'javascript_on', $js_pref);
149 /* Compute the URL to forward the user to. */
150 if(isset($rcptemail)) {
151 $redirect_url = 'webmail.php?right_frame=compose.php&rcptaddress=';
152 $redirect_url .= urlencode($rcptemail);
154 $redirect_url = 'webmail.php';
157 /* Send them off to the appropriate page. */
158 header("Location: $redirect_url");
160 /* --------------------- end main ----------------------- */
162 function attachment_common_parse($str, $debug) {
163 global $attachment_common_types, $attachment_common_types_parsed;
165 $attachment_common_types_parsed[$str] = true;
166 $types = explode(', ', $str);
168 foreach ($types as $val) {
169 // Ignore the ";q=1.0" stuff
170 if (strpos($val, ';') !== false)
171 $val = substr($val, 0, strpos($val, ';'));
173 if (! isset($attachment_common_types[$val])) {
174 $attachment_common_types[$val] = true;