- Fix URL for Read Receipts being incorrect in some cases (#1177518).
[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('key', $key, SQ_COOKIE);
34 sqgetGlobalVar('username', $username, SQ_SESSION);
35 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
36 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
37 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
38 sqgetGlobalVar('delayed_errors', $delayed_errors, SQ_SESSION);
39 if (is_array($delayed_errors)) {
40 $oErrorHandler->AssignDelayedErrors($delayed_errors);
41 sqsession_unregister("delayed_errors");
42 }
43 sqgetGlobalVar('mailbox', $mailbox);
44 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION);
45 sqgetGlobalVar('targetMailbox', $lastTargetMailbox, SQ_POST);
46 sqgetGlobalVar('note', $note, SQ_GET);
47 sqgetGlobalVar('mail_sent', $mail_sent, SQ_GET);
48
49
50 if ( sqgetGlobalVar('startMessage', $temp) ) {
51 $startMessage = (int) $temp;
52 } else {
53 $startMessage = 1;
54 }
55 // sort => srt because of the changed behaviour which can break new behaviour
56 if ( sqgetGlobalVar('srt', $temp, SQ_GET) ) {
57 $srt = (int) $temp;
58 }
59
60 if ( sqgetGlobalVar('showall', $temp, SQ_GET) ) {
61 $showall = (int) $temp;
62 }
63
64 if ( sqgetGlobalVar('checkall', $temp, SQ_GET) ) {
65 $checkall = (int) $temp;
66 }
67
68 /* future work */
69 if ( sqgetGlobalVar('account', $account, SQ_GET) ) {
70 $account = (int) $account;
71 } else {
72 $account = 0;
73 }
74
75 /* end of get globals */
76
77
78 /* Open an imap connection */
79
80 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
81
82 $mailbox = (isset($mailbox) && $mailbox) ? $mailbox : 'INBOX';
83
84 /* compensate for the UW vulnerability. */
85 if ($imap_server_type == 'uw' && (strstr($mailbox, '../') ||
86 substr($mailbox, 0, 1) == '/')) {
87 $mailbox = 'INBOX';
88 }
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 */
94
95 $aMailboxPrefSer=getPref($data_dir, $username,'pref_'.$account.'_'.$mailbox);
96 if ($aMailboxPrefSer) {
97 $aMailboxPref = unserialize($aMailboxPrefSer);
98 $aMailboxPref[MBX_PREF_COLUMNS] = $index_order; // index_order contains the columns to show and the order of the columns
99 } else {
100 setUserPref($username,'pref_'.$account.'_'.$mailbox,serialize($default_mailbox_pref));
101 $aMailboxPref = $default_mailbox_pref;
102 }
103 if (isset($srt)) {
104 $aMailboxPref[MBX_PREF_SORT] = (int) $srt;
105 }
106
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
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');
119 $aMailboxPref[MBX_PREF_COLUMNS] = $index_order;
120
121 /**
122 * Replace From => To in case it concerns a draft or sent folder
123 */
124 if (($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
143 foreach ($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);
182
183
184 /**
185 * system wide admin settings and incoming vars.
186 */
187 $aConfig = array(
188 'user' => $username,
189 // incoming vars
190 'offset' => $startMessage // offset in paginator
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 */
197 if (isset($showall)) {
198 $aConfig['showall'] = $showall; // show all messages in a mailbox (paginator is disabled)
199 } else {
200 $showall = false;
201 }
202
203
204 /**
205 * Retrieve the mailbox cache from the session.
206 */
207 sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION);
208
209 /**
210 * Select the mailbox and retrieve the cached info.
211 */
212 $aMailbox = sqm_api_mailbox_select($imapConnection,$account, $mailbox,$aConfig,$aMailboxPref);
213
214 /**
215 * MOVE THIS to a central init section !!!!
216 */
217 if (!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 }
226
227 /*
228 * After initialisation of the mailbox array it's time to handle the FORM data
229 */
230 $sError = handleMessageListForm($imapConnection,$aMailbox);
231 if ($sError) {
232 $note = $sError;
233 }
234
235
236
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 */
241 if (isset($aMailbox['FORWARD_SESSION'])) {
242 if ($compose_new_win) {
243 /* add the mailbox to the cache */
244 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
245 sqsession_register($mailbox_cache,'mailbox_cache');
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();
249 // restart the session. Do not use sqsession_is_active because the session_id
250 // isn't empty after a session_write_close
251 sqsession_start();
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!!!
259 $comp_uri = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox).
260 '&session='.$aMailbox['FORWARD_SESSION'];
261 displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri', $compose_width, $compose_height);", '');
262 } else {
263 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
264 sqsession_register($mailbox_cache,'mailbox_cache');
265
266 // save mailboxstate
267 sqsession_register($aMailbox,'aLastSelectedMailbox');
268 session_write_close();
269 // we have to redirect to the compose page
270 $location = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox).
271 '&session='.$aMailbox['FORWARD_SESSION'];
272 header("Location: $location");
273 exit;
274 }
275 } else {
276 displayPageHeader($color, $mailbox);
277 }
278
279 do_hook('right_main_after_header');
280
281 /* display a message to the user that their mail has been sent */
282 if (isset($mail_sent) && $mail_sent == 'yes') {
283 $note = _("Your Message has been sent.");
284 }
285 if (isset($note)) {
286 $oTemplate->assign('note', htmlspecialchars($note));
287 $oTemplate->display('note.tpl');
288 }
289
290 if ( sqgetGlobalVar('just_logged_in', $just_logged_in, SQ_SESSION) ) {
291 if ($just_logged_in == true) {
292 $just_logged_in = false;
293 sqsession_register($just_logged_in, 'just_logged_in');
294
295 $motd = trim($motd);
296 if (strlen($motd) > 0) {
297 $oTemplate->assign('motd', $motd);
298 $oTemplate->display('motd.tpl');
299 }
300 }
301 }
302
303
304 if ($aMailbox['EXISTS'] > 0) {
305 $aTemplateVars = showMessagesForMailbox($imapConnection,$aMailbox,$aProps,$iError);
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);
322 $oTemplate->assign('icon_theme_path', $icon_theme_path);
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);
327
328 $oTemplate->display('message_list.tpl');
329
330 } else {
331 $oTemplate->display('empty_folder.tpl');
332 }
333
334 do_hook('right_main_bottom');
335 sqimap_logout ($imapConnection);
336 $oTemplate->display('footer.tpl');
337
338
339 /* add the mailbox to the cache */
340 $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
341 sqsession_register($mailbox_cache,'mailbox_cache');