59177427 |
1 | <?php |
2ba13803 |
2 | |
35586184 |
3 | /** |
4 | * mailbox_display.php |
5 | * |
6 | * Copyright (c) 1999-2001 The SquirrelMail Development Team |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
9 | * This contains functions that display mailbox information, such as the |
10 | * table row that has sender, date, subject, etc... |
11 | * |
12 | * $Id$ |
13 | */ |
a4c2cd49 |
14 | |
35586184 |
15 | define('PG_SEL_MAX', 10); /* Default value for page_selector_max. */ |
16 | |
17 | function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $start_msg, $where, $what) { |
bdfb67f8 |
18 | global $checkall; |
19 | global $color, $msgs, $msort; |
20 | global $sent_folder, $draft_folder; |
21 | global $default_use_priority; |
22 | global $message_highlight_list; |
23 | global $index_order; |
24 | |
25 | $color_string = $color[4]; |
26 | if ($GLOBALS['alt_index_colors']) { |
27 | if (!isset($GLOBALS["row_count"])) { |
ac53fb56 |
28 | $GLOBALS["row_count"] = 0; |
bdfb67f8 |
29 | } |
30 | $GLOBALS["row_count"]++; |
31 | if ($GLOBALS["row_count"] % 2) { |
32 | if (!isset($color[12])) $color[12] = '#EAEAEA'; |
ac53fb56 |
33 | $color_string = $color[12]; |
bdfb67f8 |
34 | } |
35 | } |
36 | $msg = $msgs[$key]; |
37 | |
38 | $senderName = htmlspecialchars(sqimap_find_displayable_name($msg['FROM'])); |
39 | if( $mailbox == 'None' ) { |
40 | // $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
41 | $boxes = sqimap_mailbox_list($imapConnection); |
42 | // sqimap_logout($imapConnection); |
43 | $mailbox = $boxes[0]['unformatted']; |
44 | unset( $boxes ); |
45 | } |
46 | $urlMailbox = urlencode($mailbox); |
47 | $subject = processSubject($msg['SUBJECT']); |
48 | echo "<TR>\n"; |
49 | |
50 | if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) { |
51 | $flag = "<font color=$color[2]>"; |
52 | $flag_end = '</font>'; |
53 | } else { |
54 | $flag = ''; |
55 | $flag_end = ''; |
56 | } |
57 | if (!isset($msg['FLAG_SEEN']) || ($msg['FLAG_SEEN'] == false)) { |
58 | $bold = '<b>'; |
59 | $bold_end = '</b>'; |
60 | } else { |
61 | $bold = ''; |
62 | $bold_end = ''; |
63 | } |
64 | |
65 | if (($mailbox == $sent_folder) || ($mailbox == $draft_folder)) { |
66 | $italic = '<i>'; |
67 | $italic_end = '</i>'; |
68 | } else { |
69 | $italic = ''; |
70 | $italic_end = ''; |
71 | } |
72 | |
73 | if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) { |
74 | $fontstr = "<font color=\"$color[9]\">"; |
75 | $fontstr_end = '</font>'; |
76 | } else { |
77 | $fontstr = ''; |
78 | $fontstr_end = ''; |
79 | } |
80 | |
81 | for ($i=0; $i < count($message_highlight_list); $i++) { |
82 | if (trim($message_highlight_list[$i]['value']) != '') { |
90bc0b93 |
83 | if ($message_highlight_list[$i]['match_type'] == 'to_cc') { |
bdfb67f8 |
84 | if (strpos('^^'.strtolower($msg['TO']), strtolower($message_highlight_list[$i]['value'])) || strpos('^^'.strtolower($msg['CC']), strtolower($message_highlight_list[$i]['value']))) { |
85 | $hlt_color = $message_highlight_list[$i]['color']; |
86 | continue; |
87 | } |
90bc0b93 |
88 | } else if (strpos('^^'.strtolower($msg[strtoupper($message_highlight_list[$i]['match_type'])]),strtolower($message_highlight_list[$i]['value']))) { |
bdfb67f8 |
89 | $hlt_color = $message_highlight_list[$i]['color']; |
90 | continue; |
b60b58f9 |
91 | } |
bdfb67f8 |
92 | } |
93 | } |
94 | |
95 | if (!isset($hlt_color)) { |
96 | $hlt_color = $color_string; |
97 | } |
98 | |
99 | if ($where && $what) { |
100 | $search_stuff = '&where='.urlencode($where).'&what='.urlencode($what); |
101 | } |
102 | |
103 | $checked = ($checkall == 1 ?' checked' : ''); |
104 | |
105 | for ($i=1; $i <= count($index_order); $i++) { |
106 | switch ($index_order[$i]) { |
107 | case 1: /* checkbox */ |
108 | echo " <td bgcolor=$hlt_color align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n"; |
109 | break; |
110 | case 2: /* from */ |
111 | echo " <td bgcolor=$hlt_color>$italic$bold$flag$fontstr$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n"; |
112 | break; |
113 | case 3: /* date */ |
114 | echo " <td nowrap bgcolor=$hlt_color><center>$bold$flag$fontstr".$msg["DATE_STRING"]."$fontstr_end$flag_end$bold_end</center></td>\n"; |
115 | break; |
116 | case 4: /* subject */ |
117 | echo " <td bgcolor=$hlt_color>$bold"; |
118 | if (! isset($search_stuff)) { $search_stuff = ''; } |
119 | echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$start_msg&show_more=0$search_stuff\""; |
120 | do_hook("subject_link"); |
121 | |
122 | if ($subject != $msg['SUBJECT']) { |
123 | $title = get_html_translation_table(HTML_SPECIALCHARS); |
124 | $title = array_flip($title); |
125 | $title = strtr($msg['SUBJECT'], $title); |
126 | $title = str_replace('"', "''", $title); |
127 | echo " title=\"$title\""; |
128 | } |
129 | echo ">$flag$subject$flag_end</a>$bold_end</td>\n"; |
130 | break; |
131 | case 5: /* flags */ |
132 | $stuff = false; |
133 | echo " <td bgcolor=$hlt_color align=center nowrap><b><small>\n"; |
134 | if (isset($msg['FLAG_ANSWERED']) && |
135 | $msg['FLAG_ANSWERED'] == true) { |
136 | echo "A\n"; |
137 | $stuff = true; |
138 | } |
139 | if ($msg['TYPE0'] == 'multipart') { |
140 | echo "+\n"; |
141 | $stuff = true; |
142 | } |
143 | if ($default_use_priority) { |
144 | if (ereg('(1|2)',substr($msg['PRIORITY'],0,1))) { |
145 | echo "<font color=$color[1]>!</font>\n"; |
146 | $stuff = true; |
147 | } |
148 | if (ereg('(5)',substr($msg['PRIORITY'],0,1))) { |
149 | echo "<font color=$color[8]>?</font>\n"; |
150 | $stuff = true; |
151 | } |
152 | } |
153 | if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) { |
154 | echo "<font color=\"$color[1]\">D</font>\n"; |
155 | $stuff = true; |
156 | } |
157 | |
158 | if (!$stuff) { |
159 | echo " \n"; |
160 | } |
161 | echo "</small></b></td>\n"; |
162 | break; |
163 | case 6: /* size */ |
164 | echo " <td bgcolor=$hlt_color>$bold$fontstr" . |
165 | show_readable_size($msg['SIZE']) . |
166 | "$fontstr_end$bold_end</td>\n"; |
167 | break; |
168 | } |
169 | } |
170 | echo "</tr>\n"; |
171 | } |
172 | |
173 | /** |
174 | * This function loops through a group of messages in the mailbox |
175 | * and shows them to the user. |
176 | */ |
177 | function showMessagesForMailbox |
23d6bd09 |
178 | ($imapConnection, $mailbox, $num_msgs, $start_msg, |
bdfb67f8 |
179 | $sort, $color,$show_num, $use_cache) { |
180 | global $msgs, $msort; |
181 | global $sent_folder, $draft_folder; |
182 | global $message_highlight_list; |
183 | global $auto_expunge; |
184 | |
185 | /* If autoexpunge is turned on, then do it now. */ |
186 | if ($auto_expunge == true) { |
187 | sqimap_mailbox_expunge($imapConnection, $mailbox, false); |
188 | } |
189 | sqimap_mailbox_select($imapConnection, $mailbox); |
190 | |
191 | $issent = (($mailbox == $sent_folder) || ($mailbox == $draft_folder)); |
192 | if (!$use_cache) { |
193 | /* If it is sorted... */ |
194 | if ($num_msgs >= 1) { |
0d455368 |
195 | if ($sort < 6) { |
bdfb67f8 |
196 | $id = range(1, $num_msgs); |
0d455368 |
197 | } else { |
bdfb67f8 |
198 | // if it's not sorted |
199 | if ($start_msg + ($show_num - 1) < $num_msgs) { |
200 | $end_msg = $start_msg + ($show_num-1); |
201 | } else { |
202 | $end_msg = $num_msgs; |
203 | } |
204 | |
205 | if ($end_msg < $start_msg) { |
206 | $start_msg = $start_msg - $show_num; |
207 | if ($start_msg < 1) { |
208 | $start_msg = 1; |
209 | } |
210 | } |
211 | |
212 | $real_startMessage = $num_msgs - $start_msg + 1; |
213 | $real_endMessage = $num_msgs - $start_msg - $show_num + 2; |
214 | if ($real_endMessage <= 0) { |
215 | $real_endMessage = 1; |
216 | } |
217 | $id = array_reverse(range($real_endMessage, $real_startMessage)); |
91f68e94 |
218 | } |
b60b58f9 |
219 | |
91f68e94 |
220 | $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent); |
221 | $flags = sqimap_get_flags_list($imapConnection, $id, $issent); |
222 | foreach ($msgs_list as $hdr) { |
bdfb67f8 |
223 | $from[] = $hdr->from; |
224 | $date[] = $hdr->date; |
225 | $subject[] = $hdr->subject; |
226 | $to[] = $hdr->to; |
227 | $priority[] = $hdr->priority; |
228 | $cc[] = $hdr->cc; |
229 | $size[] = $hdr->size; |
230 | $type[] = $hdr->type0; |
231 | } |
232 | } |
233 | |
234 | $j = 0; |
235 | if ($sort == 6) { |
236 | $end = $start_msg + $show_num - 1; |
237 | if ($num_msgs < $show_num) { |
238 | $end_loop = $num_msgs; |
239 | } else if ($end > $num_msgs) { |
240 | $end_loop = $num_msgs - $start_msg + 1; |
241 | } else { |
242 | $end_loop = $show_num; |
b60b58f9 |
243 | } |
bdfb67f8 |
244 | } else { |
23d6bd09 |
245 | $end = $num_msgs; |
cd928157 |
246 | $end_loop = $end; |
bdfb67f8 |
247 | } |
f7b1b3b1 |
248 | |
bdfb67f8 |
249 | while ($j < $end_loop) { |
cd928157 |
250 | if (isset($date[$j])) { |
251 | $date[$j] = ereg_replace(' ', ' ', $date[$j]); |
252 | $tmpdate = explode(' ', trim($date[$j])); |
253 | } else { |
bdfb67f8 |
254 | $tmpdate = $date = array('', '', '', '', '', ''); |
cd928157 |
255 | } |
90bc0b93 |
256 | |
257 | $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate); |
258 | $messages[$j]['DATE_STRING'] = getDateString($messages[$j]['TIME_STAMP']); |
259 | $messages[$j]['ID'] = $id[$j]; |
260 | $messages[$j]['FROM'] = decodeHeader($from[$j]); |
261 | $messages[$j]['FROM-SORT'] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j]))); |
262 | $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]); |
263 | $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j])); |
264 | $messages[$j]['TO'] = decodeHeader($to[$j]); |
265 | $messages[$j]['PRIORITY'] = $priority[$j]; |
266 | $messages[$j]['CC'] = $cc[$j]; |
267 | $messages[$j]['SIZE'] = $size[$j]; |
268 | $messages[$j]['TYPE0'] = $type[$j]; |
e9f8ea4e |
269 | |
270 | # fix SUBJECT-SORT to remove Re: |
bdfb67f8 |
271 | $re_abbr = /* Add more here! */ |
272 | 'vedr|sv|' . /* Danish */ |
273 | 're|aw'; /* English */ |
f1e6f580 |
274 | |
bdfb67f8 |
275 | if (eregi( "^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs)) { |
276 | $messages[$j]['SUBJECT-SORT'] = $regs[2]; |
277 | } |
b60b58f9 |
278 | |
5b6ae78a |
279 | $num = 0; |
280 | while ($num < count($flags[$j])) { |
bdfb67f8 |
281 | if ($flags[$j][$num] == 'Deleted') { |
282 | $messages[$j]['FLAG_DELETED'] = true; |
283 | } else if ($flags[$j][$num] == 'Answered') { |
284 | $messages[$j]['FLAG_ANSWERED'] = true; |
285 | } else if ($flags[$j][$num] == 'Seen') { |
286 | $messages[$j]['FLAG_SEEN'] = true; |
287 | } else if ($flags[$j][$num] == 'Flagged') { |
288 | $messages[$j]['FLAG_FLAGGED'] = true; |
289 | } |
290 | $num++; |
7151188f |
291 | } |
5b6ae78a |
292 | $j++; |
bdfb67f8 |
293 | } |
f9b3e5d9 |
294 | |
bdfb67f8 |
295 | /* Only ignore messages flagged as deleted if we are using a |
296 | * trash folder or auto_expunge */ |
297 | if (((isset($move_to_trash) && $move_to_trash) |
298 | || (isset($auto_expunge) && $auto_expunge)) && $sort != 6) { |
f7b1b3b1 |
299 | |
f9b3e5d9 |
300 | /** Find and remove the ones that are deleted */ |
301 | $i = 0; |
302 | $j = 0; |
f7b1b3b1 |
303 | |
23d6bd09 |
304 | while ($j < $num_msgs) { |
bdfb67f8 |
305 | if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) { |
306 | $j++; |
307 | continue; |
308 | } |
309 | $msgs[$i] = $messages[$j]; |
310 | |
311 | $i++; |
312 | $j++; |
5b6ae78a |
313 | } |
23d6bd09 |
314 | $num_msgs = $i; |
bdfb67f8 |
315 | } else { |
316 | if (!isset($messages)) { |
317 | $messages = array(); |
318 | } |
319 | $msgs = $messages; |
320 | } |
321 | } |
322 | |
323 | // There's gotta be messages in the array for it to sort them. |
324 | if ($num_msgs > 0 && ! $use_cache) { |
325 | /** 0 = Date (up) 4 = Subject (up) |
326 | ** 1 = Date (dn) 5 = Subject (dn) |
327 | ** 2 = Name (up) |
328 | ** 3 = Name (dn) |
329 | **/ |
330 | session_unregister("msgs"); |
331 | if (($sort == 0) || ($sort == 1)) |
90bc0b93 |
332 | $msort = array_cleave ($msgs, 'TIME_STAMP'); |
bdfb67f8 |
333 | elseif (($sort == 2) || ($sort == 3)) |
90bc0b93 |
334 | $msort = array_cleave ($msgs, 'FROM-SORT'); |
bdfb67f8 |
335 | elseif (($sort == 4) || ($sort == 5)) |
90bc0b93 |
336 | $msort = array_cleave ($msgs, 'SUBJECT-SORT'); |
bdfb67f8 |
337 | else // ($sort == 6) |
0d455368 |
338 | $msort = $msgs; |
339 | |
bdfb67f8 |
340 | if ($sort < 6) { |
9b0f85eb |
341 | if ($sort % 2) { |
bdfb67f8 |
342 | asort($msort); |
0d455368 |
343 | } else { |
bdfb67f8 |
344 | arsort($msort); |
0d455368 |
345 | } |
bdfb67f8 |
346 | } |
347 | session_register('msort'); |
348 | } |
349 | displayMessageArray($imapConnection, $num_msgs, $start_msg, $msgs, $msort, $mailbox, $sort, $color,$show_num); |
350 | session_register('msgs'); |
351 | } |
352 | |
353 | /** |
354 | * Generic function to convert the msgs array into an HTML table. |
355 | */ |
356 | function displayMessageArray($imapConnection, $num_msgs, $start_msg, &$msgs, $msort, $mailbox, $sort, $color, $show_num) { |
357 | global $folder_prefix, $sent_folder; |
358 | global $imapServerAddress, $data_dir, $username, $use_mailbox_cache; |
359 | global $index_order, $real_endMessage, $real_startMessage, $checkall; |
360 | |
361 | /* If cache isn't already set, do it now. */ |
362 | if (!session_is_registered('msgs')) { session_register('msgs'); } |
363 | if (!session_is_registered('msort')) { session_register('msort'); } |
364 | |
365 | if ($start_msg + ($show_num - 1) < $num_msgs) { |
366 | $end_msg = $start_msg + ($show_num-1); |
367 | } else { |
368 | $end_msg = $num_msgs; |
369 | } |
370 | |
371 | if ($end_msg < $start_msg) { |
372 | $start_msg = $start_msg - $show_num; |
373 | if ($start_msg < 1) { $start_msg = 1; } |
374 | } |
375 | |
376 | $urlMailbox = urlencode($mailbox); |
377 | |
378 | do_hook('mailbox_index_before'); |
379 | |
380 | $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs); |
7b294953 |
381 | $paginator_str = get_paginator_str |
382 | ($urlMailbox, $start_msg, $end_msg, $num_msgs, $show_num, $sort); |
bdfb67f8 |
383 | |
384 | if (! isset($msg)) { |
385 | $msg = ''; |
386 | } |
387 | |
388 | mail_message_listing_beginning |
389 | ($imapConnection, |
390 | "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$start_msg", |
391 | $mailbox, $sort, $msg_cnt_str, $paginator_str, $start_msg); |
392 | |
393 | $groupNum = $start_msg % ($show_num - 1); |
394 | $real_startMessage = $start_msg; |
395 | if ($sort == 6) { |
396 | if ($end_msg - $start_msg < $show_num - 1) { |
23d6bd09 |
397 | $end_msg = $end_msg - $start_msg + 1; |
398 | $start_msg = 1; |
bdfb67f8 |
399 | } else if ($start_msg > $show_num) { |
23d6bd09 |
400 | $end_msg = $show_num; |
401 | $start_msg = 1; |
bdfb67f8 |
402 | } |
403 | } |
404 | $endVar = $end_msg + 1; |
405 | |
406 | /* Loop through and display the info for each message. */ |
407 | $t = 0; // $t is used for the checkbox number |
408 | if ($num_msgs == 0) { // if there's no messages in this folder |
409 | echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order) . ">\n". |
410 | " <CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR> </CENTER>\n". |
411 | "</TD></TR>"; |
412 | } elseif ($start_msg == $end_msg) { |
413 | /* If there's only one message in the box, handle it differently. */ |
414 | if ($sort != 6) { |
415 | $i = $start_msg; |
416 | } else { |
417 | $i = 1; |
418 | } |
419 | |
420 | reset($msort); |
421 | $k = 0; |
422 | do { |
423 | $key = key($msort); |
424 | next($msort); |
425 | $k++; |
426 | } while (isset ($key) && ($k < $i)); |
427 | printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0); |
428 | } else { |
429 | $i = $start_msg; |
430 | |
431 | reset($msort); |
432 | $k = 0; |
433 | do { |
434 | $key = key($msort); |
435 | next($msort); |
436 | $k++; |
437 | } while (isset ($key) && ($k < $i)); |
438 | |
439 | do { |
440 | printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0); |
441 | $key = key($msort); |
442 | $t++; |
443 | $i++; |
444 | next($msort); |
445 | } while ($i && $i < $endVar); |
446 | } |
447 | |
448 | echo '</table>'. |
449 | "<table bgcolor=\"$color[9]\" width=100% border=0 cellpadding=1 cellspacing=1>" . |
450 | "<tr BGCOLOR=\"$color[4]\">" . |
451 | "<table width=100% BGCOLOR=\"$color[4]\" border=0 cellpadding=1 cellspacing=0><tr><td>$paginator_str</td>". |
452 | "<td align=right>$msg_cnt_str</td></tr></table>". |
453 | "</tr>". |
454 | "</table>"; |
455 | /** End of message-list table */ |
456 | |
457 | do_hook('mailbox_index_after'); |
458 | echo "</TABLE></FORM>\n"; |
459 | } |
460 | |
461 | /** |
462 | * Displays the standard message list header. To finish the table, |
463 | * you need to do a "</table></table>"; |
464 | * |
465 | * $moveURL is the URL to submit the delete/move form to |
466 | * $mailbox is the current mailbox |
467 | * $sort is the current sorting method (-1 for no sorting available [searches]) |
468 | * $Message is a message that is centered on top of the list |
469 | * $More is a second line that is left aligned |
470 | */ |
471 | function mail_message_listing_beginning |
f7b1b3b1 |
472 | ($imapConnection, $moveURL, $mailbox = '', $sort = -1, |
bdfb67f8 |
473 | $msg_cnt_str = '', $paginator = ' ', $start_msg = 1) { |
474 | global $color, $index_order, $auto_expunge, $move_to_trash; |
475 | global $checkall, $sent_folder, $draft_folder; |
476 | $urlMailbox = urlencode($mailbox); |
477 | |
478 | /* |
479 | * This is the beginning of the message list table. |
480 | * It wraps around all messages |
481 | */ |
7b294953 |
482 | echo "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"0\">\n" |
483 | . "<TR BGCOLOR=\"$color[0]\"><TD>" |
484 | . " <TABLE BGCOLOR=\"$color[4]\" width=\"100%\" CELLPADDING=\"2\" CELLSPACING=\"0\" BORDER=\"0\"><TR>\n" |
485 | . " <TD ALIGN=LEFT>$paginator</TD>\n" |
486 | . " <TD ALIGN=RIGHT>$msg_cnt_str</TD>\n" |
487 | . " </TR></TABLE>\n" |
488 | . '</TD></TR>' |
489 | . "<TR><TD BGCOLOR=\"$color[0]\">\n" |
490 | . "<FORM name=messageList method=post action=\"$moveURL\">\n" |
491 | . "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=\"100%\">\n" |
492 | . " <TR>\n" |
493 | . " <TD ALIGN=LEFT VALIGN=CENTER NOWRAP>\n" |
494 | . ' <SMALL> ' . _("Move selected to:") . "</SMALL>\n" |
495 | . " </TD>\n" |
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">'; |
bdfb67f8 |
503 | |
504 | $boxes = sqimap_mailbox_list($imapConnection); |
505 | for ($i = 0; $i < count($boxes); $i++) { |
506 | if (!in_array("noselect", $boxes[$i]['flags'])) { |
90bc0b93 |
507 | $box = $boxes[$i]['unformatted']; |
3b7e638f |
508 | $box2 = str_replace(' ', ' ', $boxes[$i]['unformatted-disp']); |
14eb705c |
509 | echo " <OPTION VALUE=\"$box\">$box2</option>\n"; |
bdfb67f8 |
510 | } |
511 | } |
512 | echo ' </SELECT></TT></SMALL>'. |
513 | "<SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"" . _("Move") . "\"></SMALL>\n". |
514 | " </TD>\n". |
515 | " <TD ALIGN=RIGHT NOWRAP> \n"; |
516 | if (!$auto_expunge) { |
517 | echo ' <INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'"> '. _("mailbox") ." \n"; |
518 | } |
519 | echo " <INPUT TYPE=SUBMIT NAME=\"markRead\" VALUE=\"". _("Read")."\">\n". |
520 | " <INPUT TYPE=SUBMIT NAME=\"markUnread\" VALUE=\"". _("Unread")."\">\n". |
521 | " <INPUT TYPE=SUBMIT VALUE=\"". _("Delete") . "\"> \n". |
522 | " </TD>\n". |
523 | " </TR>\n". |
524 | "</TABLE>\n"; |
525 | do_hook('mailbox_form_before'); |
526 | echo '</TD></TR>'. |
527 | |
528 | "<TR><TD BGCOLOR=\"$color[0]\">". |
529 | "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING="; |
530 | if ($GLOBALS['alt_index_colors']) { |
ac53fb56 |
531 | echo "0"; |
bdfb67f8 |
532 | } else { |
ac53fb56 |
533 | echo "1"; |
bdfb67f8 |
534 | } |
535 | echo " BGCOLOR=\"$color[0]\">". |
536 | "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">"; |
537 | |
538 | /* Print the headers. */ |
539 | for ($i=1; $i <= count($index_order); $i++) { |
540 | switch ($index_order[$i]) { |
541 | case 1: /* checkbox */ |
542 | case 5: /* flags */ |
543 | echo ' <TD WIDTH="1%"><B> </B></TD>'; |
544 | break; |
545 | |
546 | case 2: /* from */ |
547 | if (($mailbox == $sent_folder) |
548 | || ($mailbox == $draft_folder)) { |
549 | echo ' <TD WIDTH="25%"><B>'. _("To") .'</B>'; |
550 | } else { |
551 | echo ' <TD WIDTH="25%"><B>'. _("From") .'</B>'; |
552 | } |
553 | |
554 | ShowSortButton($sort, $mailbox, 2, 3); |
555 | echo "</TD>\n"; |
556 | break; |
557 | |
558 | case 3: /* date */ |
559 | echo ' <TD NOWRAP WIDTH="5%"><B>'. _("Date") .'</B>'; |
560 | ShowSortButton($sort, $mailbox, 0, 1); |
561 | echo "</TD>\n"; |
562 | break; |
563 | |
564 | case 4: /* subject */ |
565 | echo ' <TD><B>'. _("Subject") .'</B> '; |
566 | ShowSortButton($sort, $mailbox, 4, 5); |
567 | echo "</TD>\n"; |
568 | break; |
569 | |
570 | case 6: /* size */ |
571 | echo ' <TD WIDTH="5%"><b>' . _("Size")."</b></TD>\n"; |
572 | break; |
573 | } |
574 | } |
575 | echo "</TR>\n"; |
576 | } |
577 | |
578 | /* |
579 | * This function shows the sort button. Isn't this a good comment? |
580 | */ |
581 | function ShowSortButton($sort, $mailbox, $Up, $Down) { |
582 | /* Figure out which image we want to use. */ |
583 | if ($sort != $Up && $sort != $Down) { |
001befaf |
584 | $img = 'sort_none.png'; |
bdfb67f8 |
585 | $which = $Up; |
586 | } elseif ($sort == $Up) { |
001befaf |
587 | $img = 'up_pointer.png'; |
bdfb67f8 |
588 | $which = $Down; |
589 | } else { |
001befaf |
590 | $img = 'down_pointer.png'; |
bdfb67f8 |
591 | $which = 6; |
592 | } |
593 | |
594 | /* Now that we have everything figured out, show the actual button. */ |
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>'; |
599 | } |
600 | |
601 | function get_selectall_link($start_msg, $sort) { |
602 | global $checkall, $PHP_SELF, $what, $where, $mailbox, $javascript_on; |
603 | |
604 | if ($javascript_on) { |
605 | $result = |
606 | '<script language="JavaScript">' . |
607 | "\n<!-- \n" . |
608 | "function CheckAll() {\n" . |
609 | " for (var i = 0; i < document.messageList.elements.length; i++) {\n" . |
610 | " if( document.messageList.elements[i].type == 'checkbox' ) {\n" . |
611 | " document.messageList.elements[i].checked = !(document.messageList.elements[i].checked);\n". |
612 | " }\n" . |
613 | " }\n" . |
614 | "}\n" . |
615 | "//-->\n" . |
616 | '</script><a href=# onClick="CheckAll();">' . _("Toggle All") . "</a>\n"; |
617 | } else { |
618 | $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox) |
c57b0888 |
619 | . "&startMessage=$start_msg&sort=$sort&checkall="; |
bdfb67f8 |
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) |
628 | . '&what=' . urlencode($what); |
629 | } |
630 | |
631 | $result .= "\">"; |
632 | |
633 | if (isset($checkall) && ($checkall == '1')) { |
634 | $result .= _("Unselect All"); |
23d6bd09 |
635 | } else { |
bdfb67f8 |
636 | $result .= _("Select All"); |
23d6bd09 |
637 | } |
638 | |
bdfb67f8 |
639 | $result .= "</A>\n"; |
23d6bd09 |
640 | } |
641 | |
bdfb67f8 |
642 | /* Return our final result. */ |
643 | return ($result); |
644 | } |
1a0e0983 |
645 | |
bdfb67f8 |
646 | /** |
647 | * This function computes the "Viewing Messages..." string. |
648 | */ |
649 | function get_msgcnt_str($start_msg, $end_msg, $num_msgs) { |
650 | /* Compute the $msg_cnt_str. */ |
651 | $result = ''; |
652 | if ($start_msg < $end_msg) { |
653 | $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"), $start_msg, $end_msg, $num_msgs); |
654 | } else if ($start_msg == $end_msg) { |
655 | $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg); |
656 | } else { |
657 | $result = '<br>'; |
658 | } |
23d6bd09 |
659 | |
bdfb67f8 |
660 | /* Return our result string. */ |
661 | return ($result); |
662 | } |
663 | |
664 | /** |
7b294953 |
665 | * Generate a paginator link. |
666 | */ |
667 | function get_paginator_link |
668 | ($box, $start_msg, $use, $text) { |
669 | $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use" |
670 | . "&startMessage=$start_msg&mailbox=$box\" " |
671 | . "TARGET=\"right\">$text</A>"; |
672 | return ($result); |
673 | } |
674 | |
675 | /** |
676 | * This function computes the paginator string. |
677 | */ |
bdfb67f8 |
678 | function get_paginator_str |
7b294953 |
679 | ($box, $start_msg, $end_msg, $num_msgs, $show_num, $sort) { |
bdfb67f8 |
680 | global $username, $data_dir, $use_mailbox_cache, $color; |
681 | |
7b294953 |
682 | /* Initialize paginator string chunks. */ |
683 | $prv_str = ''; |
684 | $nxt_str = ''; |
685 | $pg_str = ''; |
686 | $all_str = ''; |
687 | $tgl_str = ''; |
688 | |
689 | /* Create simple strings that will be creating the paginator. */ |
690 | $spc = ' '; /* This will be used as a space. */ |
691 | $sep = '|'; /* This will be used as a seperator. */ |
bdfb67f8 |
692 | |
7b294953 |
693 | /* Get some paginator preference values. */ |
311339a0 |
694 | $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON); |
7b294953 |
695 | $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX); |
696 | |
697 | /* Make sure that our start message number is not too big. */ |
698 | $start_msg = min($start_msg, $num_msgs); |
699 | |
700 | /* Decide whether or not we will use the mailbox cache. */ |
701 | /* Not sure why $use_mailbox_cache is even passed in. */ |
bdfb67f8 |
702 | if ($sort == 6) { |
703 | $use = 0; |
704 | } else { |
705 | $use = 1; |
706 | } |
7b294953 |
707 | |
708 | /* Compute the starting message of the previous and next page group. */ |
709 | $next_grp = $start_msg + $show_num; |
710 | $prev_grp = $start_msg - $show_num; |
711 | |
712 | /* Compute the basic previous and next strings. */ |
713 | if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) { |
714 | $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous")); |
715 | $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next")); |
716 | } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) { |
717 | $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous")); |
718 | $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n"; |
719 | } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) { |
720 | $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>'; |
721 | $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next")); |
bdfb67f8 |
722 | } |
7b294953 |
723 | |
bdfb67f8 |
724 | /* Page selector block. Following code computes page links. */ |
7b294953 |
725 | if ($pg_sel && ($num_msgs > $show_num)) { |
726 | /* Most importantly, what is the current page!!! */ |
727 | $cur_pg = intval($start_msg / $show_num) + 1; |
728 | |
729 | /* Compute total # of pages and # of paginator page links. */ |
730 | $tot_pgs = ceil($num_msgs / $show_num); /* Total # of Pages */ |
731 | $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */ |
732 | |
733 | /************************************************************/ |
734 | /* Compute the size of the four quarters of the page links. */ |
735 | /************************************************************/ |
736 | |
737 | /* If we can, just show all the pages. */ |
738 | if (($tot_pgs - 1) <= $pg_max) { |
739 | $q1_pgs = $cur_pg - 1; |
740 | $q2_pgs = $q3_pgs = 0; |
741 | $q4_pgs = $tot_pgs - $cur_pg; |
742 | |
743 | /* Otherwise, compute some magic to choose the four quarters. */ |
744 | } else { |
745 | /* Compute the magic base values. Added together, */ |
746 | /* these values will always equal to the $pag_pgs. */ |
747 | /* NOTE: These are DEFAULT values and do not take */ |
748 | /* the current page into account. That is below. */ |
749 | $q1_pgs = floor($vis_pgs/4); |
750 | $q2_pgs = round($vis_pgs/4, 0); |
751 | $q3_pgs = ceil($vis_pgs/4); |
752 | $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0); |
753 | |
754 | /* Adjust if the first quarter contains the current page. */ |
755 | if (($cur_pg - $q1_pgs) < 1) { |
756 | $extra_pgs = ($q1_pgs - ($cur_pg - 1)) + $q2_pgs; |
757 | $q1_pgs = $cur_pg - 1; |
758 | $q2_pgs = 0; |
759 | $q3_pgs += ceil($extra_pgs / 2); |
760 | $q4_pgs += floor($extra_pgs / 2); |
761 | |
762 | /* Adjust if the first and second quarters intersect. */ |
763 | } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) { |
764 | $extra_pgs = $q2_pgs; |
765 | $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75); |
766 | $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75); |
767 | $q3_pgs += ceil($extra_pgs / 2); |
768 | $q4_pgs += floor($extra_pgs / 2); |
769 | |
770 | /* Adjust if the fourth quarter contains the current page. */ |
771 | } else if (($cur_pg + $q4_pgs) >= $tot_pgs) { |
772 | $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) + $q3_pgs; |
773 | $q3_pgs = 0; |
774 | $q4_pgs = $tot_pgs - $cur_pg; |
775 | $q1_pgs += floor($extra_pgs / 2); |
776 | $q2_pgs += ceil($extra_pgs / 2); |
777 | |
778 | /* Adjust if the third and fourth quarter intersect. */ |
779 | } else if (($cur_pg + $q3_pgs + 1) >= ($tot_pgs - $q4_pgs + 1)) { |
780 | $extra_pgs = $q3_pgs; |
781 | $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75); |
782 | $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75); |
783 | $q1_pgs += floor($extra_pgs / 2); |
784 | $q2_pgs += ceil($extra_pgs / 2); |
785 | } |
23d6bd09 |
786 | } |
7b294953 |
787 | |
788 | /* I am leaving this debug code here, commented out, because */ |
789 | /* it is a really nice way to see what the above code is doing. */ |
790 | /* echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = " */ |
791 | /* . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>'; */ |
792 | |
793 | /************************************************************/ |
794 | /* Print out the page links from the compute page quarters. */ |
795 | /************************************************************/ |
796 | |
797 | /* Start with the first quarter. */ |
798 | if (($q1_pgs == 0) && ($cur_pg > 1)) { |
799 | $pg_str .= "...$spc"; |
800 | } else { |
801 | for ($pg = 1; $pg <= $q1_pgs; ++$pg) { |
802 | $start = (($pg-1) * $show_num) + 1; |
803 | $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc; |
804 | } |
805 | if ($cur_pg - $q2_pgs - $q1_pgs > 1) { |
806 | $pg_str .= "...$spc"; |
807 | } |
23d6bd09 |
808 | } |
7b294953 |
809 | |
810 | /* Continue with the second quarter. */ |
811 | for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++$pg) { |
812 | $start = (($pg-1) * $show_num) + 1; |
813 | $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc; |
23d6bd09 |
814 | } |
7b294953 |
815 | |
816 | /* Now print the current page. */ |
817 | $pg_str .= $cur_pg . $spc; |
818 | |
819 | /* Next comes the third quarter. */ |
820 | for ($pg = $cur_pg + 1; $pg <= $cur_pg + $q3_pgs; ++$pg) { |
821 | $start = (($pg-1) * $show_num) + 1; |
822 | $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc; |
823 | } |
824 | |
825 | /* And last, print the forth quarter page links. */ |
826 | if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) { |
827 | $pg_str .= "...$spc"; |
828 | } else { |
829 | if (($tot_pgs - $q4_pgs) > ($cur_pg + $q3_pgs)) { |
830 | $pg_str .= "...$spc"; |
831 | } |
832 | for ($pg = $tot_pgs - $q4_pgs + 1; $pg <= $tot_pgs; ++$pg) { |
833 | $start = (($pg-1) * $show_num) + 1; |
834 | $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc; |
835 | } |
836 | } |
837 | } |
838 | |
839 | /* If necessary, compute the 'show all' string. */ |
840 | if (($prv_str != '') || ($nxt_str != '')) { |
841 | $all_str = "<A HREF=\"right_main.php?PG_SHOWNUM=9999" |
842 | . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" " |
843 | . "TARGET=\"right\">" . _("Show All") . '</A>'; |
bdfb67f8 |
844 | } |
23d6bd09 |
845 | |
7b294953 |
846 | /* Last but not least, get the value for the toggle all link. */ |
847 | $tgl_str = get_selectall_link($start_msg, $sort); |
848 | |
849 | /* Put all the pieces of the paginator string together. */ |
850 | $result = ''; |
851 | $result .= ($all_str != '' ? $all_str . $spc . $sep . $spc: ''); |
852 | $result .= ($prv_str != '' ? $prv_str . $spc . $sep . $spc : ''); |
853 | $result .= ($pg_str != '' ? $pg_str . $sep . $spc : ''); |
854 | $result .= ($nxt_str != '' ? $nxt_str : ''); |
855 | $result .= ($result != '' ? $spc . $sep . $spc . $tgl_str: $tgl_str); |
856 | |
857 | /* If the resulting string is blank, return a non-breaking space. */ |
858 | if ($result == '') { |
859 | $result = ' '; |
bdfb67f8 |
860 | } |
7b294953 |
861 | |
862 | /* Return our final magical paginator string. */ |
863 | return ($result); |
bdfb67f8 |
864 | } |
865 | |
866 | function processSubject($subject) { |
867 | // Shouldn't ever happen -- caught too many times in the IMAP functions |
868 | if ($subject == '') |
869 | return _("(no subject)"); |
870 | |
871 | if (strlen($subject) <= 55) |
872 | return $subject; |
873 | |
874 | $ent_strlen=strlen($subject); |
875 | $trim_val=50; |
876 | $ent_offset=0; |
877 | // see if this is entities-encoded string |
878 | // If so, Iterate through the whole string, find out |
879 | // the real number of characters, and if more |
880 | // than 55, substr with an updated trim value. |
881 | while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false && |
882 | ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false) |
883 | { |
884 | $trim_val += ($ent_loc_end-$ent_loc)+1; |
885 | $ent_strlen -= $ent_loc_end-$ent_loc; |
886 | $ent_offset = $ent_loc_end+1; |
887 | } |
23d6bd09 |
888 | |
bdfb67f8 |
889 | if ($ent_strlen <= 55) |
890 | return $subject; |
891 | |
892 | return substr($subject, 0, $trim_val) . '...'; |
893 | } |
f93c93b9 |
894 | |
c57b0888 |
895 | ?> |