59177427 |
1 | <?php |
c57b0888 |
2 | /** |
3 | * right_main.php |
4 | * |
82d304a0 |
5 | * Copyright (c) 1999-2004 The SquirrelMail Project Team |
c57b0888 |
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 | * |
30967a1e |
11 | * @version $Id$ |
8f6f9ba5 |
12 | * @package squirrelmail |
c57b0888 |
13 | */ |
14 | |
30967a1e |
15 | /** |
16 | * Path for SquirrelMail required files. |
17 | * @ignore |
18 | */ |
86725763 |
19 | define('SM_PATH','../'); |
20 | |
21 | /* SquirrelMail required files. */ |
08185f2a |
22 | require_once(SM_PATH . 'include/validate.php'); |
8650e9e1 |
23 | require_once(SM_PATH . 'functions/global.php'); |
86725763 |
24 | require_once(SM_PATH . 'functions/imap.php'); |
25 | require_once(SM_PATH . 'functions/date.php'); |
86725763 |
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'); |
c97f4825 |
30 | require_once(SM_PATH . 'functions/plugin.php'); |
c57b0888 |
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: * |
c57b0888 |
41 | * $key pass * |
a32985a5 |
42 | * incoming from session: * |
43 | * $username duh * |
44 | * * |
c57b0888 |
45 | ***********************************************************/ |
46 | |
a32985a5 |
47 | |
48 | /* lets get the global vars we may need */ |
1e12d1ff |
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); |
324ac3c5 |
57 | sqgetGlobalVar('targetMailbox', $lastTargetMailbox, SQ_POST); |
1e12d1ff |
58 | sqgetGlobalVar('note', $note, SQ_GET); |
2ffeb7c5 |
59 | sqgetGlobalVar('mail_sent', $mail_sent, SQ_GET); |
1e12d1ff |
60 | |
324ac3c5 |
61 | |
1e12d1ff |
62 | if ( sqgetGlobalVar('startMessage', $temp) ) { |
324ac3c5 |
63 | $startMessage = (int) $temp; |
64 | } else { |
65 | $startMessage = 1; |
a32985a5 |
66 | } |
324ac3c5 |
67 | // sort => srt because of the changed behaviour which can break new behaviour |
68 | if ( sqgetGlobalVar('srt', $temp, SQ_GET) ) { |
69 | $srt = (int) $temp; |
a32985a5 |
70 | } |
324ac3c5 |
71 | |
72 | if ( sqgetGlobalVar('showall', $temp, SQ_GET) ) { |
73 | $showall = (int) $temp; |
a32985a5 |
74 | } |
324ac3c5 |
75 | |
1e12d1ff |
76 | if ( sqgetGlobalVar('checkall', $temp, SQ_GET) ) { |
77 | $checkall = (int) $temp; |
a32985a5 |
78 | } |
a32985a5 |
79 | /* end of get globals */ |
80 | |
81 | |
e0e30169 |
82 | /* Open an imap connection */ |
6f223ace |
83 | |
c57b0888 |
84 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
85 | |
e0e30169 |
86 | $mailbox = (isset($mailbox) && $mailbox) ? $mailbox : 'INBOX'; |
324ac3c5 |
87 | |
e0e30169 |
88 | /* compensate for the UW vulnerability. */ |
89 | if ($imap_server_type == 'uw' && (strstr($mailbox, '../') || |
90 | substr($mailbox, 0, 1) == '/')) { |
91 | $mailbox = 'INBOX'; |
92 | } |
324ac3c5 |
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 | */ |
bdfb67f8 |
98 | |
e372ee8c |
99 | |
324ac3c5 |
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 */ |
a32985a5 |
109 | do_hook ('generic_header'); |
7c612fdd |
110 | |
324ac3c5 |
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'); |
fe6efa94 |
130 | |
fe6efa94 |
131 | |
324ac3c5 |
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; |
26e90c74 |
149 | } |
150 | |
324ac3c5 |
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; |
fe6efa94 |
166 | } |
139b3991 |
167 | |
324ac3c5 |
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); |
139b3991 |
181 | } else { |
324ac3c5 |
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&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; |
139b3991 |
195 | } |
6f223ace |
196 | } else { |
197 | displayPageHeader($color, $mailbox); |
198 | } |
324ac3c5 |
199 | |
c57b0888 |
200 | do_hook('right_main_after_header'); |
2ffeb7c5 |
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 | } |
c57b0888 |
206 | if (isset($note)) { |
fab3baa6 |
207 | echo html_tag( 'div', '<b>' . $note .'</b>', 'center' ) . "<br>\n"; |
c57b0888 |
208 | } |
209 | |
f38b7cf0 |
210 | if ( sqgetGlobalVar('just_logged_in', $just_logged_in, SQ_SESSION) ) { |
a32985a5 |
211 | if ($just_logged_in == true) { |
212 | $just_logged_in = false; |
dd2a2e15 |
213 | sqsession_register($just_logged_in, 'just_logged_in'); |
a32985a5 |
214 | |
215 | if (strlen(trim($motd)) > 0) { |
216 | echo html_tag( 'table', |
217 | html_tag( 'tr', |
c97f4825 |
218 | html_tag( 'td', |
a32985a5 |
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 | } |
23d6bd09 |
228 | } |
c57b0888 |
229 | } |
324ac3c5 |
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 | } |
7c612fdd |
246 | |
c57b0888 |
247 | do_hook('right_main_bottom'); |
248 | sqimap_logout ($imapConnection); |
dcc1cc82 |
249 | echo '</body></html>'; |
250 | |
324ac3c5 |
251 | /* add the mailbox to the cache */ |
252 | $mailbox_cache[$aMailbox['NAME']] = $aMailbox; |
253 | sqsession_register($mailbox_cache,'mailbox_cache'); |
fe6efa94 |
254 | |
dcc1cc82 |
255 | ?> |