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