4 * Prevents users from reposting their form data after a successful logout.
6 * Derived from webmail.php by Ralf Kraudelt <kraude@wiwi.uni-rostock.de>
8 * @copyright © 1999-2006 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @package squirrelmail
15 * Path for SquirrelMail required files.
18 define('SM_PATH','../');
20 /* SquirrelMail required files. */
21 require_once(SM_PATH
. 'functions/global.php');
22 require_once(SM_PATH
. 'functions/i18n.php');
23 require_once(SM_PATH
. 'functions/strings.php');
24 require_once(SM_PATH
. 'config/config.php');
25 require_once(SM_PATH
. 'functions/prefs.php');
26 require_once(SM_PATH
. 'functions/imap.php');
27 require_once(SM_PATH
. 'functions/plugin.php');
28 require_once(SM_PATH
. 'functions/constants.php');
29 require_once(SM_PATH
. 'functions/page_header.php');
31 /* Before starting the session, the base URI must be known. Assuming */
32 /* that this file is in the src/ subdirectory (or something). */
33 $base_uri = sqm_baseuri();
35 header('Pragma: no-cache');
36 $location = get_location();
38 session_set_cookie_params (0, $base_uri);
39 sqsession_is_active();
41 sqsession_unregister ('user_is_logged_in');
42 sqsession_register ($base_uri, 'base_uri');
44 /* get globals we me need */
45 sqGetGlobalVar('login_username', $login_username);
46 sqGetGlobalVar('secretkey', $secretkey);
47 if(!sqGetGlobalVar('squirrelmail_language', $squirrelmail_language) ||
$squirrelmail_language == '') {
48 $squirrelmail_language = $squirrelmail_default_language;
50 if (!sqgetGlobalVar('mailto', $mailto)) {
54 /* end of get globals */
56 set_up_language($squirrelmail_language, true);
57 /* Refresh the language cookie. */
58 sqsetcookie('squirrelmail_language', $squirrelmail_language, time()+
2592000,
61 if (!isset($login_username)) {
62 include_once(SM_PATH
. 'functions/display_messages.php' );
63 logout_error( _("You must be logged in to access this page.") );
67 if (!sqsession_is_registered('user_is_logged_in')) {
68 do_hook ('login_before');
70 $onetimepad = OneTimePadCreate(strlen($secretkey));
71 $key = OneTimePadEncrypt($secretkey, $onetimepad);
72 sqsession_register($onetimepad, 'onetimepad');
74 /* remove redundant spaces */
75 $login_username = trim($login_username);
77 /* Verify that username and password are correct. */
78 if ($force_username_lowercase) {
79 $login_username = strtolower($login_username);
82 $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
84 $sqimap_capabilities = sqimap_capability($imapConnection);
86 /* Server side sorting control */
87 if (isset($sqimap_capabilities['SORT']) && $sqimap_capabilities['SORT'] == true &&
88 isset($disable_server_sort) && $disable_server_sort) {
89 unset($sqimap_capabilities['SORT']);
92 /* Thread sort control */
93 if (isset($sqimap_capabilities['THREAD']) && $sqimap_capabilities['THREAD'] == true &&
94 isset($disable_thread_sort) && $disable_thread_sort) {
95 unset($sqimap_capabilities['THREAD']);
98 sqsession_register($sqimap_capabilities, 'sqimap_capabilities');
99 $delimiter = sqimap_get_delimiter ($imapConnection);
101 sqimap_logout($imapConnection);
102 sqsession_register($delimiter, 'delimiter');
104 $username = $login_username;
105 sqsession_register ($username, 'username');
106 sqsetcookie('key', $key, false, $base_uri);
107 do_hook ('login_verified');
111 /* Set the login variables. */
112 $user_is_logged_in = true;
113 $just_logged_in = true;
115 /* And register with them with the session. */
116 sqsession_register ($user_is_logged_in, 'user_is_logged_in');
117 sqsession_register ($just_logged_in, 'just_logged_in');
119 /* parse the accepted content-types of the client */
120 $attachment_common_types = array();
121 $attachment_common_types_parsed = array();
122 sqsession_register($attachment_common_types, 'attachment_common_types');
123 sqsession_register($attachment_common_types_parsed, 'attachment_common_types_parsed');
127 if ( sqgetGlobalVar('HTTP_ACCEPT', $http_accept, SQ_SERVER
) &&
128 !isset($attachment_common_types_parsed[$http_accept]) ) {
129 attachment_common_parse($http_accept, $debug);
132 /* Complete autodetection of Javascript. */
133 checkForJavascript();
135 /* Compute the URL to forward the user to. */
136 $redirect_url = $location . '/webmail.php';
138 if ( sqgetGlobalVar('session_expired_location', $session_expired_location, SQ_SESSION
) ) {
139 sqsession_unregister('session_expired_location');
140 $compose_new_win = getPref($data_dir, $username, 'compose_new_win', 0);
141 if ($compose_new_win) {
142 // do not prefix $location here because $session_expired_location is set to PHP_SELF
144 $redirect_url = $session_expired_location;
145 } elseif ( strpos($session_expired_location, 'webmail.php') === FALSE ) {
146 $redirect_url = $location.'/webmail.php?right_frame='.urldecode($session_expired_location);
148 unset($session_expired_location);
151 $redirect_url = $location . '/webmail.php?right_frame=compose.php&mailto=';
152 $redirect_url .= urlencode($mailto);
155 /* Write session data and send them off to the appropriate page. */
156 session_write_close();
157 header("Location: $redirect_url");
159 /* --------------------- end main ----------------------- */
161 function attachment_common_parse($str, $debug) {
162 global $attachment_common_types, $attachment_common_types_parsed;
164 $attachment_common_types_parsed[$str] = true;
167 * Replace ", " with "," and explode on that as Mozilla 1.x seems to
168 * use "," to seperate whilst IE, and earlier versions of Mozilla use
172 $str = str_replace( ', ' , ',' , $str );
173 $types = explode(',', $str);
175 foreach ($types as $val) {
176 // Ignore the ";q=1.0" stuff
177 if (strpos($val, ';') !== false)
178 $val = substr($val, 0, strpos($val, ';'));
180 if (! isset($attachment_common_types[$val])) {
181 $attachment_common_types[$val] = true;
184 sqsession_register($attachment_common_types, 'attachment_common_types');