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