5 * Derived from webmail.php by Ralf Kraudelt <kraude@wiwi.uni-rostock.de>
7 * Copyright (c) 1999-2004 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
17 * Path for SquirrelMail required files.
20 define('SM_PATH','../');
22 /* SquirrelMail required files. */
23 require_once(SM_PATH
. 'functions/global.php');
24 require_once(SM_PATH
. 'functions/i18n.php');
25 require_once(SM_PATH
. 'functions/strings.php');
26 require_once(SM_PATH
. 'config/config.php');
27 require_once(SM_PATH
. 'functions/prefs.php');
28 require_once(SM_PATH
. 'functions/imap.php');
29 require_once(SM_PATH
. 'functions/plugin.php');
30 require_once(SM_PATH
. 'functions/constants.php');
31 require_once(SM_PATH
. 'functions/page_header.php');
33 /* Before starting the session, the base URI must be known. Assuming */
34 /* that this file is in the src/ subdirectory (or something). */
35 if (!function_exists('sqm_baseuri')){
36 require_once(SM_PATH
. 'functions/display_messages.php');
38 $base_uri = sqm_baseuri();
40 header('Pragma: no-cache');
41 $location = get_location();
43 sqsession_is_active();
45 sqsession_unregister ('user_is_logged_in');
46 sqsession_register ($base_uri, 'base_uri');
48 /* get globals we me need */
49 sqGetGlobalVar('login_username', $login_username);
50 sqGetGlobalVar('secretkey', $secretkey);
51 if(!sqGetGlobalVar('squirrelmail_language', $squirrelmail_language) ||
$squirrelmail_language == '') {
52 $squirrelmail_language = $squirrelmail_default_language;
54 if (!sqgetGlobalVar('mailto', $mailto)) {
58 /* end of get globals */
60 set_up_language($squirrelmail_language, true);
61 /* Refresh the language cookie. */
62 setcookie('squirrelmail_language', $squirrelmail_language, time()+
2592000,
65 if (!isset($login_username)) {
66 include_once(SM_PATH
. 'functions/display_messages.php' );
67 logout_error( _("You must be logged in to access this page.") );
71 if (!sqsession_is_registered('user_is_logged_in')) {
72 do_hook ('login_before');
74 $onetimepad = OneTimePadCreate(strlen($secretkey));
75 $key = OneTimePadEncrypt($secretkey, $onetimepad);
76 sqsession_register($onetimepad, 'onetimepad');
78 /* remove redundant spaces */
79 $login_username = trim($login_username);
81 /* Verify that username and password are correct. */
82 if ($force_username_lowercase) {
83 $login_username = strtolower($login_username);
86 $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
88 $sqimap_capabilities = sqimap_capability($imapConnection);
89 sqsession_register($sqimap_capabilities, 'sqimap_capabilities');
90 $delimiter = sqimap_get_delimiter ($imapConnection);
92 sqimap_logout($imapConnection);
93 sqsession_register($delimiter, 'delimiter');
95 $username = $login_username;
96 sqsession_register ($username, 'username');
97 setcookie('key', $key, 0, $base_uri);
98 do_hook ('login_verified');
102 /* Set the login variables. */
103 $user_is_logged_in = true;
104 $just_logged_in = true;
106 /* And register with them with the session. */
107 sqsession_register ($user_is_logged_in, 'user_is_logged_in');
108 sqsession_register ($just_logged_in, 'just_logged_in');
110 /* parse the accepted content-types of the client */
111 $attachment_common_types = array();
112 $attachment_common_types_parsed = array();
113 sqsession_register($attachment_common_types, 'attachment_common_types');
114 sqsession_register($attachment_common_types_parsed, 'attachment_common_types_parsed');
118 if ( sqgetGlobalVar('HTTP_ACCEPT', $http_accept, SQ_SERVER
) &&
119 !isset($attachment_common_types_parsed[$http_accept]) ) {
120 attachment_common_parse($http_accept, $debug);
123 /* Complete autodetection of Javascript. */
124 checkForJavascript();
126 /* Compute the URL to forward the user to. */
127 $redirect_url = $location . '/webmail.php';
129 if ( sqgetGlobalVar('session_expired_location', $session_expired_location, SQ_SESSION
) ) {
130 sqsession_unregister('session_expired_location');
131 $compose_new_win = getPref($data_dir, $username, 'compose_new_win', 0);
132 if ($compose_new_win) {
133 // do not prefix $location here because $session_expired_location is set to PHP_SELF
135 $redirect_url = $session_expired_location;
136 } elseif ( strpos($session_expired_location, 'webmail.php') === FALSE ) {
137 $redirect_url = $location.'/webmail.php?right_frame='.urldecode($session_expired_location);
139 unset($session_expired_location);
142 $redirect_url = $location . '/webmail.php?right_frame=compose.php&mailto=';
143 $redirect_url .= $mailto;
146 /* Write session data and send them off to the appropriate page. */
147 session_write_close();
148 header("Location: $redirect_url");
150 /* --------------------- end main ----------------------- */
152 function attachment_common_parse($str, $debug) {
153 global $attachment_common_types, $attachment_common_types_parsed;
155 $attachment_common_types_parsed[$str] = true;
158 * Replace ", " with "," and explode on that as Mozilla 1.x seems to
159 * use "," to seperate whilst IE, and earlier versions of Mozilla use
163 $str = str_replace( ', ' , ',' , $str );
164 $types = explode(',', $str);
166 foreach ($types as $val) {
167 // Ignore the ";q=1.0" stuff
168 if (strpos($val, ';') !== false)
169 $val = substr($val, 0, strpos($val, ';'));
171 if (! isset($attachment_common_types[$val])) {
172 $attachment_common_types[$val] = true;
175 sqsession_register($attachment_common_types, 'attachment_common_types');