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