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