fixed comp_in_new handling
[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 require_once('../src/validate.php');
16 require_once('../functions/imap.php');
17 require_once('../functions/date.php');
18 require_once('../functions/array.php');
19 require_once('../functions/mime.php');
20 require_once('../functions/mailbox_display.php');
21 require_once('../functions/display_messages.php');
22
23 /***********************************************************
24 * incoming variables from URL: *
25 * $sort Direction to sort by date *
26 * values: 0 - descending order *
27 * values: 1 - ascending order *
28 * $startMessage Message to start at *
29 * $mailbox Full Mailbox name *
30 * *
31 * incoming from cookie: *
32 * $username duh *
33 * $key pass *
34 ***********************************************************/
35
36 $bob = getHashedFile($username, $data_dir, "username.pref");
37
38 /* Open a connection on the imap port (143) */
39
40 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
41
42 global $PG_SHOWNUM;
43 if (isset($PG_SHOWALL)) {
44 if ($PG_SHOWALL) {
45 $PG_SHOWNUM=999999;
46 $show_num=$PG_SHOWNUM;
47 session_register('PG_SHOWNUM');
48 }
49 else {
50 session_unregister('PG_SHOWNUM');
51 unset($PG_SHOWNUM);
52 }
53 }
54 else if( isset( $PG_SHOWNUM ) ) {
55 $show_num = $PG_SHOWNUM;
56 }
57
58 if (isset($newsort) && $newsort != $sort) {
59 setPref($data_dir, $username, 'sort', $newsort);
60 }
61
62
63
64 /* If the page has been loaded without a specific mailbox, */
65 /* send them to the inbox */
66 if (!isset($mailbox)) {
67 $mailbox = 'INBOX';
68 $startMessage = 1;
69 }
70
71
72 if (!isset($startMessage) || ($startMessage == '')) {
73 $startMessage = 1;
74 }
75
76 /* compensate for the UW vulnerability. */
77 if ($imap_server_type == 'uw' && (strstr($mailbox, '../') ||
78 substr($mailbox, 0, 1) == '/')) {
79 $mailbox = 'INBOX';
80 }
81
82 /* decide if we are thread sorting or not */
83 global $allow_thread_sort;
84 if ($allow_thread_sort == TRUE) {
85 if (isset($set_thread)) {
86 if ($set_thread == 1) {
87 setPref($data_dir, $username, "thread_$mailbox", 1);
88 $thread_sort_messages = '1';
89 }
90 elseif ($set_thread == 2) {
91 setPref($data_dir, $username, "thread_$mailbox", 0);
92 $thread_sort_messages = '0';
93 }
94 }
95 else {
96 $thread_sort_messages = getPref($data_dir, $username, "thread_$mailbox");
97 }
98 }
99 else {
100 $thread_sort_messages = 0;
101 }
102
103 global $color;
104 if( isset($do_hook) && $do_hook ) {
105 do_hook ("generic_header");
106 }
107
108 sqimap_mailbox_select($imapConnection, $mailbox);
109
110 if (isset($composenew) && $composenew) {
111 $comp_uri = "../src/compose.php?mailbox=". urlencode($mailbox).
112 "&amp;session=$composesession&amp;attachedmessages=true&amp";
113
114 displayPageHeader($color, $mailbox, "comp_in_new(false,'$comp_uri');", false);
115 } else {
116 displayPageHeader($color, $mailbox);
117 }
118 echo "<br>\n";
119
120 do_hook('right_main_after_header');
121 if (isset($note)) {
122 echo "<CENTER><B>$note</B></CENTER><BR>\n";
123 }
124
125 if ($just_logged_in == true) {
126 $just_logged_in = false;
127
128 if (strlen(trim($motd)) > 0) {
129 echo "<br><table align=center width=\"70%\" cellpadding=0 cellspacing=3 border=0 bgcolor=\"$color[9]\">" .
130 '<tr><td>' .
131 "<table width=\"100%\" cellpadding=5 cellspacing=1 border=0 bgcolor=\"$color[4]\">" .
132 "<tr><td align=center>$motd";
133 do_hook('motd');
134 echo '</td></tr>' .
135 '</table>' .
136 '</td></tr></table>';
137 }
138 }
139
140 if (isset($newsort)) {
141 $sort = $newsort;
142 session_register('sort');
143 }
144
145 /*********************************************************************
146 * Check to see if we can use cache or not. Currently the only time *
147 * when you will not use it is when a link on the left hand frame is *
148 * used. Also check to make sure we actually have the array in the *
149 * registered session data. :) *
150 *********************************************************************/
151 if (! isset($use_mailbox_cache)) {
152 $use_mailbox_cache = 0;
153 }
154
155 /* There is a problem with registered vars in 4.1 */
156 /*
157 if( substr( phpversion(), 0, 3 ) == '4.1' ) {
158 $use_mailbox_cache = FALSE;
159 }
160 */
161
162 if ($use_mailbox_cache && session_is_registered('msgs')) {
163 showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color, $show_num, $use_mailbox_cache);
164 } else {
165 if (session_is_registered('msgs')) {
166 unset($msgs);
167 }
168
169 if (session_is_registered('msort')) {
170 unset($msort);
171 }
172
173 if (session_is_registered('numMessages')) {
174 unset($numMessages);
175 }
176
177 $numMessages = sqimap_get_num_messages ($imapConnection, $mailbox);
178
179 showMessagesForMailbox($imapConnection, $mailbox, $numMessages,
180 $startMessage, $sort, $color, $show_num,
181 $use_mailbox_cache);
182
183 if (session_is_registered('msgs') && isset($msgs)) {
184 session_register('msgs');
185 $_SESSION['msgs'] = $msgs;
186 }
187
188 if (session_is_registered('msort') && isset($msort)) {
189 session_register('msort');
190 $_SESSION['msort'] = $msort;
191 }
192
193 session_register('numMessages');
194 $_SESSION['numMessages'] = $numMessages;
195 }
196 do_hook('right_main_bottom');
197 sqimap_logout ($imapConnection);
198
199 echo '</BODY></HTML>';
200
201 ?>