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