If mailto: string isn't double URL encoded, the values don't correctly get
[squirrelmail.git] / src / redirect.php
1 <?php
2
3 /**
4 * redirect.php
5 * Derived from webmail.php by Ralf Kraudelt <kraude@wiwi.uni-rostock.de>
6 *
7 * Copyright (c) 1999-2005 The SquirrelMail Project Team
8 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 *
10 * Prevents users from reposting their form data after a successful logout.
11 *
12 * @version $Id$
13 * @package squirrelmail
14 */
15
16 /**
17 * Path for SquirrelMail required files.
18 * @ignore
19 */
20 define('SM_PATH','../');
21
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');
32
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');
37 }
38 $base_uri = sqm_baseuri();
39
40 header('Pragma: no-cache');
41 $location = get_location();
42
43 session_set_cookie_params (0, $base_uri);
44 sqsession_is_active();
45
46 sqsession_unregister ('user_is_logged_in');
47 sqsession_register ($base_uri, 'base_uri');
48
49 /* get globals we me need */
50 sqGetGlobalVar('login_username', $login_username);
51 sqGetGlobalVar('secretkey', $secretkey);
52 if(!sqGetGlobalVar('squirrelmail_language', $squirrelmail_language) || $squirrelmail_language == '') {
53 $squirrelmail_language = $squirrelmail_default_language;
54 }
55 if (!sqgetGlobalVar('mailto', $mailto)) {
56 $mailto = '';
57 }
58
59 /* end of get globals */
60
61 set_up_language($squirrelmail_language, true);
62 /* Refresh the language cookie. */
63 setcookie('squirrelmail_language', $squirrelmail_language, time()+2592000,
64 $base_uri);
65
66 if (!isset($login_username)) {
67 include_once(SM_PATH . 'functions/display_messages.php' );
68 logout_error( _("You must be logged in to access this page.") );
69 exit;
70 }
71
72 if (!sqsession_is_registered('user_is_logged_in')) {
73 do_hook ('login_before');
74
75 $onetimepad = OneTimePadCreate(strlen($secretkey));
76 $key = OneTimePadEncrypt($secretkey, $onetimepad);
77 sqsession_register($onetimepad, 'onetimepad');
78
79 /* remove redundant spaces */
80 $login_username = trim($login_username);
81
82 /* Verify that username and password are correct. */
83 if ($force_username_lowercase) {
84 $login_username = strtolower($login_username);
85 }
86
87 $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
88
89 $sqimap_capabilities = sqimap_capability($imapConnection);
90 sqsession_register($sqimap_capabilities, 'sqimap_capabilities');
91 $delimiter = sqimap_get_delimiter ($imapConnection);
92
93 sqimap_logout($imapConnection);
94 sqsession_register($delimiter, 'delimiter');
95
96 $username = $login_username;
97 sqsession_register ($username, 'username');
98 setcookie('key', $key, 0, $base_uri);
99 do_hook ('login_verified');
100
101 }
102
103 /* Set the login variables. */
104 $user_is_logged_in = true;
105 $just_logged_in = true;
106
107 /* And register with them with the session. */
108 sqsession_register ($user_is_logged_in, 'user_is_logged_in');
109 sqsession_register ($just_logged_in, 'just_logged_in');
110
111 /* parse the accepted content-types of the client */
112 $attachment_common_types = array();
113 $attachment_common_types_parsed = array();
114 sqsession_register($attachment_common_types, 'attachment_common_types');
115 sqsession_register($attachment_common_types_parsed, 'attachment_common_types_parsed');
116
117 $debug = false;
118
119 if ( sqgetGlobalVar('HTTP_ACCEPT', $http_accept, SQ_SERVER) &&
120 !isset($attachment_common_types_parsed[$http_accept]) ) {
121 attachment_common_parse($http_accept, $debug);
122 }
123
124 /* Complete autodetection of Javascript. */
125 checkForJavascript();
126
127 /* Compute the URL to forward the user to. */
128 $redirect_url = $location . '/webmail.php';
129
130 if ( sqgetGlobalVar('session_expired_location', $session_expired_location, SQ_SESSION) ) {
131 sqsession_unregister('session_expired_location');
132 $compose_new_win = getPref($data_dir, $username, 'compose_new_win', 0);
133 if ($compose_new_win) {
134 // do not prefix $location here because $session_expired_location is set to PHP_SELF
135 // of the last page
136 $redirect_url = $session_expired_location;
137 } elseif ( strpos($session_expired_location, 'webmail.php') === FALSE ) {
138 $redirect_url = $location.'/webmail.php?right_frame='.urldecode($session_expired_location);
139 }
140 unset($session_expired_location);
141 }
142 if($mailto != '') {
143 $redirect_url = $location . '/webmail.php?right_frame=compose.php&mailto=';
144 $redirect_url .= urlencode($mailto);
145 }
146
147 /* Write session data and send them off to the appropriate page. */
148 session_write_close();
149 header("Location: $redirect_url");
150
151 /* --------------------- end main ----------------------- */
152
153 function attachment_common_parse($str, $debug) {
154 global $attachment_common_types, $attachment_common_types_parsed;
155
156 $attachment_common_types_parsed[$str] = true;
157
158 /*
159 * Replace ", " with "," and explode on that as Mozilla 1.x seems to
160 * use "," to seperate whilst IE, and earlier versions of Mozilla use
161 * ", " to seperate
162 */
163
164 $str = str_replace( ', ' , ',' , $str );
165 $types = explode(',', $str);
166
167 foreach ($types as $val) {
168 // Ignore the ";q=1.0" stuff
169 if (strpos($val, ';') !== false)
170 $val = substr($val, 0, strpos($val, ';'));
171
172 if (! isset($attachment_common_types[$val])) {
173 $attachment_common_types[$val] = true;
174 }
175 }
176 sqsession_register($attachment_common_types, 'attachment_common_types');
177 }
178
179 ?>