59177427 |
1 | <?php |
3302d0d4 |
2 | /** |
23d6bd09 |
3 | * mailbox_display.php |
4 | * |
5 | * Copyright (c) 1999-2001 The Squirrelmail Development Team |
6 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
7 | * |
8 | * This contains functions that display mailbox information, such as the |
9 | * table row that has sender, date, subject, etc... |
10 | * |
11 | * $Id$ |
12 | */ |
a4c2cd49 |
13 | |
f435778e |
14 | if (defined('mailbox_display_php')) |
15 | return; |
16 | define('mailbox_display_php', true); |
d068c0ec |
17 | |
f7b1b3b1 |
18 | define('PG_SEL_MAX', 10); /* Default value for page_selector_max. */ |
f1e6f580 |
19 | |
23d6bd09 |
20 | function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $start_msg, $where, $what) { |
66289791 |
21 | global $checkall; |
af9404d7 |
22 | global $color, $msgs, $msort; |
f7b1b3b1 |
23 | global $sent_folder, $draft_folder; |
9d157cec |
24 | global $message_highlight_list; |
8e265988 |
25 | global $index_order; |
cbdc5621 |
26 | |
ac53fb56 |
27 | $color_string = $color[4]; |
28 | if ($GLOBALS['alt_index_colors']) { |
29 | if (!isset($GLOBALS["row_count"])) { |
30 | $GLOBALS["row_count"] = 0; |
31 | } |
32 | $GLOBALS["row_count"]++; |
33 | if ($GLOBALS["row_count"] % 2) { |
f136c965 |
34 | if (!isset($color[12])) $color[12] = '#EAEAEA'; |
ac53fb56 |
35 | $color_string = $color[12]; |
36 | } |
b3b103cb |
37 | } |
0d455368 |
38 | $msg = $msgs[$key]; |
d92b6f31 |
39 | |
a91b14d8 |
40 | $senderName = htmlentities(sqimap_find_displayable_name($msg['FROM'])); |
f136c965 |
41 | if( $mailbox == _("None") ) { |
42 | // $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
43 | $boxes = sqimap_mailbox_list($imapConnection); |
44 | // sqimap_logout($imapConnection); |
45 | $mailbox = $boxes[0]['unformatted']; |
46 | unset( $boxes ); |
d6def997 |
47 | } |
05207a68 |
48 | $urlMailbox = urlencode($mailbox); |
f93c93b9 |
49 | $subject = processSubject($msg['SUBJECT']); |
926da13e |
50 | echo "<TR>\n"; |
b60b58f9 |
51 | |
f7b1b3b1 |
52 | if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) { |
d6def997 |
53 | $flag = "<font color=$color[2]>"; |
54 | $flag_end = '</font>'; |
f7b1b3b1 |
55 | } else { |
90bc0b93 |
56 | $flag = ''; |
6edca885 |
57 | $flag_end = ''; |
245a6892 |
58 | } |
f7b1b3b1 |
59 | if (!isset($msg['FLAG_SEEN']) || ($msg['FLAG_SEEN'] == false)) { |
d6def997 |
60 | $bold = '<b>'; |
61 | $bold_end = '</b>'; |
f7b1b3b1 |
62 | } else { |
90bc0b93 |
63 | $bold = ''; |
6edca885 |
64 | $bold_end = ''; |
245a6892 |
65 | } |
f7b1b3b1 |
66 | |
67 | if (($mailbox == $sent_folder) || ($mailbox == $draft_folder)) { |
d6def997 |
68 | $italic = '<i>'; |
69 | $italic_end = '</i>'; |
f7b1b3b1 |
70 | } else { |
90bc0b93 |
71 | $italic = ''; |
6edca885 |
72 | $italic_end = ''; |
245a6892 |
73 | } |
f7b1b3b1 |
74 | |
75 | if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) { |
d6def997 |
76 | $fontstr = "<font color=\"$color[9]\">"; |
77 | $fontstr_end = '</font>'; |
f7b1b3b1 |
78 | } else { |
90bc0b93 |
79 | $fontstr = ''; |
6edca885 |
80 | $fontstr_end = ''; |
245a6892 |
81 | } |
b60b58f9 |
82 | |
9d157cec |
83 | for ($i=0; $i < count($message_highlight_list); $i++) { |
90bc0b93 |
84 | if (trim($message_highlight_list[$i]['value']) != '') { |
85 | if ($message_highlight_list[$i]['match_type'] == 'to_cc') { |
86 | if (strpos('^^'.strtolower($msg['TO']), strtolower($message_highlight_list[$i]['value'])) || strpos('^^'.strtolower($msg['CC']), strtolower($message_highlight_list[$i]['value']))) { |
87 | $hlt_color = $message_highlight_list[$i]['color']; |
d059be8f |
88 | continue; |
89 | } |
90bc0b93 |
90 | } else if (strpos('^^'.strtolower($msg[strtoupper($message_highlight_list[$i]['match_type'])]),strtolower($message_highlight_list[$i]['value']))) { |
91 | $hlt_color = $message_highlight_list[$i]['color']; |
1195c340 |
92 | continue; |
b60b58f9 |
93 | } |
d059be8f |
94 | } |
b60b58f9 |
95 | } |
96 | |
f7b1b3b1 |
97 | if (!isset($hlt_color)) { |
98 | $hlt_color = $color_string; |
99 | } |
1809bad8 |
100 | |
101 | if ($where && $what) { |
90bc0b93 |
102 | $search_stuff = '&where='.urlencode($where).'&what='.urlencode($what); |
1809bad8 |
103 | } |
66289791 |
104 | |
f7b1b3b1 |
105 | $checked = ($checkall == 1 ?' checked' : ''); |
d6def997 |
106 | |
8e265988 |
107 | for ($i=1; $i <= count($index_order); $i++) { |
108 | switch ($index_order[$i]) { |
f7b1b3b1 |
109 | case 1: /* checkbox */ |
20cd8abb |
110 | echo " <td bgcolor=$hlt_color align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n"; |
8e265988 |
111 | break; |
f7b1b3b1 |
112 | case 2: /* from */ |
20cd8abb |
113 | echo " <td bgcolor=$hlt_color>$italic$bold$flag$fontstr$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n"; |
8e265988 |
114 | break; |
f7b1b3b1 |
115 | case 3: /* date */ |
20cd8abb |
116 | echo " <td nowrap bgcolor=$hlt_color><center>$bold$flag$fontstr".$msg["DATE_STRING"]."$fontstr_end$flag_end$bold_end</center></td>\n"; |
8e265988 |
117 | break; |
f7b1b3b1 |
118 | case 4: /* subject */ |
7e73c6be |
119 | echo " <td bgcolor=$hlt_color>$bold"; |
6edca885 |
120 | if (! isset($search_stuff)) { $search_stuff = ''; } |
23d6bd09 |
121 | echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$start_msg&show_more=0$search_stuff\""; |
23fd3c8e |
122 | do_hook("subject_link"); |
77f70304 |
123 | |
8c16ad63 |
124 | if ($subject != $msg['SUBJECT']) { |
feb563a6 |
125 | $title = get_html_translation_table(HTML_SPECIALCHARS); |
126 | $title = array_flip($title); |
127 | $title = strtr($msg['SUBJECT'], $title); |
128 | $title = str_replace('"', "''", $title); |
8c16ad63 |
129 | echo " title=\"$title\""; |
feb563a6 |
130 | } |
131 | echo ">$flag$subject$flag_end</a>$bold_end</td>\n"; |
8e265988 |
132 | break; |
f7b1b3b1 |
133 | case 5: /* flags */ |
9db5f5fc |
134 | $stuff = false; |
20cd8abb |
135 | echo " <td bgcolor=$hlt_color align=center nowrap><b><small>\n"; |
d6def997 |
136 | if (isset($msg['FLAG_ANSWERED']) && |
6edca885 |
137 | $msg['FLAG_ANSWERED'] == true) { |
9db5f5fc |
138 | echo "A\n"; |
139 | $stuff = true; |
8ae331c2 |
140 | } |
5ae0173b |
141 | if (ereg('(5)',substr($msg['PRIORITY'],0,1))) { |
142 | echo "<font color=$color[8]>v</font>\n"; |
143 | $stuff = true; |
144 | } |
90bc0b93 |
145 | if ($msg['TYPE0'] == 'multipart') { |
9db5f5fc |
146 | echo "+\n"; |
147 | $stuff = true; |
8ae331c2 |
148 | } |
90bc0b93 |
149 | if (ereg('(1|2)',substr($msg['PRIORITY'],0,1))) { |
9db5f5fc |
150 | echo "<font color=$color[1]>!</font>\n"; |
151 | $stuff = true; |
152 | } |
90bc0b93 |
153 | if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) { |
f9b3e5d9 |
154 | echo "<font color=\"$color[1]\">D</font>\n"; |
155 | $stuff = true; |
156 | } |
8ae331c2 |
157 | |
9db5f5fc |
158 | if (!$stuff) echo " \n"; |
159 | echo "</small></b></td>\n"; |
8e265988 |
160 | break; |
f7b1b3b1 |
161 | case 6: /* size */ |
20cd8abb |
162 | echo " <td bgcolor=$hlt_color>$bold$fontstr".show_readable_size($msg['SIZE'])."$fontstr_end$bold_end</td>\n"; |
8e265988 |
163 | break; |
164 | } |
165 | } |
7151188f |
166 | echo "</tr>\n"; |
926da13e |
167 | } |
168 | |
169 | /** |
f7b1b3b1 |
170 | * This function loops through a group of messages in the mailbox |
171 | * and shows them to the user. |
172 | */ |
173 | function showMessagesForMailbox |
23d6bd09 |
174 | ($imapConnection, $mailbox, $num_msgs, $start_msg, |
f7b1b3b1 |
175 | $sort, $color,$show_num, $use_cache) { |
5b6ae78a |
176 | global $msgs, $msort; |
f7b1b3b1 |
177 | global $sent_folder, $draft_folder; |
9d157cec |
178 | global $message_highlight_list; |
a3432f47 |
179 | global $auto_expunge; |
180 | |
f7b1b3b1 |
181 | /* If autoexpunge is turned on, then do it now. */ |
182 | if ($auto_expunge == true) { |
183 | sqimap_mailbox_expunge($imapConnection, $mailbox, false); |
184 | } |
0d455368 |
185 | sqimap_mailbox_select($imapConnection, $mailbox); |
61a4ac35 |
186 | |
f7b1b3b1 |
187 | $issent = (($mailbox == $sent_folder) || ($mailbox == $draft_folder)); |
5b6ae78a |
188 | if (!$use_cache) { |
f7b1b3b1 |
189 | /* If it is sorted... */ |
23d6bd09 |
190 | if ($num_msgs >= 1) { |
0d455368 |
191 | if ($sort < 6) { |
23d6bd09 |
192 | $id = range(1, $num_msgs); |
0d455368 |
193 | } else { |
194 | // if it's not sorted |
23d6bd09 |
195 | if ($start_msg + ($show_num - 1) < $num_msgs) { |
196 | $end_msg = $start_msg + ($show_num-1); |
0d455368 |
197 | } else { |
23d6bd09 |
198 | $end_msg = $num_msgs; |
0d455368 |
199 | } |
b60b58f9 |
200 | |
23d6bd09 |
201 | if ($end_msg < $start_msg) { |
202 | $start_msg = $start_msg - $show_num; |
203 | if ($start_msg < 1) { |
204 | $start_msg = 1; |
f7b1b3b1 |
205 | } |
0d455368 |
206 | } |
207 | |
23d6bd09 |
208 | $real_startMessage = $num_msgs - $start_msg + 1; |
209 | $real_endMessage = $num_msgs - $start_msg - $show_num + 2; |
f7b1b3b1 |
210 | if ($real_endMessage <= 0) { |
211 | $real_endMessage = 1; |
212 | } |
91f68e94 |
213 | $id = array_reverse(range($real_endMessage, $real_startMessage)); |
214 | } |
b60b58f9 |
215 | |
91f68e94 |
216 | $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent); |
217 | $flags = sqimap_get_flags_list($imapConnection, $id, $issent); |
218 | foreach ($msgs_list as $hdr) { |
219 | $from[] = $hdr->from; |
220 | $date[] = $hdr->date; |
221 | $subject[] = $hdr->subject; |
222 | $to[] = $hdr->to; |
223 | $priority[] = $hdr->priority; |
224 | $cc[] = $hdr->cc; |
225 | $size[] = $hdr->size; |
226 | $type[] = $hdr->type0; |
b60b58f9 |
227 | } |
5b6ae78a |
228 | } |
b60b58f9 |
229 | |
5b6ae78a |
230 | $j = 0; |
0d455368 |
231 | if ($sort == 6) { |
23d6bd09 |
232 | $end = $start_msg + $show_num - 1; |
233 | if ($num_msgs < $show_num) { |
234 | $end_loop = $num_msgs; |
235 | } else if ($end > $num_msgs) { |
236 | $end_loop = $num_msgs - $start_msg + 1; |
f7b1b3b1 |
237 | } else { |
238 | $end_loop = $show_num; |
239 | } |
0d455368 |
240 | } else { |
23d6bd09 |
241 | $end = $num_msgs; |
cd928157 |
242 | $end_loop = $end; |
0d455368 |
243 | } |
f7b1b3b1 |
244 | |
cd928157 |
245 | while ($j < $end_loop) { |
246 | if (isset($date[$j])) { |
247 | $date[$j] = ereg_replace(' ', ' ', $date[$j]); |
248 | $tmpdate = explode(' ', trim($date[$j])); |
249 | } else { |
250 | $tmpdate = $date = array("","","","","",""); |
251 | } |
90bc0b93 |
252 | |
253 | $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate); |
254 | $messages[$j]['DATE_STRING'] = getDateString($messages[$j]['TIME_STAMP']); |
255 | $messages[$j]['ID'] = $id[$j]; |
256 | $messages[$j]['FROM'] = decodeHeader($from[$j]); |
257 | $messages[$j]['FROM-SORT'] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j]))); |
258 | $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]); |
259 | $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j])); |
260 | $messages[$j]['TO'] = decodeHeader($to[$j]); |
261 | $messages[$j]['PRIORITY'] = $priority[$j]; |
262 | $messages[$j]['CC'] = $cc[$j]; |
263 | $messages[$j]['SIZE'] = $size[$j]; |
264 | $messages[$j]['TYPE0'] = $type[$j]; |
e9f8ea4e |
265 | |
266 | # fix SUBJECT-SORT to remove Re: |
0d455368 |
267 | $re_abbr = # Add more here! |
90bc0b93 |
268 | 'vedr|sv|' . # Danish |
269 | 're|aw'; # English |
f1e6f580 |
270 | |
271 | if (eregi( "^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs)) |
0d455368 |
272 | $messages[$j]['SUBJECT-SORT'] = $regs[2]; |
b60b58f9 |
273 | |
5b6ae78a |
274 | $num = 0; |
275 | while ($num < count($flags[$j])) { |
90bc0b93 |
276 | if ($flags[$j][$num] == 'Deleted') { |
f7b1b3b1 |
277 | $messages[$j]['FLAG_DELETED'] = true; |
278 | } else if ($flags[$j][$num] == 'Answered') { |
279 | $messages[$j]['FLAG_ANSWERED'] = true; |
280 | } else if ($flags[$j][$num] == 'Seen') { |
281 | $messages[$j]['FLAG_SEEN'] = true; |
282 | } else if ($flags[$j][$num] == 'Flagged') { |
283 | $messages[$j]['FLAG_FLAGGED'] = true; |
5b6ae78a |
284 | } |
285 | $num++; |
7151188f |
286 | } |
5b6ae78a |
287 | $j++; |
3302d0d4 |
288 | } |
f9b3e5d9 |
289 | |
290 | /* Only ignore messages flagged as deleted if we are using a |
291 | * trash folder or auto_expunge */ |
d6def997 |
292 | if (((isset($move_to_trash) && $move_to_trash) |
f7b1b3b1 |
293 | || (isset($auto_expunge) && $auto_expunge)) && $sort != 6) { |
294 | |
f9b3e5d9 |
295 | /** Find and remove the ones that are deleted */ |
296 | $i = 0; |
297 | $j = 0; |
f7b1b3b1 |
298 | |
23d6bd09 |
299 | while ($j < $num_msgs) { |
cd928157 |
300 | if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) { |
f9b3e5d9 |
301 | $j++; |
302 | continue; |
303 | } |
304 | $msgs[$i] = $messages[$j]; |
b60b58f9 |
305 | |
f9b3e5d9 |
306 | $i++; |
5b6ae78a |
307 | $j++; |
5b6ae78a |
308 | } |
23d6bd09 |
309 | $num_msgs = $i; |
0d455368 |
310 | } else { |
f7b1b3b1 |
311 | if (!isset($messages)) { |
312 | $messages = array(); |
313 | } |
314 | $msgs = $messages; |
5b10f02a |
315 | } |
d6def997 |
316 | } |
926da13e |
317 | |
4c2d69ac |
318 | // There's gotta be messages in the array for it to sort them. |
23d6bd09 |
319 | if ($num_msgs > 0 && ! $use_cache) { |
0e919368 |
320 | /** 0 = Date (up) 4 = Subject (up) |
321 | ** 1 = Date (dn) 5 = Subject (dn) |
322 | ** 2 = Name (up) |
323 | ** 3 = Name (dn) |
324 | **/ |
09856735 |
325 | session_unregister("msgs"); |
1c292c82 |
326 | if (($sort == 0) || ($sort == 1)) |
90bc0b93 |
327 | $msort = array_cleave ($msgs, 'TIME_STAMP'); |
9b0f85eb |
328 | elseif (($sort == 2) || ($sort == 3)) |
90bc0b93 |
329 | $msort = array_cleave ($msgs, 'FROM-SORT'); |
9b0f85eb |
330 | elseif (($sort == 4) || ($sort == 5)) |
90bc0b93 |
331 | $msort = array_cleave ($msgs, 'SUBJECT-SORT'); |
9b0f85eb |
332 | else // ($sort == 6) |
0d455368 |
333 | $msort = $msgs; |
334 | |
335 | if ($sort < 6) { |
9b0f85eb |
336 | if ($sort % 2) { |
0d455368 |
337 | asort($msort); |
338 | } else { |
339 | arsort($msort); |
340 | } |
0e919368 |
341 | } |
90bc0b93 |
342 | session_register('msort'); |
4c2d69ac |
343 | } |
23d6bd09 |
344 | displayMessageArray($imapConnection, $num_msgs, $start_msg, $msgs, $msort, $mailbox, $sort, $color,$show_num); |
f7b1b3b1 |
345 | session_register('msgs'); |
9f2215a1 |
346 | } |
347 | |
f7b1b3b1 |
348 | /******************************************************************/ |
349 | /* Generic function to convert the msgs array into an HTML table. */ |
350 | /******************************************************************/ |
23d6bd09 |
351 | function displayMessageArray($imapConnection, $num_msgs, $start_msg, &$msgs, $msort, $mailbox, $sort, $color, $show_num) { |
cbdc5621 |
352 | global $folder_prefix, $sent_folder; |
4aaea201 |
353 | global $imapServerAddress, $data_dir, $username, $use_mailbox_cache; |
21fafac8 |
354 | global $index_order, $real_endMessage, $real_startMessage, $checkall; |
feb563a6 |
355 | |
f7b1b3b1 |
356 | /* If cache isn't already set, do it now. */ |
357 | if (!session_is_registered('msgs')) { session_register('msgs'); } |
358 | if (!session_is_registered('msort')) { session_register('msort'); } |
90033b64 |
359 | |
23d6bd09 |
360 | if ($start_msg + ($show_num - 1) < $num_msgs) { |
361 | $end_msg = $start_msg + ($show_num-1); |
926da13e |
362 | } else { |
23d6bd09 |
363 | $end_msg = $num_msgs; |
926da13e |
364 | } |
b60b58f9 |
365 | |
23d6bd09 |
366 | if ($end_msg < $start_msg) { |
367 | $start_msg = $start_msg - $show_num; |
368 | if ($start_msg < 1) { $start_msg = 1; } |
8442ac08 |
369 | } |
b60b58f9 |
370 | |
20db5033 |
371 | $urlMailbox = urlencode($mailbox); |
926da13e |
372 | |
90bc0b93 |
373 | do_hook('mailbox_index_before'); |
926da13e |
374 | |
23d6bd09 |
375 | $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs); |
376 | $paginator_str = get_paginator_str($urlMailbox, $start_msg, $end_msg, $num_msgs, $show_num); |
26b6c99c |
377 | |
23d6bd09 |
378 | if (! isset($msg)) { |
379 | $msg = ''; |
14eb705c |
380 | } |
381 | |
23d6bd09 |
382 | mail_message_listing_beginning |
383 | ($imapConnection, |
384 | "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$start_msg", |
385 | $mailbox, $sort, $msg_cnt_str, $paginator_str, $start_msg); |
14eb705c |
386 | |
23d6bd09 |
387 | $groupNum = $start_msg % ($show_num - 1); |
388 | $real_startMessage = $start_msg; |
b60b58f9 |
389 | if ($sort == 6) { |
23d6bd09 |
390 | if ($end_msg - $start_msg < $show_num - 1) { |
391 | $end_msg = $end_msg - $start_msg + 1; |
392 | $start_msg = 1; |
393 | } else if ($start_msg > $show_num) { |
394 | $end_msg = $show_num; |
395 | $start_msg = 1; |
b60b58f9 |
396 | } |
397 | } |
23d6bd09 |
398 | $endVar = $end_msg + 1; |
b60b58f9 |
399 | |
23d6bd09 |
400 | /* Loop through and display the info for each message. */ |
14eb705c |
401 | $t = 0; // $t is used for the checkbox number |
23d6bd09 |
402 | if ($num_msgs == 0) { // if there's no messages in this folder |
403 | echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order) . ">\n"; |
404 | echo " <CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR> </CENTER>\n"; |
405 | echo "</TD></TR>"; |
406 | } else if ($start_msg == $end_msg) { |
407 | /* If there's only one message in the box, handle it differently. */ |
408 | if ($sort != 6) { |
409 | $i = $start_msg; |
410 | } else { |
411 | $i = 1; |
412 | } |
413 | |
414 | reset($msort); |
415 | $k = 0; |
416 | do { |
417 | $key = key($msort); |
418 | next($msort); |
419 | $k++; |
420 | } while (isset ($key) && ($k < $i)); |
421 | printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0); |
14eb705c |
422 | } else { |
23d6bd09 |
423 | $i = $start_msg; |
424 | |
425 | reset($msort); |
426 | $k = 0; |
427 | do { |
428 | $key = key($msort); |
429 | next($msort); |
430 | $k++; |
431 | } while (isset ($key) && ($k < $i)); |
432 | |
433 | do { |
434 | printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0); |
435 | $key = key($msort); |
436 | $t++; |
437 | $i++; |
438 | next($msort); |
439 | } while ($i && $i < $endVar); |
14eb705c |
440 | } |
14eb705c |
441 | |
1125b3de |
442 | echo '</table>'; |
e72fb4f7 |
443 | echo "<table bgcolor=\"$color[9]\" width=100% border=0 cellpadding=1 cellspacing=1>" . |
444 | "<tr BGCOLOR=\"$color[4]\">" . |
23d6bd09 |
445 | "<table width=100% BGCOLOR=\"$color[4]\" border=0 cellpadding=1 cellspacing=0><tr><td>$paginator_str</td>". |
446 | "<td align=right>$msg_cnt_str</td></tr></table>". |
e72fb4f7 |
447 | "</tr>". |
448 | "</table>"; |
a2ae47f7 |
449 | /** End of message-list table */ |
14eb705c |
450 | |
90bc0b93 |
451 | do_hook('mailbox_index_after'); |
a2ae47f7 |
452 | echo "</TABLE></FORM>\n"; |
14eb705c |
453 | } |
454 | |
23d6bd09 |
455 | /** |
456 | * Displays the standard message list header. To finish the table, |
457 | * you need to do a "</table></table>"; |
458 | * |
14eb705c |
459 | * $moveURL is the URL to submit the delete/move form to |
460 | * $mailbox is the current mailbox |
461 | * $sort is the current sorting method (-1 for no sorting available [searches]) |
462 | * $Message is a message that is centered on top of the list |
463 | * $More is a second line that is left aligned |
464 | */ |
f7b1b3b1 |
465 | function mail_message_listing_beginning |
466 | ($imapConnection, $moveURL, $mailbox = '', $sort = -1, |
23d6bd09 |
467 | $msg_cnt_str = '', $paginator = '', $start_msg = 1) { |
f9b3e5d9 |
468 | global $color, $index_order, $auto_expunge, $move_to_trash; |
f7b1b3b1 |
469 | global $checkall, $sent_folder, $draft_folder; |
eca500d0 |
470 | $urlMailbox = urlencode($mailbox); |
8ae331c2 |
471 | |
23d6bd09 |
472 | /**************************************************** |
473 | * This is the beginning of the message list table. * |
474 | * It wraps around all messages * |
475 | ****************************************************/ |
476 | echo "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"0\">\n"; |
8ae331c2 |
477 | |
23d6bd09 |
478 | echo "<TR BGCOLOR=\"$color[0]\"><TD>"; |
479 | echo " <TABLE BGCOLOR=\"$color[4]\" width=\"100%\" CELLPADDING=\"2\" CELLSPACING=\"0\" BORDER=\"0\"><TR>\n"; |
480 | echo " <TD ALIGN=LEFT>$paginator</TD>\n"; |
481 | echo ' <TD ALIGN=CENTER>' . get_selectall_link($start_msg, $sort) . "</TD>\n"; |
482 | echo " <TD ALIGN=RIGHT>$msg_cnt_str</TD>\n"; |
483 | echo " </TR></TABLE>\n"; |
484 | echo "</TD></TR>"; |
81caa0f3 |
485 | |
68347a84 |
486 | /** The delete and move options */ |
23d6bd09 |
487 | echo "<TR><TD BGCOLOR=\"$color[0]\">"; |
ed4332d1 |
488 | |
feb563a6 |
489 | echo "\n<FORM name=messageList method=post action=\"$moveURL\">\n"; |
4f313fcf |
490 | echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=100%>\n"; |
66289791 |
491 | |
f1e6f580 |
492 | echo " <TR>\n" . |
493 | " <TD ALIGN=LEFT VALIGN=CENTER NOWRAP>\n" . |
494 | ' <SMALL> ' . _("Move selected to:") . "</SMALL>\n" . |
495 | " </TD>\n" . |
f1e6f580 |
496 | " <TD ALIGN=RIGHT NOWRAP>\n" . |
497 | ' <SMALL> ' . _("Transform Selected Messages") . ": </SMALL><BR>\n" . |
498 | " </TD>\n" . |
499 | " </TR>\n" . |
500 | " <TR>\n" . |
501 | " <TD ALIGN=LEFT VALIGN=CENTER NOWRAP>\n" . |
502 | ' <SMALL> <TT><SELECT NAME="targetMailbox">'; |
7ce342dc |
503 | |
9f2215a1 |
504 | $boxes = sqimap_mailbox_list($imapConnection); |
7ce342dc |
505 | for ($i = 0; $i < count($boxes); $i++) { |
cbbdef2a |
506 | if (!in_array("noselect", $boxes[$i]['flags'])) { |
90bc0b93 |
507 | $box = $boxes[$i]['unformatted']; |
e78e7f48 |
508 | $box2 = str_replace(' ', ' ', $boxes[$i]['formatted']); |
14eb705c |
509 | echo " <OPTION VALUE=\"$box\">$box2</option>\n"; |
6edca885 |
510 | } |
dd88d31f |
511 | } |
0c6d50f1 |
512 | echo ' </SELECT></TT></SMALL>'; |
6332704d |
513 | echo " <SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"" . _("Move") . "\"></SMALL>\n"; |
ed4332d1 |
514 | echo " </TD>\n"; |
6332704d |
515 | echo " <TD ALIGN=RIGHT NOWRAP> \n"; |
f7b1b3b1 |
516 | if (!$auto_expunge) { |
6332704d |
517 | echo ' <INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'"> '. _("mailbox") ." \n"; |
f9b3e5d9 |
518 | } |
6332704d |
519 | echo " <INPUT TYPE=SUBMIT NAME=\"markRead\" VALUE=\"". _("Read")."\">\n"; |
520 | echo " <INPUT TYPE=SUBMIT NAME=\"markUnread\" VALUE=\"". _("Unread")."\">\n"; |
521 | echo " <INPUT TYPE=SUBMIT VALUE=\"". _("Delete") . "\"> \n"; |
14eb705c |
522 | echo " </TD>\n"; |
ed4332d1 |
523 | echo " </TR>\n"; |
70b455e0 |
524 | echo "</TABLE>\n"; |
90bc0b93 |
525 | do_hook('mailbox_form_before'); |
526 | echo '</TD></TR>'; |
aa4c3749 |
527 | |
f8f9bed9 |
528 | echo "<TR><TD BGCOLOR=\"$color[0]\">"; |
ac53fb56 |
529 | echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING="; |
530 | if ($GLOBALS['alt_index_colors']) { |
531 | echo "0"; |
532 | } else { |
533 | echo "1"; |
534 | } |
535 | echo " BGCOLOR=\"$color[0]\">"; |
f8f9bed9 |
536 | echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">"; |
be8e07f8 |
537 | |
f7b1b3b1 |
538 | /* Print the headers. */ |
8e265988 |
539 | for ($i=1; $i <= count($index_order); $i++) { |
540 | switch ($index_order[$i]) { |
f7b1b3b1 |
541 | case 1: /* checkbox */ |
542 | case 5: /* flags */ |
90bc0b93 |
543 | echo ' <TD WIDTH="1%"><B> </B></TD>'; |
8e265988 |
544 | break; |
d6def997 |
545 | |
f7b1b3b1 |
546 | case 2: /* from */ |
547 | if (($mailbox == $sent_folder) |
548 | || ($mailbox == $draft_folder)) { |
20cd8abb |
549 | echo ' <TD WIDTH="25%"><B>'. _("To") .'</B>'; |
f7b1b3b1 |
550 | } else { |
551 | echo ' <TD WIDTH="25%"><B>'. _("From") .'</B>'; |
552 | } |
553 | |
d6def997 |
554 | ShowSortButton($sort, $mailbox, 2, 3); |
9b0f85eb |
555 | echo "</TD>\n"; |
8e265988 |
556 | break; |
d6def997 |
557 | |
f7b1b3b1 |
558 | case 3: /* date */ |
20cd8abb |
559 | echo ' <TD NOWRAP WIDTH="5%"><B>'. _("Date") .'</B>'; |
d6def997 |
560 | ShowSortButton($sort, $mailbox, 0, 1); |
9b0f85eb |
561 | echo "</TD>\n"; |
8e265988 |
562 | break; |
d6def997 |
563 | |
f7b1b3b1 |
564 | case 4: /* subject */ |
9b0f85eb |
565 | echo ' <TD><B>'. _("Subject") .'</B> '; |
d6def997 |
566 | ShowSortButton($sort, $mailbox, 4, 5); |
9b0f85eb |
567 | echo "</TD>\n"; |
8e265988 |
568 | break; |
d6def997 |
569 | |
f7b1b3b1 |
570 | case 6: /* size */ |
20cd8abb |
571 | echo ' <TD WIDTH="5%"><b>' . _("Size")."</b></TD>\n"; |
8e265988 |
572 | break; |
573 | } |
574 | } |
14eb705c |
575 | echo "</TR>\n"; |
3302d0d4 |
576 | } |
d6def997 |
577 | |
f7b1b3b1 |
578 | /*******************************************************************/ |
579 | /* This function shows the sort button. Isn't this a good comment? */ |
580 | /*******************************************************************/ |
9b0f85eb |
581 | function ShowSortButton($sort, $mailbox, $Up, $Down) { |
f7b1b3b1 |
582 | /* Figure out which image we want to use. */ |
9b0f85eb |
583 | if ($sort != $Up && $sort != $Down) { |
584 | $img = 'sort_none.gif'; |
585 | $which = $Up; |
586 | } elseif ($sort == $Up) { |
587 | $img = 'up_pointer.gif'; |
d6def997 |
588 | $which = $Down; |
9b0f85eb |
589 | } else { |
590 | $img = 'down_pointer.gif'; |
d6def997 |
591 | $which = 6; |
9b0f85eb |
592 | } |
f7b1b3b1 |
593 | |
594 | /* Now that we have everything figured out, show the actual button. */ |
d6def997 |
595 | echo ' <a href="right_main.php?newsort=' . $which . |
596 | '&startMessage=1&mailbox=' . urlencode($mailbox) . |
597 | '"><IMG SRC="../images/' . $img . |
598 | '" BORDER=0 WIDTH=12 HEIGHT=10></a>'; |
9b0f85eb |
599 | } |
d6def997 |
600 | |
23d6bd09 |
601 | function get_selectall_link($start_msg, $sort) { |
323218d7 |
602 | global $checkall, $PHP_SELF, $what, $where, $mailbox; |
5de4de79 |
603 | |
23d6bd09 |
604 | $result = |
605 | ' <script language="JavaScript">' . |
2016e645 |
606 | "\n<!-- \n" . |
607 | "function CheckAll() {\n" . |
608 | " for (var i = 0; i < document.messageList.elements.length; i++) {\n" . |
609 | " if( document.messageList.elements[i].type == 'checkbox' ) {\n" . |
610 | " document.messageList.elements[i].checked = !(document.messageList.elements[i].checked);\n". |
611 | " }\n" . |
612 | " }\n" . |
613 | "}\n" . |
614 | 'window.document.write(\'<a href=# onClick="CheckAll();">' . _("Toggle All") . "</a>');\n" . |
615 | "//-->\n" . |
616 | "</script>\n<noscript>\n"; |
0700d853 |
617 | |
23d6bd09 |
618 | $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox) |
619 | . "&startMessage=$start_msg&sort=$sort&checkall="; |
620 | if (isset($checkall) && $checkall == '1') { |
621 | $result .= '0'; |
622 | } else { |
623 | $result .= '1'; |
624 | } |
625 | |
626 | if (isset($where) && isset($what)) { |
627 | $result .= '&where=' . urlencode($where) . '&what=' . urlencode($what); |
628 | } |
629 | |
630 | $result .= "\">"; |
631 | |
632 | if (isset($checkall) && ($checkall == '1')) { |
633 | $result .= _("Unselect All"); |
634 | } else { |
635 | $result .= _("Select All"); |
636 | } |
637 | |
638 | $result .= "</A>\n</noscript>\n"; |
639 | |
640 | /* Return our final result. */ |
641 | return ($result); |
323218d7 |
642 | } |
f93c93b9 |
643 | |
23d6bd09 |
644 | /** |
645 | * This function computes the "Viewing Messages..." string. |
646 | */ |
647 | function get_msgcnt_str($start_msg, $end_msg, $num_msgs) { |
648 | /* Compute the $msg_cnt_str. */ |
649 | $result = ''; |
650 | if ($start_msg < $end_msg) { |
651 | $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"), $start_msg, $end_msg, $num_msgs); |
652 | } else if ($start_msg == $end_msg) { |
653 | $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg); |
654 | } else { |
655 | $result = '<br>'; |
656 | } |
657 | |
658 | /* Return our result string. */ |
659 | return ($result); |
660 | } |
661 | |
662 | /** |
663 | * This function computes the paginator string. |
664 | */ |
665 | function get_paginator_str |
666 | ($urlMailbox, $start_msg, $end_msg, $num_msgs, $show_num) { |
667 | $nextGroup = $start_msg + $show_num; |
668 | $prevGroup = $start_msg - $show_num; |
669 | |
670 | if ($sort == 6) { |
671 | $use = 0; |
672 | } else { |
673 | $use = 1; |
674 | } |
675 | $lMore = ''; |
676 | $rMore = ''; |
677 | if (($nextGroup <= $num_msgs) && ($prevGroup >= 0)) { |
678 | $lMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") . '</A>'; |
679 | $rMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n"; |
680 | } else if (($nextGroup > $num_msgs) && ($prevGroup >= 0)) { |
681 | $lMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") . '</A>'; |
682 | $rMore = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n"; |
683 | } else if (($nextGroup <= $num_msgs) && ($prevGroup < 0)) { |
684 | $lMore = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>'; |
685 | $rMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n"; |
686 | } |
687 | if ($lMore <> '') { |
688 | $lMore .= ' | '; |
689 | } |
690 | |
691 | /* Page selector block. Following code computes page links. */ |
692 | $mMore = ''; |
693 | if (!getPref($data_dir, $username, 'page_selector') |
694 | && ($num_msgs > $show_num)) { |
695 | $j = intval( $num_msgs / $show_num ); // Max pages |
696 | $k = max( 1, $j / getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX ) ); |
697 | if ($num_msgs % $show_num <> 0 ) { |
698 | $j++; |
699 | } |
700 | $start_msgs = min( $start_msgs, $num_msgs ); |
701 | $p = intval( $start_msgs / $show_num ) + 1; |
702 | $i = 1; |
703 | while( $i < $p ) { |
704 | $pg = intval( $i ); |
705 | $start = ( ($pg-1) * $show_num ) + 1; |
706 | $mMore .= "<a href=\"right_main.php?use_mailbox_cache=$use_mailbox_cache&startMessage=$start" . |
707 | "&mailbox=$urlMailbox\" TARGET=\"right\">$pg</a> "; |
708 | $i += $k; |
709 | } |
710 | $mMore .= "<b>$p</b> "; |
711 | $i += $k; |
712 | while( $i <= $j ) { |
713 | $pg = intval( $i ); |
714 | $start = ( ($pg-1) * $show_num ) + 1; |
715 | $mMore .= "<a href=\"right_main.php?use_mailbox_cache=$use_mailbox_cache&startMessage=$start" |
716 | . "&mailbox=$urlMailbox\" TARGET=\"right\">$pg</a> "; |
717 | $i+=$k; |
718 | } |
719 | $mMore .= ' | '; |
720 | } |
721 | |
722 | /* Return the resulting string. */ |
723 | return ($lMore . $mMore . $rMore); |
724 | } |
725 | |
726 | function processSubject($subject) { |
f93c93b9 |
727 | // Shouldn't ever happen -- caught too many times in the IMAP functions |
728 | if ($subject == '') |
729 | return _("(no subject)"); |
d6def997 |
730 | |
f93c93b9 |
731 | if (strlen($subject) <= 55) |
732 | return $subject; |
d6def997 |
733 | |
f93c93b9 |
734 | $ent_strlen=strlen($subject); |
735 | $trim_val=50; |
736 | $ent_offset=0; |
737 | // see if this is entities-encoded string |
738 | // If so, Iterate through the whole string, find out |
739 | // the real number of characters, and if more |
740 | // than 55, substr with an updated trim value. |
741 | while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false && |
742 | ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false) |
743 | { |
d6def997 |
744 | $trim_val += ($ent_loc_end-$ent_loc)+1; |
745 | $ent_strlen -= $ent_loc_end-$ent_loc; |
746 | $ent_offset = $ent_loc_end+1; |
f93c93b9 |
747 | } |
d6def997 |
748 | |
f93c93b9 |
749 | if ($ent_strlen <= 55) |
750 | return $subject; |
751 | |
752 | return substr($subject, 0, $trim_val) . '...'; |
753 | } |
754 | |
e78e7f48 |
755 | ?> |