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