01d7634c428b410543a59abc12eaf0e5b3e0f7e3
[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 if( isset( $PG_SHOWNUM ) ) {
43 $show_num = $PG_SHOWNUM;
44 }
45
46 if (isset($newsort) && $newsort != $sort) {
47 setPref($data_dir, $username, 'sort', $newsort);
48 }
49
50
51
52 /* If the page has been loaded without a specific mailbox, */
53 /* send them to the inbox */
54 if (!isset($mailbox)) {
55 $mailbox = 'INBOX';
56 $startMessage = 1;
57 }
58
59
60 if (!isset($startMessage) || ($startMessage == '')) {
61 $startMessage = 1;
62 }
63
64 /* compensate for the UW vulnerability. */
65 if ($imap_server_type == 'uw' && (strstr($mailbox, '../') ||
66 substr($mailbox, 0, 1) == '/')) {
67 $mailbox = 'INBOX';
68 }
69
70 /* decide if we are thread sorting or not */
71 global $allow_thread_sort;
72 if ($allow_thread_sort == TRUE) {
73 if (isset($set_thread)) {
74 if ($set_thread == 1) {
75 setPref($data_dir, $username, "thread_$mailbox", 1);
76 $thread_sort_messages = '1';
77 }
78 elseif ($set_thread == 2) {
79 setPref($data_dir, $username, "thread_$mailbox", 0);
80 $thread_sort_messages = '0';
81 }
82 }
83 else {
84 $thread_sort_messages = getPref($data_dir, $username, "thread_$mailbox");
85 }
86 }
87 else {
88 $thread_sort_messages = 0;
89 }
90
91 global $color;
92 if( isset($do_hook) && $do_hook ) {
93 do_hook ("generic_header");
94 }
95
96 sqimap_mailbox_select($imapConnection, $mailbox);
97
98 if (isset($composenew)) {
99 $width= getPref($username, $data_dir, 'editor_size', 76);
100 if ($width < 65) {
101 $pix_width = 560;
102 } else {
103 $width = (.9*$width);
104 $pix_width = intval($width).'0';
105 }
106 $features = "toolbar=no, width=$pix_width, height=650, scrollbars=yes, resizable=yes target=_blank";
107 $location = 'compose.php?mailbox='. urlencode($mailbox).'&attachedmessages=true&session='."$session";
108 $onload= "window.open(\"$location\",\"compose_window_$session\", \"$features\");";
109 displayPageHeader($color, $mailbox, $onload);
110 } else {
111 displayPageHeader($color, $mailbox);
112 }
113 echo "<br>\n";
114
115 do_hook('right_main_after_header');
116 if (isset($note)) {
117 echo "<CENTER><B>$note</B></CENTER><BR>\n";
118 }
119
120 if ($just_logged_in == true) {
121 $just_logged_in = false;
122
123 if (strlen(trim($motd)) > 0) {
124 echo "<br><table align=center width=\"70%\" cellpadding=0 cellspacing=3 border=0 bgcolor=\"$color[9]\">" .
125 '<tr><td>' .
126 "<table width=\"100%\" cellpadding=5 cellspacing=1 border=0 bgcolor=\"$color[4]\">" .
127 "<tr><td align=center>$motd";
128 do_hook('motd');
129 echo '</td></tr>' .
130 '</table>' .
131 '</td></tr></table>';
132 }
133 }
134
135 if (isset($newsort)) {
136 $sort = $newsort;
137 session_register('sort');
138 }
139
140 /*********************************************************************
141 * Check to see if we can use cache or not. Currently the only time *
142 * when you will not use it is when a link on the left hand frame is *
143 * used. Also check to make sure we actually have the array in the *
144 * registered session data. :) *
145 *********************************************************************/
146 if (! isset($use_mailbox_cache)) {
147 $use_mailbox_cache = 0;
148 }
149
150 /* There is a problem with registered vars in 4.1 */
151 /*
152 if( substr( phpversion(), 0, 3 ) == '4.1' ) {
153 $use_mailbox_cache = FALSE;
154 }
155 */
156
157 if ($use_mailbox_cache && session_is_registered('msgs')) {
158 showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color, $show_num, $use_mailbox_cache);
159 } else {
160 if (session_is_registered('msgs')) {
161 unset($msgs);
162 }
163
164 if (session_is_registered('msort')) {
165 unset($msort);
166 }
167
168 if (session_is_registered('numMessages')) {
169 unset($numMessages);
170 }
171
172 $numMessages = sqimap_get_num_messages ($imapConnection, $mailbox);
173
174 showMessagesForMailbox($imapConnection, $mailbox, $numMessages,
175 $startMessage, $sort, $color, $show_num,
176 $use_mailbox_cache);
177
178 if (session_is_registered('msgs') && isset($msgs)) {
179 session_register('msgs');
180 $_SESSION['msgs'] = $msgs;
181 }
182
183 if (session_is_registered('msort') && isset($msort)) {
184 session_register('msort');
185 $_SESSION['msort'] = $msort;
186 }
187
188 session_register('numMessages');
189 $_SESSION['numMessages'] = $numMessages;
190 }
191 do_hook('right_main_bottom');
192 sqimap_logout ($imapConnection);
193
194 echo '</BODY></HTML>';
195
196 ?>