Added a counter pref and a fix for the imapid
[squirrelmail.git] / src / redirect.php
CommitLineData
7392739d 1<?php
895905c0 2
23d6bd09 3 /**
895905c0 4 ** redirect.php
5 ** Derived from webmail.php by Ralf Kraudelt <kraude@wiwi.uni-rostock.de>
6 **
7 ** Copyright (c) 1999-2001 The Squirrelmail Development 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 ** $Id$
13 **/
23d6bd09 14
15 require_once('../functions/i18n.php');
16 require_once('../functions/strings.php');
17 require_once('../config/config.php');
cb48c245 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
23 function attachment_common_parse($str, $debug) {
24 global $attachment_common_types, $attachment_common_types_parsed;
25
26 $attachment_common_types_parsed[$str] = true;
27 $types = explode(', ', $str);
28
29 foreach ($types as $val)
30 {
31 // Ignore the ";q=1.0" stuff
32 if (strpos($val, ';') !== false)
33 $val = substr($val, 0, strpos($val, ';'));
34
35 if (! isset($attachment_common_types[$val])) {
36 $attachment_common_types[$val] = true;
37 }
38 }
39 }
40
23d6bd09 41
42 /* Before starting the session, the base URI must be known. Assuming */
43 /* that this file is in the src/ subdirectory (or something). */
44 ereg ("(^.*/)[^/]+/[^/]+$", $PHP_SELF, $regs);
45 $base_uri = $regs[1];
46
47 header('Pragma: no-cache');
48 $location = get_location();
49
50 session_set_cookie_params (0, $base_uri);
51 session_start();
52
53 session_unregister ('user_is_logged_in');
54 session_register ('base_uri');
55
cb48c245 56 if (! isset($squirrelmail_language) ||
57 $squirrelmail_language == '' ) {
58 $squirrelmail_language = $squirrelmail_default_language;
23d6bd09 59 }
60 set_up_language($squirrelmail_language, true);
cb48c245 61 /* Refresh the language cookie. */
62 setcookie('squirrelmail_language', $squirrelmail_language, time()+2592000,$base_uri);
23d6bd09 63
64 if (!isset($login_username)) {
cb48c245 65 echo "<HTML><BODY BGCOLOR=\"#ffffff\">\n" .
66 "<BR>&nbsp;<BR>\n" .
67 "<CENTER>\n" .
68 '<B>' . _("You must be logged in to access this page.") . "</B><BR>" .
69 '<A HREF="../src/login.php">' . _("Go to the login page") . "</A>\n" .
70 "</CENTER>\n" .
71 "</BODY></HTML>\n";
23d6bd09 72 exit;
73 }
74
23d6bd09 75 if (!session_is_registered('user_is_logged_in')) {
76 do_hook ('login_before');
77
78 $onetimepad = OneTimePadCreate(strlen($secretkey));
79 $key = OneTimePadEncrypt($secretkey, $onetimepad);
80 session_register('onetimepad');
81
82 /* Verify that username and password are correct. */
83 if ($force_username_lowercase) {
84 $login_username = strtolower($login_username);
85 }
cb48c245 86
23d6bd09 87 $imapConnection = sqimap_login($login_username, $key, $imapServerAddress, $imapPort, 0);
88 if (!$imapConnection) {
cb48c245 89 echo "<html><body bgcolor=\"#ffffff\">\n".
90 "<br> <br>\n".
91 "<center>\n".
92 '<b>' . _("There was an error contacting the mail server.") . "</b><br>\n".
93 _("Contact your administrator for help.") . "\n".
94 "</center>\n".
95 "</body></html>\n";
23d6bd09 96 exit;
97 } else {
98 $delimiter = sqimap_get_delimiter ($imapConnection);
99 }
100 sqimap_logout($imapConnection);
525b7ae6 101 session_register('delimiter');
23d6bd09 102
103 $username = $login_username;
104 session_register ('username');
105 setcookie('key', $key, 0, $base_uri);
23d6bd09 106 do_hook ('login_verified');
71257f8b 107 setPref( $data_dir, $username, 'counter',
108 getPref( $data_dir, $username, 'counter', 0 ) + 1 );
23d6bd09 109 }
110
111 /* Set the login variables. */
112 $user_is_logged_in = true;
113 $just_logged_in = true;
114
115 /* And register with them with the session. */
116 session_register ('user_is_logged_in');
117 session_register ('just_logged_in');
118
7baf86a9 119 /* parse the accepted content-types of the client */
120 $attachment_common_types = array();
121 $attachment_common_types_parsed = array();
122 session_register('attachment_common_types');
123 session_register('attachment_common_types_parsed');
124
bbdd6ddb 125 $debug = false;
7baf86a9 126 if (isset($HTTP_SERVER_VARS['HTTP_ACCEPT']) &&
127 !isset($attachment_common_types_parsed[$HTTP_SERVER_VARS['HTTP_ACCEPT']]))
128 attachment_common_parse($HTTP_SERVER_VARS['HTTP_ACCEPT'], $debug);
129 if (isset($HTTP_ACCEPT) &&
130 !isset($attachment_common_types_parsed[$HTTP_ACCEPT]))
131 attachment_common_parse($HTTP_ACCEPT, $debug);
132
133
23d6bd09 134 /* Complete autodetection of Javascript. */
357f1ae0 135 checkForPrefs($data_dir, $username);
23d6bd09 136 $javascript_setting = getPref($data_dir, $username, 'javascript_setting', SMPREF_JS_AUTODETECT);
137 $js_autodetect_results = (isset($js_autodetect_results) ? $js_autodetect_results : SMPREF_JS_OFF);
138 if ($javascript_setting == SMPREF_JS_AUTODETECT) {
139 if ($js_autodetect_results == SMPREF_JS_ON) {
140 setPref($data_dir, $username, 'javascript_on', SMPREF_JS_ON);
141 } else {
142 setPref($data_dir, $username, 'javascript_on', SMPREF_JS_OFF);
143 }
144 } else {
145 setPref($data_dir, $username, 'javascript_on', SMPREF_JS_OFF);
146 }
147
148 /* Compute the URL to forward the user to. */
149 if(isset($rcptemail)) {
150 $redirect_url = 'webmail.php?right_frame=compose.php&rcptaddress=';
151 $redirect_url .= urlencode($rcptemail);
152 } else {
153 $redirect_url = 'webmail.php';
154 }
155
156 /* Send them off to the appropriate page. */
157 header("Location: $redirect_url");
7baf86a9 158
e0dcff78 159?>