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