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