Removing "www." in some links as well as the link to the deprecated feedback page.
[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-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 */
21 include('../include/init.php');
22
23 /* If email_address not set and admin wants us to ask user for it,
24 * redirect to options page. */
25 if ( $ask_user_info && getPref($data_dir, $username,'email_address') == "" ) {
26 header("Location: " . get_location() . "/options.php?optpage=personal");
27 exit;
28 }
29
30 /* SquirrelMail required files. */
31 require_once(SM_PATH . 'functions/imap_asearch.php');
32 require_once(SM_PATH . 'functions/imap_general.php');
33 require_once(SM_PATH . 'functions/imap_messages.php');
34 require_once(SM_PATH . 'functions/date.php');
35 require_once(SM_PATH . 'functions/mime.php');
36 require_once(SM_PATH . 'functions/mailbox_display.php');
37 require_once(SM_PATH . 'functions/compose.php');
38
39 /* lets get the global vars we may need */
40 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
41 sqgetGlobalVar('delayed_errors', $delayed_errors, SQ_SESSION);
42 if (is_array($delayed_errors)) {
43 $oErrorHandler->AssignDelayedErrors($delayed_errors);
44 sqsession_unregister("delayed_errors");
45 }
46 sqgetGlobalVar('mailbox', $mailbox);
47 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION);
48 sqgetGlobalVar('targetMailbox', $lastTargetMailbox, SQ_POST);
49 sqgetGlobalVar('note', $note, SQ_GET);
50 sqgetGlobalVar('mail_sent', $mail_sent, SQ_GET);
51
52
53 if ( sqGetGlobalVarMultiple('startMessage', $temp, 'paginator_submit') ) {
54 $startMessage = (int) $temp;
55 } else {
56 $startMessage = 1;
57 }
58 // sort => srt because of the changed behaviour which can break new behaviour
59 if ( sqgetGlobalVar('srt', $temp, SQ_GET) ) {
60 $srt = (int) $temp;
61 }
62
63 if ( sqgetGlobalVar('showall', $temp, SQ_GET) ) {
64 $showall = (int) $temp;
65 }
66
67 if ( sqgetGlobalVar('checkall', $temp, SQ_GET) ) {
68 $checkall = (int) $temp;
69 }
70
71 /* future work */
72 if ( sqgetGlobalVar('account', $account, SQ_GET) ) {
73 $account = (int) $account;
74 } else {
75 $account = 0;
76 }
77
78 /* end of get globals */
79
80
81 /* Open an imap connection */
82
83 $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0);
84
85 $mailbox = (isset($mailbox) && $mailbox) ? $mailbox : 'INBOX';
86
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 */
92
93 $aMailboxPrefSer=getPref($data_dir, $username,'pref_'.$account.'_'.$mailbox);
94 if ($aMailboxPrefSer) {
95 $aMailboxPref = unserialize($aMailboxPrefSer);
96 $aMailboxPref[MBX_PREF_COLUMNS] = $index_order; // index_order contains the columns to show and the order of the columns
97 } else {
98 setUserPref($username,'pref_'.$account.'_'.$mailbox,serialize($default_mailbox_pref));
99 $aMailboxPref = $default_mailbox_pref;
100 }
101 if (isset($srt)) {
102 $aMailboxPref[MBX_PREF_SORT] = (int) $srt;
103 }
104
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
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');
117 $aMailboxPref[MBX_PREF_COLUMNS] = $index_order;
118
119 /**
120 * Replace From => To in case it concerns a draft or sent folder
121 */
122 if (($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
141 foreach ($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);
180
181
182 /**
183 * system wide admin settings and incoming vars.
184 */
185 $aConfig = array(
186 'user' => $username,
187 // incoming vars
188 'offset' => $startMessage // offset in paginator
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 */
195 if (isset($showall)) {
196 $aConfig['showall'] = $showall; // show all messages in a mailbox (paginator is disabled)
197 } else {
198 $showall = false;
199 }
200
201
202 /**
203 * Retrieve the mailbox cache from the session.
204 */
205 sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION);
206
207 /**
208 * Select the mailbox and retrieve the cached info.
209 */
210 $aMailbox = sqm_api_mailbox_select($imapConnection,$account, $mailbox,$aConfig,$aMailboxPref);
211
212 /**
213 * MOVE THIS to a central init section !!!!
214 */
215 if (!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 }
224
225 /*
226 * After initialisation of the mailbox array it's time to handle the FORM data
227 */
228 $sError = handleMessageListForm($imapConnection,$aMailbox);
229 if ($sError) {
230 $note = $sError;
231 }
232
233
234
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 */
239 if (isset($aMailbox['FORWARD_SESSION'])) {
240 if ($compose_new_win) {
241 /* add the mailbox to the cache */
242 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
243 sqsession_register($mailbox_cache,'mailbox_cache');
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();
247 // restart the session. Do not use sqsession_is_active because the session_id
248 // isn't empty after a session_write_close
249 sqsession_start();
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!!!
257 $comp_uri = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox).
258 '&session='.urlencode($aMailbox['FORWARD_SESSION']);
259 displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri', $compose_width, $compose_height);", '');
260 } else {
261 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
262 sqsession_register($mailbox_cache,'mailbox_cache');
263
264 // save mailboxstate
265 sqsession_register($aMailbox,'aLastSelectedMailbox');
266 session_write_close();
267 // we have to redirect to the compose page
268 $location = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox).
269 '&session='.$aMailbox['FORWARD_SESSION'];
270 header("Location: $location");
271 exit;
272 }
273 } else {
274 displayPageHeader($color, $mailbox);
275 }
276
277 do_hook('right_main_after_header', $null);
278
279 /* display a message to the user that their mail has been sent */
280 if (isset($mail_sent) && $mail_sent == 'yes') {
281 $note = _("Your mail has been sent.");
282 }
283 if (isset($note)) {
284 $oTemplate->assign('note', htmlspecialchars($note));
285 $oTemplate->display('note.tpl');
286 }
287
288 if ( sqgetGlobalVar('just_logged_in', $just_logged_in, SQ_SESSION) ) {
289 if ($just_logged_in == true) {
290 $just_logged_in = false;
291 sqsession_register($just_logged_in, 'just_logged_in');
292
293 $motd = trim($motd);
294 if (strlen($motd) > 0) {
295 $oTemplate->assign('motd', $motd);
296 $oTemplate->display('motd.tpl');
297 }
298 }
299 }
300
301
302 if ($aMailbox['EXISTS'] > 0) {
303 $aTemplateVars = showMessagesForMailbox($imapConnection,$aMailbox,$aProps,$iError);
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);
318 $oTemplate->assign('javascript_on', checkForJavascript());
319 $oTemplate->assign('base_uri', sqm_baseuri());
320 $oTemplate->assign('enablesort', (isset($aProps['config']['enablesort'])) ? $aProps['config']['enablesort'] : false);
321 $oTemplate->assign('icon_theme_path', $icon_theme_path);
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);
326
327 $oTemplate->display('message_list.tpl');
328
329 } else {
330 $oTemplate->display('empty_folder.tpl');
331 }
332
333 do_hook('right_main_bottom', $null);
334 sqimap_logout ($imapConnection);
335 $oTemplate->display('footer.tpl');
336
337
338 /* add the mailbox to the cache */
339 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
340 sqsession_register($mailbox_cache,'mailbox_cache');