Add index.html to Development subdir, rename README.russian_apache to
[squirrelmail.git] / src / right_main.php
1 <?php
2 /**
3 * right_main.php
4 *
5 * Copyright (c) 1999-2005 The SquirrelMail Project Team
6 * Licensed under the GNU GPL. For full terms see the file COPYING.
7 *
8 * This is where the mailboxes are listed. This controls most of what
9 * goes on in SquirrelMail.
10 *
11 * @version $Id$
12 * @package squirrelmail
13 */
14
15 /**
16 * Path for SquirrelMail required files.
17 * @ignore
18 */
19 define('SM_PATH','../');
20
21 /* SquirrelMail required files. */
22 require_once(SM_PATH . 'include/validate.php');
23 require_once(SM_PATH . 'functions/global.php');
24 require_once(SM_PATH . 'functions/imap.php');
25 require_once(SM_PATH . 'functions/date.php');
26 require_once(SM_PATH . 'functions/mime.php');
27 require_once(SM_PATH . 'functions/mailbox_display.php');
28 require_once(SM_PATH . 'functions/display_messages.php');
29 require_once(SM_PATH . 'functions/html.php');
30 require_once(SM_PATH . 'functions/plugin.php');
31
32 //include_once(SM_PATH . 'templates/default/message_list.tpl');
33 include_once(SM_PATH . 'class/template/template.class.php');
34
35
36 /* lets get the global vars we may need */
37 sqgetGlobalVar('key', $key, SQ_COOKIE);
38 sqgetGlobalVar('username', $username, SQ_SESSION);
39 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
40 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
41 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
42
43 sqgetGlobalVar('mailbox', $mailbox);
44 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION);
45 sqgetGlobalVar('targetMailbox', $lastTargetMailbox, SQ_POST);
46 sqgetGlobalVar('note', $note, SQ_GET);
47 sqgetGlobalVar('mail_sent', $mail_sent, SQ_GET);
48
49
50 if ( sqgetGlobalVar('startMessage', $temp) ) {
51 $startMessage = (int) $temp;
52 } else {
53 $startMessage = 1;
54 }
55 // sort => srt because of the changed behaviour which can break new behaviour
56 if ( sqgetGlobalVar('srt', $temp, SQ_GET) ) {
57 $srt = (int) $temp;
58 }
59
60 if ( sqgetGlobalVar('showall', $temp, SQ_GET) ) {
61 $showall = (int) $temp;
62 }
63
64 if ( sqgetGlobalVar('checkall', $temp, SQ_GET) ) {
65 $checkall = (int) $temp;
66 }
67
68 /* future work */
69 if ( sqgetGlobalVar('account', $account, SQ_GET) ) {
70 $account = (int) $account;
71 } else {
72 $account = 0;
73 }
74
75 /* end of get globals */
76
77
78 /* Open an imap connection */
79
80 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
81
82 $mailbox = (isset($mailbox) && $mailbox) ? $mailbox : 'INBOX';
83
84 /* compensate for the UW vulnerability. */
85 if ($imap_server_type == 'uw' && (strstr($mailbox, '../') ||
86 substr($mailbox, 0, 1) == '/')) {
87 $mailbox = 'INBOX';
88 }
89 /**
90 * Set the global settings for a mailbox and merge them with the usersettings
91 * for the mailbox. In the future we can add more mailbox specific preferences
92 * preferences.
93 */
94
95
96 /* not sure if this hook should be capable to alter the global pref array */
97 do_hook ('generic_header');
98
99 $aMailboxPrefSer=getPref($data_dir, $username,'pref_'.$account.'_'.$mailbox);
100 if ($aMailboxPrefSer) {
101 $aMailboxPref = unserialize($aMailboxPrefSer);
102 $aMailboxPref[MBX_PREF_COLUMNS] = $index_order; // index_order contains the columns to show and the order of the columns
103 } else {
104 setUserPref($username,'pref_'.$account.'_'.$mailbox,serialize($default_mailbox_pref));
105 $aMailboxPref = $default_mailbox_pref;
106 }
107 if (isset($srt)) {
108 $aMailboxPref[MBX_PREF_SORT] = (int) $srt;
109 }
110
111 $trash_folder = (isset($trash_folder)) ? $trash_folder : false;
112 $sent_folder = (isset($sent_folder)) ? $sent_folder : false;
113 $draft_folder = (isset($draft_folder)) ? $draft_folder : false;
114
115
116 /**
117 * until there is no per mailbox option screen to set prefs we override
118 * the mailboxprefs by the default ones
119 */
120 $aMailboxPref[MBX_PREF_LIMIT] = (int) $show_num;
121 $aMailboxPref[MBX_PREF_AUTO_EXPUNGE] = (bool) $auto_expunge;
122 $aMailboxPref[MBX_PREF_INTERNALDATE] = (bool) getPref($data_dir, $username, 'internal_date_sort');
123 $aMailboxPref[MBX_PREF_COLUMNS] = $index_order;
124
125 /**
126 * Replace From => To in case it concerns a draft or sent folder
127 */
128 if (($mailbox == $sent_folder || $mailbox == $draft_folder) &&
129 !in_array(SQM_COL_TO,$aMailboxPref[MBX_PREF_COLUMNS])) {
130 $aNewOrder = array(); // nice var name ;)
131 foreach($aMailboxPref[MBX_PREF_COLUMNS] as $iCol) {
132 if ($iCol == SQM_COL_FROM) {
133 $iCol = SQM_COL_TO;
134 }
135 $aNewOrder[] = $iCol;
136 }
137 $aMailboxPref[MBX_PREF_COLUMNS] = $aNewOrder;
138 setUserPref($username,'pref_'.$account.'_'.$mailbox,serialize($aMailboxPref));
139 }
140
141
142
143 /**
144 * Set the config options for the messages list
145 */
146 $aColumns = array(); // contains settings per column. Switch to key -> value based array, order is the order of the array keys
147 foreach ($aMailboxPref[MBX_PREF_COLUMNS] as $iCol) {
148 $aColumns[$iCol] = array();
149 switch ($iCol) {
150 case SQM_COL_SUBJ:
151 if ($truncate_subject) {
152 $aColumns[$iCol]['truncate'] = $truncate_subject;
153 }
154 break;
155 case SQM_COL_FROM:
156 case SQM_COL_TO:
157 case SQM_COL_CC:
158 case SQM_COL_BCC:
159 if ($truncate_sender) {
160 $aColumns[$iCol]['truncate'] = $truncate_sender;
161 }
162 break;
163 }
164 }
165
166 /**
167 * Properties required by showMessagesForMailbox
168 */
169 $aProps = array(
170 'columns' => $aColumns, // columns bound settings
171 'config' => array('alt_index_colors' => $alt_index_colors, // alternating row colors (should be a template thing)
172 'highlight_list' => $message_highlight_list, // row highlighting rules
173 'fancy_index_highlite' => $fancy_index_highlite, // highlight rows on hover or on click -> check
174 'show_flag_buttons' => (isset($show_flag_buttons)) ? $show_flag_buttons : true,
175 'lastTargetMailbox' => (isset($lastTargetMailbox)) ? $lastTargetMailbox : '', // last mailbox where messages are moved/copied to
176 'trash_folder' => $trash_folder,
177 'sent_folder' => $sent_folder,
178 'draft_folder' => $draft_folder,
179 'color' => $color,
180 'enablesort' => true // enable sorting on columns
181 ),
182 'mailbox' => $mailbox,
183 'account' => (isset($account)) ? $account : 0, // future usage if we support multiple imap accounts
184 'module' => 'read_body',
185 'email' => false);
186
187
188 /**
189 * system wide admin settings and incoming vars.
190 */
191 $aConfig = array(
192 'user' => $username,
193 // incoming vars
194 'offset' => $startMessage // offset in paginator
195 );
196 /**
197 * The showall functionality is for the moment added to the config array
198 * to avoid storage of the showall link in the mailbox pref. We could change
199 * this behaviour later and add it to $aMailboxPref instead
200 */
201 if (isset($showall)) {
202 $aConfig['showall'] = $showall; // show all messages in a mailbox (paginator is disabled)
203 } else {
204 $showall = false;
205 }
206
207
208 /**
209 * Retrieve the mailbox cache from the session.
210 */
211 sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION);
212
213 /**
214 * Select the mailbox and retrieve the cached info.
215 */
216 $aMailbox = sqm_api_mailbox_select($imapConnection,$account, $mailbox,$aConfig,$aMailboxPref);
217
218 /**
219 * MOVE THIS to a central init section !!!!
220 */
221 if (!sqgetGlobalVar('align',$align,SQ_SESSION)) {
222 $dir = ( isset( $languages[$squirrelmail_language]['DIR']) ) ? $languages[$squirrelmail_language]['DIR'] : 'ltr';
223 if ( $dir == 'ltr' ) {
224 $align = array('left' => 'left', 'right' => 'right');
225 } else {
226 $align = array('left' => 'right', 'right' => 'left');
227 }
228 sqsession_register($align, 'align');
229 }
230
231 /*
232 * After initialisation of the mailbox array it's time to handle the FORM data
233 */
234 $sError = handleMessageListForm($imapConnection,$aMailbox);
235 if ($sError) {
236 $note = $sError;
237 }
238
239 /**
240 * Which templatedir are we using. TODO, add make a config var of this and make it possible to switch templates
241 */
242 $sTplDir = SM_PATH . 'templates/default/';
243
244
245 /*
246 * If we try to forward messages as attachment we have to open a new window
247 * in case of compose in new window or redirect to compose.php
248 */
249 if (isset($aMailbox['FORWARD_SESSION'])) {
250 if ($compose_new_win) {
251 /* add the mailbox to the cache */
252 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
253 sqsession_register($mailbox_cache,'mailbox_cache');
254 // write the session in order to make sure that the compose window has
255 // access to the composemessages array which is stored in the session
256 session_write_close();
257 // restart the session. Do not use sqsession_is_active because the session_id
258 // isn't empty after a session_write_close
259 session_start();
260 if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
261 $compose_width = '640';
262 }
263 if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
264 $compose_height = '550';
265 }
266 // do not use &amp;, it will break the query string and $session will not be detected!!!
267 $comp_uri = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox).
268 '&session='.$aMailbox['FORWARD_SESSION'];
269 displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri', $compose_width, $compose_height);", '');
270 } else {
271 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
272 sqsession_register($mailbox_cache,'mailbox_cache');
273
274 // save mailboxstate
275 sqsession_register($aMailbox,'aLastSelectedMailbox');
276 session_write_close();
277 // we have to redirect to the compose page
278 $location = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox).
279 '&amp;session='.$aMailbox['FORWARD_SESSION'];
280 header("Location: $location");
281 exit;
282 }
283 } else {
284 displayPageHeader($color, $mailbox);
285 }
286
287 do_hook('right_main_after_header');
288
289 /* display a message to the user that their mail has been sent */
290 if (isset($mail_sent) && $mail_sent == 'yes') {
291 $note = _("Your Message has been sent.");
292 }
293 if (isset($note)) {
294 echo html_tag( 'div', '<b>' . $note .'</b>', 'center' ) . "<br />\n";
295 }
296
297 if ( sqgetGlobalVar('just_logged_in', $just_logged_in, SQ_SESSION) ) {
298 if ($just_logged_in == true) {
299 $just_logged_in = false;
300 sqsession_register($just_logged_in, 'just_logged_in');
301
302 if (strlen(trim($motd)) > 0) {
303 echo html_tag( 'table',
304 html_tag( 'tr',
305 html_tag( 'td',
306 html_tag( 'table',
307 html_tag( 'tr',
308 html_tag( 'td', $motd, 'center' )
309 ) ,
310 '', $color[4], 'width="100%" cellpadding="5" cellspacing="1" border="0"' )
311 )
312 ) ,
313 'center', $color[9], 'width="70%" cellpadding="0" cellspacing="3" border="0"' );
314 }
315 }
316 }
317
318 /**
319 * In the future, move this the the initialisation area
320 */
321
322
323 $oTemplate = new Template($sTplDir);
324
325 if ($aMailbox['EXISTS'] > 0) {
326 $aTemplateVars =& showMessagesForMailbox($imapConnection,$aMailbox,$aProps,$iError);
327 if ($iError) {
328
329 }
330 foreach ($aTemplateVars as $k => $v) {
331 $oTemplate->assign($k, $v);
332 }
333
334 /*
335 * TODO: To many config related vars. We should move all config related vars to
336 * one single associative array and assign that to the template
337 */
338 $oTemplate->assign('page_selector', $page_selector);
339 $oTemplate->assign('page_selector_max', $page_selector_max);
340 $oTemplate->assign('compact_paginator', $compact_paginator);
341 $oTemplate->assign('javascript_on', $javascript_on);
342 $oTemplate->assign('enablesort', (isset($aProps['config']['enablesort'])) ? $aProps['config']['enablesort'] : false);
343 // Aaaaaahhhhhhh FIX ME DO NOT USE the string "none" for a var when you mean the boolean false or null
344 $oTemplate->assign('icon_theme', (isset($icon_theme) && $icon_theme !== 'none') ? $icon_theme : false);
345 $oTemplate->assign('use_icons', (isset($use_icons)) ? $use_icons : false);
346 $oTemplate->assign('aOrder', array_keys($aColumns));
347 $oTemplate->assign('alt_index_colors', isset($alt_index_colors) ? $alt_index_colors: false);
348 $oTemplate->assign('color', $color);
349 $oTemplate->assign('align', $align);
350
351 $oTemplate->display('message_list.tpl');
352
353 } else {
354 $string = '<b>' . _("THIS FOLDER IS EMPTY") . '</b>';
355 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
356 echo ' <tr><td>';
357 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
358 echo ' <tr><td><br />';
359 echo ' <table cellpadding="1" cellspacing="5" align="center" border="0">';
360 echo ' <tr>' . html_tag( 'td', $string."\n", 'left')
361 . '</tr>';
362 echo ' </table>';
363 echo ' <br /></td></tr>';
364 echo ' </table></td></tr>';
365 echo ' </table>';
366 }
367
368 do_hook('right_main_bottom');
369 sqimap_logout ($imapConnection);
370 echo '</body></html>';
371
372 /* add the mailbox to the cache */
373 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
374 sqsession_register($mailbox_cache,'mailbox_cache');
375
376 ?>