charset encode /decode fixes
[squirrelmail.git] / src / right_main.php
CommitLineData
59177427 1<?php
895905c0 2
c57b0888 3/**
4 * right_main.php
5 *
76911253 6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
c57b0888 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This is where the mailboxes are listed. This controls most of what
10 * goes on in SquirrelMail.
11 *
12 * $Id$
13 */
14
86725763 15/* Path for SquirrelMail required files. */
16define('SM_PATH','../');
17
18/* SquirrelMail required files. */
08185f2a 19require_once(SM_PATH . 'include/validate.php');
86725763 20require_once(SM_PATH . 'functions/imap.php');
21require_once(SM_PATH . 'functions/date.php');
86725763 22require_once(SM_PATH . 'functions/mime.php');
23require_once(SM_PATH . 'functions/mailbox_display.php');
24require_once(SM_PATH . 'functions/display_messages.php');
25require_once(SM_PATH . 'functions/html.php');
c57b0888 26
27/***********************************************************
28 * incoming variables from URL: *
29 * $sort Direction to sort by date *
30 * values: 0 - descending order *
31 * values: 1 - ascending order *
32 * $startMessage Message to start at *
33 * $mailbox Full Mailbox name *
34 * *
35 * incoming from cookie: *
c57b0888 36 * $key pass *
a32985a5 37 * incoming from session: *
38 * $username duh *
39 * *
c57b0888 40 ***********************************************************/
41
a32985a5 42
43/* lets get the global vars we may need */
44$username = $_SESSION['username'];
45$key = $_COOKIE['key'];
46$onetimepad = $_SESSION['onetimepad'];
47$base_uri = $_SESSION['base_uri'];
48$delimiter = $_SESSION['delimiter'];
49
50if (isset($_GET['startMessage'])) {
9b761dbd 51 $startMessage = (int) $_GET['startMessage'];
cd9a4fd3 52} elseif (isset($_POST['startMessage'])) {
9b761dbd 53 $startMessage = (int) $_POST['startMessage'];
a32985a5 54}
55if (isset($_GET['mailbox'])) {
56 $mailbox = $_GET['mailbox'];
cd9a4fd3 57} else if (isset($_POST['mailbox'])) {
58 $mailbox = $_POST['mailbox'];
a32985a5 59}
60if (isset($_GET['PG_SHOWNUM'])) {
9b761dbd 61 $PG_SHOWNUM = (int) $_GET['PG_SHOWNUM'];
a32985a5 62}
63elseif (isset($_SESSION['PG_SHOWNUM'])) {
9b761dbd 64 $PG_SHOWNUM = (int) $_SESSION['PG_SHOWNUM'];
a32985a5 65}
66if (isset($_GET['PG_SHOWALL'])) {
9b761dbd 67 $PG_SHOWALL = (int) $_GET['PG_SHOWALL'];
a32985a5 68}
69if (isset($_GET['newsort'])) {
9b761dbd 70 $newsort = (int) $_GET['newsort'];
a32985a5 71}
8cc72ada 72if (isset($_GET['composenew'])) {
73 $composenew = $_GET['composenew'];
74} else {
75 $composenew = false;
76}
77
a32985a5 78if (isset($_GET['checkall'])) {
9b761dbd 79 $checkall = (int) $_GET['checkall'];
a32985a5 80}
81if (isset($_GET['set_thread'])) {
9b761dbd 82 $set_thread = (int) $_GET['set_thread'];
a32985a5 83}
84if (isset($_SESSION['lastTargetMailbox'])) {
85 $lastTargetMailbox =$_SESSION['lastTargetMailbox'];
86}
87
8cc72ada 88if (isset($_GET['session'])) {
89 $session = $_GET['session'];
90}
91
22053bcf 92if (isset($_GET['note'])) {
93 $note = $_GET['note'];
94}
8cc72ada 95
a32985a5 96/* end of get globals */
97
98
c57b0888 99/* Open a connection on the imap port (143) */
6f223ace 100
c57b0888 101$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
102
cf710efe 103if (isset($PG_SHOWALL)) {
104 if ($PG_SHOWALL) {
105 $PG_SHOWNUM=999999;
106 $show_num=$PG_SHOWNUM;
a32985a5 107 sqsession_register($PG_SHOWNUM, 'PG_SHOWNUM');
cf710efe 108 }
109 else {
a32985a5 110 sqsession_unregister('PG_SHOWNUM');
cf710efe 111 unset($PG_SHOWNUM);
112 }
113}
114else if( isset( $PG_SHOWNUM ) ) {
bdfb67f8 115 $show_num = $PG_SHOWNUM;
116}
117
c57b0888 118if (isset($newsort) && $newsort != $sort) {
119 setPref($data_dir, $username, 'sort', $newsort);
120}
121
e372ee8c 122
123
124/* If the page has been loaded without a specific mailbox, */
125/* send them to the inbox */
126if (!isset($mailbox)) {
127 $mailbox = 'INBOX';
128 $startMessage = 1;
129}
130
131
132if (!isset($startMessage) || ($startMessage == '')) {
133 $startMessage = 1;
134}
135
136/* compensate for the UW vulnerability. */
137if ($imap_server_type == 'uw' && (strstr($mailbox, '../') ||
138 substr($mailbox, 0, 1) == '/')) {
139 $mailbox = 'INBOX';
140}
141
7c612fdd 142/* decide if we are thread sorting or not */
794d59c0 143if ($allow_thread_sort == TRUE) {
7c612fdd 144 if (isset($set_thread)) {
145 if ($set_thread == 1) {
78cc4b12 146 setPref($data_dir, $username, "thread_$mailbox", 1);
7c612fdd 147 $thread_sort_messages = '1';
148 }
149 elseif ($set_thread == 2) {
78cc4b12 150 setPref($data_dir, $username, "thread_$mailbox", 0);
7c612fdd 151 $thread_sort_messages = '0';
152 }
153 }
154 else {
78cc4b12 155 $thread_sort_messages = getPref($data_dir, $username, "thread_$mailbox");
7c612fdd 156 }
157}
158else {
159 $thread_sort_messages = 0;
160}
161
a32985a5 162do_hook ('generic_header');
7c612fdd 163
c57b0888 164sqimap_mailbox_select($imapConnection, $mailbox);
6f223ace 165
8cc72ada 166if ($composenew) {
167 $comp_uri = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox).
0cb19b37 168 "&session=$session";
11af81b9 169 displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri');", false);
6f223ace 170} else {
171 displayPageHeader($color, $mailbox);
172}
c57b0888 173do_hook('right_main_after_header');
c57b0888 174if (isset($note)) {
fab3baa6 175 echo html_tag( 'div', '<b>' . $note .'</b>', 'center' ) . "<br>\n";
c57b0888 176}
177
a32985a5 178if (isset($_SESSION['just_logged_in'])) {
179 $just_logged_in = $_SESSION['just_logged_in'];
180 if ($just_logged_in == true) {
181 $just_logged_in = false;
182
183 if (strlen(trim($motd)) > 0) {
184 echo html_tag( 'table',
185 html_tag( 'tr',
186 html_tag( 'td',
187 html_tag( 'table',
188 html_tag( 'tr',
189 html_tag( 'td', $motd, 'center' )
190 ) ,
191 '', $color[4], 'width="100%" cellpadding="5" cellspacing="1" border="0"' )
192 )
193 ) ,
194 'center', $color[9], 'width="70%" cellpadding="0" cellspacing="3" border="0"' );
195 }
23d6bd09 196 }
c57b0888 197}
198
7c612fdd 199if (isset($newsort)) {
200 $sort = $newsort;
a32985a5 201 sqsession_register($sort, 'sort');
7c612fdd 202}
203
c57b0888 204/*********************************************************************
205 * Check to see if we can use cache or not. Currently the only time *
206 * when you will not use it is when a link on the left hand frame is *
207 * used. Also check to make sure we actually have the array in the *
208 * registered session data. :) *
209 *********************************************************************/
210if (! isset($use_mailbox_cache)) {
211 $use_mailbox_cache = 0;
212}
213
d7c82551 214if ($use_mailbox_cache && sqsession_is_registered('msgs')) {
c57b0888 215 showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color, $show_num, $use_mailbox_cache);
216} else {
d7c82551 217 if (sqsession_is_registered('msgs')) {
c57b0888 218 unset($msgs);
23d6bd09 219 }
220
d7c82551 221 if (sqsession_is_registered('msort')) {
c57b0888 222 unset($msort);
23d6bd09 223 }
a37f3771 224
d7c82551 225 if (sqsession_is_registered('numMessages')) {
c57b0888 226 unset($numMessages);
2016e645 227 }
e452ce9b 228
c57b0888 229 $numMessages = sqimap_get_num_messages ($imapConnection, $mailbox);
23d6bd09 230
c57b0888 231 showMessagesForMailbox($imapConnection, $mailbox, $numMessages,
232 $startMessage, $sort, $color, $show_num,
233 $use_mailbox_cache);
23d6bd09 234
d7c82551 235 if (sqsession_is_registered('msgs') && isset($msgs)) {
a32985a5 236 sqsession_register($msgs, 'msgs');
b831fe0b 237 $_SESSION['msgs'] = $msgs;
c57b0888 238 }
1108e8bb 239
d7c82551 240 if (sqsession_is_registered('msort') && isset($msort)) {
a32985a5 241 sqsession_register($msort, 'msort');
b831fe0b 242 $_SESSION['msort'] = $msort;
c57b0888 243 }
9f2215a1 244
a32985a5 245 sqsession_register($numMessages, 'numMessages');
b831fe0b 246 $_SESSION['numMessages'] = $numMessages;
c57b0888 247}
c57b0888 248do_hook('right_main_bottom');
249sqimap_logout ($imapConnection);
23d6bd09 250
fab3baa6 251echo '</body></html>';
21c3249f 252
978d53dc 253?>