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