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