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