Templates
[squirrelmail.git] / src / right_main.php
CommitLineData
59177427 1<?php
134e4174 2
c57b0888 3/**
4 * right_main.php
5 *
6c84ba1e 6 * Copyright (c) 1999-2005 The SquirrelMail Project Team
c57b0888 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This is where the mailboxes are listed. This controls most of what
10 * goes on in SquirrelMail.
11 *
30967a1e 12 * @version $Id$
8f6f9ba5 13 * @package squirrelmail
c57b0888 14 */
15
30967a1e 16/**
17 * Path for SquirrelMail required files.
18 * @ignore
19 */
86725763 20define('SM_PATH','../');
21
22/* SquirrelMail required files. */
08185f2a 23require_once(SM_PATH . 'include/validate.php');
8650e9e1 24require_once(SM_PATH . 'functions/global.php');
86725763 25require_once(SM_PATH . 'functions/imap.php');
26require_once(SM_PATH . 'functions/date.php');
86725763 27require_once(SM_PATH . 'functions/mime.php');
28require_once(SM_PATH . 'functions/mailbox_display.php');
29require_once(SM_PATH . 'functions/display_messages.php');
30require_once(SM_PATH . 'functions/html.php');
c97f4825 31require_once(SM_PATH . 'functions/plugin.php');
c57b0888 32
33/***********************************************************
34 * incoming variables from URL: *
35 * $sort Direction to sort by date *
36 * values: 0 - descending order *
37 * values: 1 - ascending order *
38 * $startMessage Message to start at *
39 * $mailbox Full Mailbox name *
40 * *
41 * incoming from cookie: *
c57b0888 42 * $key pass *
a32985a5 43 * incoming from session: *
44 * $username duh *
45 * *
c57b0888 46 ***********************************************************/
47
a32985a5 48
49/* lets get the global vars we may need */
1e12d1ff 50sqgetGlobalVar('key', $key, SQ_COOKIE);
51sqgetGlobalVar('username', $username, SQ_SESSION);
52sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
53sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
54sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
55
56sqgetGlobalVar('mailbox', $mailbox);
57sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION);
324ac3c5 58sqgetGlobalVar('targetMailbox', $lastTargetMailbox, SQ_POST);
1e12d1ff 59sqgetGlobalVar('note', $note, SQ_GET);
2ffeb7c5 60sqgetGlobalVar('mail_sent', $mail_sent, SQ_GET);
1e12d1ff 61
324ac3c5 62
1e12d1ff 63if ( sqgetGlobalVar('startMessage', $temp) ) {
324ac3c5 64 $startMessage = (int) $temp;
65} else {
66 $startMessage = 1;
a32985a5 67}
324ac3c5 68// sort => srt because of the changed behaviour which can break new behaviour
69if ( sqgetGlobalVar('srt', $temp, SQ_GET) ) {
70 $srt = (int) $temp;
a32985a5 71}
324ac3c5 72
73if ( sqgetGlobalVar('showall', $temp, SQ_GET) ) {
74 $showall = (int) $temp;
a32985a5 75}
324ac3c5 76
1e12d1ff 77if ( sqgetGlobalVar('checkall', $temp, SQ_GET) ) {
78 $checkall = (int) $temp;
a32985a5 79}
a32985a5 80/* end of get globals */
81
82
e0e30169 83/* Open an imap connection */
6f223ace 84
c57b0888 85$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
86
e0e30169 87$mailbox = (isset($mailbox) && $mailbox) ? $mailbox : 'INBOX';
324ac3c5 88
e0e30169 89/* compensate for the UW vulnerability. */
90if ($imap_server_type == 'uw' && (strstr($mailbox, '../') ||
91 substr($mailbox, 0, 1) == '/')) {
92 $mailbox = 'INBOX';
93}
324ac3c5 94/**
95 * Set the global settings for a mailbox and merge them with the usersettings
96 * for the mailbox. In the future we can add more mailbox specific preferences
97 * preferences.
98 */
bdfb67f8 99
e372ee8c 100
324ac3c5 101$aMailboxGlobalPref = array(
102 MBX_PREF_SORT => 0,
103 MBX_PREF_LIMIT => (int) $show_num,
104 MBX_PREF_AUTO_EXPUNGE => (bool) $auto_expunge,
105 MBX_PREF_INTERNALDATE => (bool) getPref($data_dir, $username, 'internal_date_sort')
106 // MBX_PREF_FUTURE => (var) $future
107 );
108
109/* not sure if this hook should be capable to alter the global pref array */
a32985a5 110do_hook ('generic_header');
7c612fdd 111
324ac3c5 112$aMailboxPrefSer=getPref($data_dir, $username, "pref_$mailbox");
113if ($aMailboxPrefSer) {
114 $aMailboxPref = unserialize($aMailboxPrefSer);
115} else {
116 setUserPref($username,"pref_$mailbox",serialize($aMailboxGlobalPref));
117 $aMailboxPref = $aMailboxGlobalPref;
118}
119if (isset($srt)) {
120 $aMailboxPref[MBX_PREF_SORT] = (int) $srt;
121}
122
123
124/**
125 * until there is no per mailbox option screen to set prefs we override
126 * the mailboxprefs by the default ones
127 */
128$aMailboxPref[MBX_PREF_LIMIT] = (int) $show_num;
129$aMailboxPref[MBX_PREF_AUTO_EXPUNGE] = (bool) $auto_expunge;
130$aMailboxPref[MBX_PREF_INTERNALDATE] = (bool) getPref($data_dir, $username, 'internal_date_sort');
fe6efa94 131
fe6efa94 132
324ac3c5 133/**
134 * system wide admin settings and incoming vars.
135 */
136$aConfig = array(
137 'allow_thread_sort' => $allow_thread_sort,
138 'allow_server_sort' => $allow_server_sort,
139 'user' => $username,
140 // incoming vars
141 'offset' => $startMessage
142 );
143/**
144 * The showall functionality is for the moment added to the config array
145 * to avoid storage of the showall link in the mailbox pref. We could change
146 * this behaviour later and add it to $aMailboxPref instead
147 */
148if (isset($showall)) {
149 $aConfig['showall'] = $showall;
26e90c74 150}
151
324ac3c5 152/**
153 * Retrieve the mailbox cache from the session.
154 */
155sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION);
156
157
158$aMailbox = sqm_api_mailbox_select($imapConnection,$mailbox,$aConfig,$aMailboxPref);
159
160
161/*
162 * After initialisation of the mailbox array it's time to handle the FORM data
163 */
164$sError = handleMessageListForm($imapConnection,$aMailbox);
165if ($sError) {
166 $note = $sError;
fe6efa94 167}
139b3991 168
324ac3c5 169/*
170 * If we try to forward messages as attachment we have to open a new window
171 * in case of compose in new window or redirect to compose.php
172 */
173if (isset($aMailbox['FORWARD_SESSION'])) {
174 if ($compose_new_win) {
175 // write the session in order to make sure that the compose window has
176 // access to the composemessages array which is stored in the session
177 session_write_close();
178 sqsession_is_active();
179 $comp_uri = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox).
c435f076 180 '&amp;session='.$aMailbox['FORWARD_SESSION'];
324ac3c5 181 displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri');", false);
139b3991 182 } else {
324ac3c5 183 // save mailboxstate
184 sqsession_register($aMailbox,'aLastSelectedMailbox');
185 session_write_close();
186 // we have to redirect to the compose page
dc2db59a 187 $location = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox).
c435f076 188 '&amp;session='.$aMailbox['FORWARD_SESSION'];
324ac3c5 189 header("Location: $location");
190 exit;
139b3991 191 }
192} else {
6f223ace 193 displayPageHeader($color, $mailbox);
194}
324ac3c5 195
c57b0888 196do_hook('right_main_after_header');
2ffeb7c5 197
198/* display a message to the user that their mail has been sent */
199if (isset($mail_sent) && $mail_sent == 'yes') {
200 $note = _("Your Message has been sent.");
201}
c57b0888 202if (isset($note)) {
3c621ba1 203 echo html_tag( 'div', '<b>' . $note .'</b>', 'center' ) . "<br />\n";
c57b0888 204}
205
f38b7cf0 206if ( sqgetGlobalVar('just_logged_in', $just_logged_in, SQ_SESSION) ) {
a32985a5 207 if ($just_logged_in == true) {
208 $just_logged_in = false;
dd2a2e15 209 sqsession_register($just_logged_in, 'just_logged_in');
a32985a5 210
211 if (strlen(trim($motd)) > 0) {
212 echo html_tag( 'table',
213 html_tag( 'tr',
c97f4825 214 html_tag( 'td',
a32985a5 215 html_tag( 'table',
216 html_tag( 'tr',
217 html_tag( 'td', $motd, 'center' )
218 ) ,
219 '', $color[4], 'width="100%" cellpadding="5" cellspacing="1" border="0"' )
220 )
221 ) ,
222 'center', $color[9], 'width="70%" cellpadding="0" cellspacing="3" border="0"' );
223 }
23d6bd09 224 }
c57b0888 225}
324ac3c5 226if ($aMailbox['EXISTS'] > 0) {
227 showMessagesForMailbox($imapConnection,$aMailbox);
228} else {
229 $string = '<b>' . _("THIS FOLDER IS EMPTY") . '</b>';
3c621ba1 230 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
324ac3c5 231 echo ' <tr><td>';
232 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
233 echo ' <tr><td><br />';
234 echo ' <table cellpadding="1" cellspacing="5" align="center" border="0">';
235 echo ' <tr>' . html_tag( 'td', $string."\n", 'left')
236 . '</tr>';
237 echo ' </table>';
238 echo ' <br /></td></tr>';
239 echo ' </table></td></tr>';
240 echo ' </table>';
241}
7c612fdd 242
c57b0888 243do_hook('right_main_bottom');
244sqimap_logout ($imapConnection);
dcc1cc82 245echo '</body></html>';
246
324ac3c5 247/* add the mailbox to the cache */
248$mailbox_cache[$aMailbox['NAME']] = $aMailbox;
249sqsession_register($mailbox_cache,'mailbox_cache');
fe6efa94 250
3c621ba1 251?>