Fix configtest to use correct PostgreSQL connection function. (#1166228).
[squirrelmail.git] / src / right_main.php
... / ...
CommitLineData
1<?php
2
3/**
4 * right_main.php
5 *
6 * Copyright (c) 1999-2005 The SquirrelMail Project Team
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 *
12 * @version $Id$
13 * @package squirrelmail
14 */
15
16/**
17 * Path for SquirrelMail required files.
18 * @ignore
19 */
20define('SM_PATH','../');
21
22/* SquirrelMail required files. */
23require_once(SM_PATH . 'include/validate.php');
24require_once(SM_PATH . 'functions/global.php');
25require_once(SM_PATH . 'functions/imap.php');
26require_once(SM_PATH . 'functions/date.php');
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');
31require_once(SM_PATH . 'functions/plugin.php');
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: *
42 * $key pass *
43 * incoming from session: *
44 * $username duh *
45 * *
46 ***********************************************************/
47
48
49/* lets get the global vars we may need */
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);
58sqgetGlobalVar('targetMailbox', $lastTargetMailbox, SQ_POST);
59sqgetGlobalVar('note', $note, SQ_GET);
60sqgetGlobalVar('mail_sent', $mail_sent, SQ_GET);
61
62
63if ( sqgetGlobalVar('startMessage', $temp) ) {
64 $startMessage = (int) $temp;
65} else {
66 $startMessage = 1;
67}
68// sort => srt because of the changed behaviour which can break new behaviour
69if ( sqgetGlobalVar('srt', $temp, SQ_GET) ) {
70 $srt = (int) $temp;
71}
72
73if ( sqgetGlobalVar('showall', $temp, SQ_GET) ) {
74 $showall = (int) $temp;
75}
76
77if ( sqgetGlobalVar('checkall', $temp, SQ_GET) ) {
78 $checkall = (int) $temp;
79}
80/* end of get globals */
81
82
83/* Open an imap connection */
84
85$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
86
87$mailbox = (isset($mailbox) && $mailbox) ? $mailbox : 'INBOX';
88
89/* compensate for the UW vulnerability. */
90if ($imap_server_type == 'uw' && (strstr($mailbox, '../') ||
91 substr($mailbox, 0, 1) == '/')) {
92 $mailbox = 'INBOX';
93}
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 */
99
100
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 */
110do_hook ('generic_header');
111
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');
131
132
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;
150}
151
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;
167}
168
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).
180 '&amp;session='.$aMailbox['FORWARD_SESSION'];
181 displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri');", false);
182 } else {
183 // save mailboxstate
184 sqsession_register($aMailbox,'aLastSelectedMailbox');
185 session_write_close();
186 // we have to redirect to the compose page
187 $location = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox).
188 '&amp;session='.$aMailbox['FORWARD_SESSION'];
189 header("Location: $location");
190 exit;
191 }
192} else {
193 displayPageHeader($color, $mailbox);
194}
195
196do_hook('right_main_after_header');
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}
202if (isset($note)) {
203 echo html_tag( 'div', '<b>' . $note .'</b>', 'center' ) . "<br />\n";
204}
205
206if ( sqgetGlobalVar('just_logged_in', $just_logged_in, SQ_SESSION) ) {
207 if ($just_logged_in == true) {
208 $just_logged_in = false;
209 sqsession_register($just_logged_in, 'just_logged_in');
210
211 if (strlen(trim($motd)) > 0) {
212 echo html_tag( 'table',
213 html_tag( 'tr',
214 html_tag( 'td',
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 }
224 }
225}
226if ($aMailbox['EXISTS'] > 0) {
227 showMessagesForMailbox($imapConnection,$aMailbox);
228} else {
229 $string = '<b>' . _("THIS FOLDER IS EMPTY") . '</b>';
230 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
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}
242
243do_hook('right_main_bottom');
244sqimap_logout ($imapConnection);
245echo '</body></html>';
246
247/* add the mailbox to the cache */
248$mailbox_cache[$aMailbox['NAME']] = $aMailbox;
249sqsession_register($mailbox_cache,'mailbox_cache');
250
251?>