00a166e1bcd5fbbf5c1c532367766349e253605d
[squirrelmail.git] / src / right_main.php
1 <?php
2
3 /**
4 * right_main.php
5 *
6 * Copyright (c) 1999-2004 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 * @version $Id$
13 * @package squirrelmail
14 */
15
16 /**
17 * Path for SquirrelMail required files.
18 * @ignore
19 */
20 define('SM_PATH','../');
21
22 /* SquirrelMail required files. */
23 require_once(SM_PATH . 'include/validate.php');
24 require_once(SM_PATH . 'functions/global.php');
25 require_once(SM_PATH . 'functions/imap.php');
26 require_once(SM_PATH . 'functions/date.php');
27 require_once(SM_PATH . 'functions/mime.php');
28 require_once(SM_PATH . 'functions/mailbox_display.php');
29 require_once(SM_PATH . 'functions/display_messages.php');
30 require_once(SM_PATH . 'functions/html.php');
31 require_once(SM_PATH . 'functions/plugin.php');
32
33 /***********************************************************
34 * incoming variables from URL: *
35 * $sort Direction to sort by date *
36 * values: 0 - descending order *
37 * values: 1 - ascending order *
38 * $startMessage Message to start at *
39 * $mailbox Full Mailbox name *
40 * *
41 * incoming from cookie: *
42 * $key pass *
43 * incoming from session: *
44 * $username duh *
45 * *
46 ***********************************************************/
47
48
49 /* lets get the global vars we may need */
50 sqgetGlobalVar('key', $key, SQ_COOKIE);
51 sqgetGlobalVar('username', $username, SQ_SESSION);
52 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
53 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
54 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
55
56 sqgetGlobalVar('mailbox', $mailbox);
57 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION);
58 sqgetGlobalVar('targetMailbox', $lastTargetMailbox, SQ_POST);
59 sqgetGlobalVar('note', $note, SQ_GET);
60 sqgetGlobalVar('mail_sent', $mail_sent, SQ_GET);
61
62
63 if ( sqgetGlobalVar('startMessage', $temp) ) {
64 $startMessage = (int) $temp;
65 } else {
66 $startMessage = 1;
67 }
68 // sort => srt because of the changed behaviour which can break new behaviour
69 if ( sqgetGlobalVar('srt', $temp, SQ_GET) ) {
70 $srt = (int) $temp;
71 }
72
73 if ( sqgetGlobalVar('showall', $temp, SQ_GET) ) {
74 $showall = (int) $temp;
75 }
76
77 if ( sqgetGlobalVar('checkall', $temp, SQ_GET) ) {
78 $checkall = (int) $temp;
79 }
80 /* end of get globals */
81
82
83 /* Open an imap connection */
84
85 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
86
87 $mailbox = (isset($mailbox) && $mailbox) ? $mailbox : 'INBOX';
88
89 /* compensate for the UW vulnerability. */
90 if ($imap_server_type == 'uw' && (strstr($mailbox, '../') ||
91 substr($mailbox, 0, 1) == '/')) {
92 $mailbox = 'INBOX';
93 }
94 /**
95 * Set the global settings for a mailbox and merge them with the usersettings
96 * for the mailbox. In the future we can add more mailbox specific preferences
97 * preferences.
98 */
99
100
101 $aMailboxGlobalPref = array(
102 MBX_PREF_SORT => 0,
103 MBX_PREF_LIMIT => (int) $show_num,
104 MBX_PREF_AUTO_EXPUNGE => (bool) $auto_expunge,
105 MBX_PREF_INTERNALDATE => (bool) getPref($data_dir, $username, 'internal_date_sort')
106 // MBX_PREF_FUTURE => (var) $future
107 );
108
109 /* not sure if this hook should be capable to alter the global pref array */
110 do_hook ('generic_header');
111
112 $aMailboxPrefSer=getPref($data_dir, $username, "pref_$mailbox");
113 if ($aMailboxPrefSer) {
114 $aMailboxPref = unserialize($aMailboxPrefSer);
115 } else {
116 setUserPref($username,"pref_$mailbox",serialize($aMailboxGlobalPref));
117 $aMailboxPref = $aMailboxGlobalPref;
118 }
119 if (isset($srt)) {
120 $aMailboxPref[MBX_PREF_SORT] = (int) $srt;
121 }
122
123
124 /**
125 * until there is no per mailbox option screen to set prefs we override
126 * the mailboxprefs by the default ones
127 */
128 $aMailboxPref[MBX_PREF_LIMIT] = (int) $show_num;
129 $aMailboxPref[MBX_PREF_AUTO_EXPUNGE] = (bool) $auto_expunge;
130 $aMailboxPref[MBX_PREF_INTERNALDATE] = (bool) getPref($data_dir, $username, 'internal_date_sort');
131
132
133 /**
134 * system wide admin settings and incoming vars.
135 */
136 $aConfig = array(
137 'allow_thread_sort' => $allow_thread_sort,
138 'allow_server_sort' => $allow_server_sort,
139 'user' => $username,
140 // incoming vars
141 'offset' => $startMessage
142 );
143 /**
144 * The showall functionality is for the moment added to the config array
145 * to avoid storage of the showall link in the mailbox pref. We could change
146 * this behaviour later and add it to $aMailboxPref instead
147 */
148 if (isset($showall)) {
149 $aConfig['showall'] = $showall;
150 }
151
152 /**
153 * Retrieve the mailbox cache from the session.
154 */
155 sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION);
156
157
158 $aMailbox = sqm_api_mailbox_select($imapConnection,$mailbox,$aConfig,$aMailboxPref);
159
160
161 /*
162 * After initialisation of the mailbox array it's time to handle the FORM data
163 */
164 $sError = handleMessageListForm($imapConnection,$aMailbox);
165 if ($sError) {
166 $note = $sError;
167 }
168
169 /*
170 * If we try to forward messages as attachment we have to open a new window
171 * in case of compose in new window or redirect to compose.php
172 */
173 if (isset($aMailbox['FORWARD_SESSION'])) {
174 if ($compose_new_win) {
175 // write the session in order to make sure that the compose window has
176 // access to the composemessages array which is stored in the session
177 session_write_close();
178 sqsession_is_active();
179 $comp_uri = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox).
180 '&session='.$aMailbox['FORWARD_SESSION'];
181 displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri');", false);
182 } else {
183 // save mailboxstate
184 sqsession_register($aMailbox,'aLastSelectedMailbox');
185 session_write_close();
186 // we have to redirect to the compose page
187 global $PHP_SELF;
188 if (!strpos($PHP_SELF,'?')) {
189 $location = $PHP_SELF.'?mailbox=INBOX&amp;startMessage=1';
190 } else {
191 $location = $PHP_SELF;
192 }
193 $location = set_url_var($location, 'session',$aMailbox['FORWARD_SESSION'], false);
194 header("Location: $location");
195 exit;
196 }
197 } else {
198 displayPageHeader($color, $mailbox);
199 }
200
201 do_hook('right_main_after_header');
202
203 /* display a message to the user that their mail has been sent */
204 if (isset($mail_sent) && $mail_sent == 'yes') {
205 $note = _("Your Message has been sent.");
206 }
207 if (isset($note)) {
208 echo html_tag( 'div', '<b>' . $note .'</b>', 'center' ) . "<br />\n";
209 }
210
211 if ( sqgetGlobalVar('just_logged_in', $just_logged_in, SQ_SESSION) ) {
212 if ($just_logged_in == true) {
213 $just_logged_in = false;
214 sqsession_register($just_logged_in, 'just_logged_in');
215
216 if (strlen(trim($motd)) > 0) {
217 echo html_tag( 'table',
218 html_tag( 'tr',
219 html_tag( 'td',
220 html_tag( 'table',
221 html_tag( 'tr',
222 html_tag( 'td', $motd, 'center' )
223 ) ,
224 '', $color[4], 'width="100%" cellpadding="5" cellspacing="1" border="0"' )
225 )
226 ) ,
227 'center', $color[9], 'width="70%" cellpadding="0" cellspacing="3" border="0"' );
228 }
229 }
230 }
231 if ($aMailbox['EXISTS'] > 0) {
232 showMessagesForMailbox($imapConnection,$aMailbox);
233 } else {
234 $string = '<b>' . _("THIS FOLDER IS EMPTY") . '</b>';
235 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
236 echo ' <tr><td>';
237 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
238 echo ' <tr><td><br />';
239 echo ' <table cellpadding="1" cellspacing="5" align="center" border="0">';
240 echo ' <tr>' . html_tag( 'td', $string."\n", 'left')
241 . '</tr>';
242 echo ' </table>';
243 echo ' <br /></td></tr>';
244 echo ' </table></td></tr>';
245 echo ' </table>';
246 }
247
248 do_hook('right_main_bottom');
249 sqimap_logout ($imapConnection);
250 echo '</body></html>';
251
252 /* add the mailbox to the cache */
253 $mailbox_cache[$aMailbox['NAME']] = $aMailbox;
254 sqsession_register($mailbox_cache,'mailbox_cache');
255
256 ?>