rg=0 fix for vroken forward as attachment
[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['composenew'])) {
74 $composenew = $_GET['composenew'];
75 } else {
76 $composenew = false;
77 }
78
79 if (isset($_GET['checkall'])) {
80 $checkall = $_GET['checkall'];
81 }
82 if (isset($_GET['set_thread'])) {
83 $set_thread = $_GET['set_thread'];
84 }
85 if (isset($_SESSION['lastTargetMailbox'])) {
86 $lastTargetMailbox =$_SESSION['lastTargetMailbox'];
87 }
88
89 if (isset($_GET['session'])) {
90 $session = $_GET['session'];
91 }
92
93
94 /* end of get globals */
95
96
97 /* Open a connection on the imap port (143) */
98
99 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
100
101 if (isset($PG_SHOWALL)) {
102 if ($PG_SHOWALL) {
103 $PG_SHOWNUM=999999;
104 $show_num=$PG_SHOWNUM;
105 sqsession_register($PG_SHOWNUM, 'PG_SHOWNUM');
106 }
107 else {
108 sqsession_unregister('PG_SHOWNUM');
109 unset($PG_SHOWNUM);
110 }
111 }
112 else if( isset( $PG_SHOWNUM ) ) {
113 $show_num = $PG_SHOWNUM;
114 }
115
116 if (isset($newsort) && $newsort != $sort) {
117 setPref($data_dir, $username, 'sort', $newsort);
118 }
119
120
121
122 /* If the page has been loaded without a specific mailbox, */
123 /* send them to the inbox */
124 if (!isset($mailbox)) {
125 $mailbox = 'INBOX';
126 $startMessage = 1;
127 }
128
129
130 if (!isset($startMessage) || ($startMessage == '')) {
131 $startMessage = 1;
132 }
133
134 /* compensate for the UW vulnerability. */
135 if ($imap_server_type == 'uw' && (strstr($mailbox, '../') ||
136 substr($mailbox, 0, 1) == '/')) {
137 $mailbox = 'INBOX';
138 }
139
140 /* decide if we are thread sorting or not */
141 if ($allow_thread_sort == TRUE) {
142 if (isset($set_thread)) {
143 if ($set_thread == 1) {
144 setPref($data_dir, $username, "thread_$mailbox", 1);
145 $thread_sort_messages = '1';
146 }
147 elseif ($set_thread == 2) {
148 setPref($data_dir, $username, "thread_$mailbox", 0);
149 $thread_sort_messages = '0';
150 }
151 }
152 else {
153 $thread_sort_messages = getPref($data_dir, $username, "thread_$mailbox");
154 }
155 }
156 else {
157 $thread_sort_messages = 0;
158 }
159
160 do_hook ('generic_header');
161
162 sqimap_mailbox_select($imapConnection, $mailbox);
163
164 if ($composenew) {
165 $comp_uri = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox).
166 "&amp;session=$session";
167 displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri');", false);
168 } else {
169 displayPageHeader($color, $mailbox);
170 }
171 do_hook('right_main_after_header');
172 if (isset($note)) {
173 echo html_tag( 'div', '<b>' . $note .'</b>', 'center' ) . "<br>\n";
174 }
175
176 if (isset($_SESSION['just_logged_in'])) {
177 $just_logged_in = $_SESSION['just_logged_in'];
178 if ($just_logged_in == true) {
179 $just_logged_in = false;
180
181 if (strlen(trim($motd)) > 0) {
182 echo html_tag( 'table',
183 html_tag( 'tr',
184 html_tag( 'td',
185 html_tag( 'table',
186 html_tag( 'tr',
187 html_tag( 'td', $motd, 'center' )
188 ) ,
189 '', $color[4], 'width="100%" cellpadding="5" cellspacing="1" border="0"' )
190 )
191 ) ,
192 'center', $color[9], 'width="70%" cellpadding="0" cellspacing="3" border="0"' );
193 }
194 }
195 }
196
197 if (isset($newsort)) {
198 $sort = $newsort;
199 sqsession_register($sort, 'sort');
200 }
201
202 /*********************************************************************
203 * Check to see if we can use cache or not. Currently the only time *
204 * when you will not use it is when a link on the left hand frame is *
205 * used. Also check to make sure we actually have the array in the *
206 * registered session data. :) *
207 *********************************************************************/
208 if (! isset($use_mailbox_cache)) {
209 $use_mailbox_cache = 0;
210 }
211
212 if ($use_mailbox_cache && sqsession_is_registered('msgs')) {
213 showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color, $show_num, $use_mailbox_cache);
214 } else {
215 if (sqsession_is_registered('msgs')) {
216 unset($msgs);
217 }
218
219 if (sqsession_is_registered('msort')) {
220 unset($msort);
221 }
222
223 if (sqsession_is_registered('numMessages')) {
224 unset($numMessages);
225 }
226
227 $numMessages = sqimap_get_num_messages ($imapConnection, $mailbox);
228
229 showMessagesForMailbox($imapConnection, $mailbox, $numMessages,
230 $startMessage, $sort, $color, $show_num,
231 $use_mailbox_cache);
232
233 if (sqsession_is_registered('msgs') && isset($msgs)) {
234 sqsession_register($msgs, 'msgs');
235 $_SESSION['msgs'] = $msgs;
236 }
237
238 if (sqsession_is_registered('msort') && isset($msort)) {
239 sqsession_register($msort, 'msort');
240 $_SESSION['msort'] = $msort;
241 }
242
243 sqsession_register($numMessages, 'numMessages');
244 $_SESSION['numMessages'] = $numMessages;
245 }
246 do_hook('right_main_bottom');
247 sqimap_logout ($imapConnection);
248
249 echo '</body></html>';
250
251 ?>