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 | |
46d38f78 |
15 | require_once('../functions/strings.php'); |
8008456a |
16 | require_once('../functions/html.php'); |
e35045b7 |
17 | require_once('../functions/imap_utf7_decode_local.php'); |
43fdb2a4 |
18 | |
6c930ade |
19 | /* Default value for page_selector_max. */ |
20 | define('PG_SEL_MAX', 10); |
21 | |
8008456a |
22 | function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, |
c1c17724 |
23 | $start_msg, $where, $what){ |
8008456a |
24 | global $checkall, |
c1c17724 |
25 | $color, $msgs, $msort, |
26 | $sent_folder, $draft_folder, |
27 | $default_use_priority, |
28 | $message_highlight_list, |
29 | $index_order, |
30 | $indent_array, /* indent subject by */ |
31 | $pos, /* Search postion (if any) */ |
32 | $thread_sort_messages, /* thread sorting on/off */ |
33 | $server_sort_order, /* sort value when using server-sorting */ |
34 | $row_count, |
35 | $allow_server_sort; /* enable/disable server-side sorting */ |
36 | $color_string = $color[4]; |
8008456a |
37 | |
38 | if ($GLOBALS['alt_index_colors']) { |
39 | if (!isset($row_count)) { |
40 | $row_count = 0; |
41 | } |
42 | $row_count++; |
43 | if ($row_count % 2) { |
44 | if (!isset($color[12])) { |
45 | $color[12] = '#EAEAEA'; |
46 | } |
47 | $color_string = $color[12]; |
48 | } |
bdfb67f8 |
49 | } |
8008456a |
50 | $msg = $msgs[$key]; |
51 | |
52 | /* |
53 | * This is done in case you're looking into Sent folders, |
54 | * because you can have multiple receivers. |
55 | */ |
56 | $senderNames = explode(',', $msg['FROM']); |
57 | $senderName = ''; |
58 | if (sizeof($senderNames)){ |
59 | foreach ($senderNames as $senderNames_part) { |
60 | if ($senderName != '') { |
61 | $senderName .= ', '; |
62 | } |
63 | $senderName .= sqimap_find_displayable_name($senderNames_part); |
64 | } |
bdfb67f8 |
65 | } |
8008456a |
66 | |
67 | if( $mailbox == 'None' ) { |
68 | $boxes = sqimap_mailbox_list($imapConnection); |
69 | $mailbox = $boxes[0]['unformatted']; |
70 | unset( $boxes ); |
bdfb67f8 |
71 | } |
8008456a |
72 | $urlMailbox = urlencode($mailbox); |
73 | $subject = processSubject($msg['SUBJECT']); |
6b4bd11f |
74 | echo html_tag( 'tr' ) . "\n"; |
8008456a |
75 | |
76 | if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) { |
77 | $flag = "<font color=\"$color[2]\">"; |
78 | $flag_end = '</font>'; |
79 | } else { |
80 | $flag = ''; |
81 | $flag_end = ''; |
bdfb67f8 |
82 | } |
8008456a |
83 | if (!isset($msg['FLAG_SEEN']) || ($msg['FLAG_SEEN'] == false)) { |
84 | $bold = '<b>'; |
85 | $bold_end = '</b>'; |
86 | } else { |
87 | $bold = ''; |
88 | $bold_end = ''; |
bdfb67f8 |
89 | } |
8008456a |
90 | if (handleAsSent($mailbox)) { |
91 | $italic = '<i>'; |
92 | $italic_end = '</i>'; |
93 | } else { |
94 | $italic = ''; |
95 | $italic_end = ''; |
96 | } |
97 | if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) { |
98 | $fontstr = "<font color=\"$color[9]\">"; |
99 | $fontstr_end = '</font>'; |
100 | } else { |
101 | $fontstr = ''; |
102 | $fontstr_end = ''; |
103 | } |
104 | |
105 | /** |
106 | * AAAAH! Make my eyes stop bleeding! |
107 | * Who wrote this?! |
108 | */ |
109 | if (sizeof($message_highlight_list)){ |
110 | foreach ($message_highlight_list as $message_highlight_list_part) { |
111 | if (trim($message_highlight_list_part['value']) != '') { |
112 | if ($message_highlight_list_part['match_type'] == 'to_cc') { |
113 | if (strstr('^^' . strtolower($msg['TO']), |
114 | strtolower($message_highlight_list_part['value'])) |
115 | || strstr('^^'.strtolower($msg['CC']), |
116 | strtolower($message_highlight_list_part['value']))) { |
117 | $hlt_color = $message_highlight_list_part['color']; |
118 | continue; |
119 | } |
120 | } else |
121 | if (strstr('^^' . strtolower($msg[strtoupper($message_highlight_list_part['match_type'])]), |
122 | strtolower($message_highlight_list_part['value']))) { |
123 | $hlt_color = $message_highlight_list_part['color']; |
124 | continue; |
125 | } |
126 | } |
127 | } |
128 | } |
129 | |
130 | if (!isset($hlt_color)) { |
131 | $hlt_color = $color_string; |
132 | } |
133 | |
134 | if ($where && $what) { |
135 | if(!isset($pos) || $pos == '') { |
136 | $pos = '0'; |
137 | } |
138 | $search_stuff = "&pos=" . urlencode($pos) |
139 | . "&where=" . urlencode($where) . '&what=' . urlencode($what); |
140 | } else { |
141 | $search_stuff = ''; |
2728fa19 |
142 | } |
8008456a |
143 | |
144 | $checked = ($checkall == 1) ? ' checked' : ''; |
145 | |
146 | if (sizeof($index_order)){ |
147 | foreach ($index_order as $index_order_part) { |
148 | switch ($index_order_part) { |
149 | case 1: /* checkbox */ |
150 | echo html_tag( 'td', |
151 | "<input type=checkbox name=\"msg[$t]\" value=\"".$msg['ID']."\"$checked>", |
152 | 'center', |
153 | $hlt_color ); |
154 | break; |
155 | case 2: /* from */ |
156 | echo html_tag( 'td', |
157 | $italic . $bold . $flag . $fontstr . $senderName . |
158 | $fontstr_end . $flag_end . $bold_end . $italic_end, |
c1c17724 |
159 | 'left', |
8008456a |
160 | $hlt_color ); |
161 | break; |
162 | case 3: /* date */ |
163 | echo html_tag( 'td', |
164 | $bold . $flag . $fontstr . $msg['DATE_STRING'] . |
165 | $fontstr_end . $flag_end . $bold_end, |
166 | 'center', |
167 | $hlt_color, |
168 | 'nowrap' ); |
169 | break; |
170 | case 4: /* subject */ |
171 | $td_str = $bold; |
172 | if ($thread_sort_messages == 1) { |
173 | if (isset($indent_array[$msg["ID"]])) { |
174 | $td_str .= str_repeat(" ",$indent_array[$msg['ID']]); |
175 | } |
176 | } |
177 | $td_str .= "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=" |
178 | . $msg["ID"] |
a51dec54 |
179 | . "&startMessage=$start_msg&show_more=0\""; |
8008456a |
180 | do_hook("subject_link"); |
181 | if ($subject != $msg['SUBJECT']) { |
182 | $title = get_html_translation_table(HTML_SPECIALCHARS); |
183 | $title = array_flip($title); |
184 | $title = strtr($msg['SUBJECT'], $title); |
185 | $title = str_replace('"', "''", $title); |
186 | $td_str .= " title=\"$title\""; |
187 | } |
188 | $td_str .= ">$flag$subject$flag_end</a>$bold_end"; |
c1c17724 |
189 | echo html_tag( 'td', $td_str, 'left', $hlt_color ); |
8008456a |
190 | break; |
191 | case 5: /* flags */ |
192 | $stuff = false; |
193 | $td_str = "<b><small>"; |
194 | |
195 | if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) { |
196 | $td_str .= _("A"); |
197 | $stuff = true; |
198 | } |
199 | if ($msg['TYPE0'] == 'multipart') { |
200 | $td_str .= '+'; |
201 | $stuff = true; |
202 | } |
203 | if ($default_use_priority) { |
204 | if ( ($msg['PRIORITY'] == 1) || ($msg['PRIORITY'] == 2) ) { |
205 | $td_str .= "<font color=\"$color[1]\">!</font>"; |
206 | $stuff = true; |
207 | } |
208 | if ($msg['PRIORITY'] == 5) { |
209 | $td_str .= "<font color=\"$color[8]\">?</font>"; |
210 | $stuff = true; |
211 | } |
212 | } |
213 | if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) { |
214 | $td_str .= "<font color=\"$color[1]\">D</font>"; |
215 | $stuff = true; |
216 | } |
217 | if (!$stuff) { |
218 | $td_str .= ' '; |
219 | } |
220 | $td_str .= '</small></b>'; |
221 | echo html_tag( 'td', |
222 | $td_str, |
223 | 'center', |
224 | $hlt_color, |
225 | 'nowrap' ); |
226 | break; |
227 | case 6: /* size */ |
228 | |
229 | echo html_tag( 'td', |
230 | $bold . $fontstr . show_readable_size($msg['SIZE']) . |
231 | $fontstr_end . $bold_end, |
232 | 'right', |
233 | $hlt_color ); |
234 | break; |
235 | } |
236 | } |
bdfb67f8 |
237 | } |
8008456a |
238 | echo "</tr>\n"; |
bdfb67f8 |
239 | } |
240 | |
6c930ade |
241 | /* |
e35045b7 |
242 | * This function loops through a group of messages in the mailbox |
243 | * and shows them to the user. |
244 | */ |
245 | function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs, |
246 | $start_msg, $sort, $color, $show_num, |
247 | $use_cache) { |
248 | global $msgs, $msort, |
249 | $sent_folder, $draft_folder, |
250 | $message_highlight_list, |
251 | $auto_expunge, $thread_sort_messages, $allow_server_sort, |
252 | $data_dir, $username, $server_sort_order, $php_sort_order; |
253 | |
254 | |
255 | /* If autoexpunge is turned on, then do it now. */ |
256 | |
257 | $mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox); |
258 | $issent = handleAsSent($mailbox); |
259 | |
260 | /* If autoexpunge is turned on, then do it now. */ |
261 | if ($auto_expunge == true) { |
262 | $exp_cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, false, ''); |
263 | $mbxresponse['EXISTS'] = $mbxresponse['EXISTS'] - $exp_cnt; |
264 | } |
265 | |
266 | |
267 | if ($mbxresponse['EXISTS']>0) { |
aa0da530 |
268 | |
8008456a |
269 | /* if $start_msg is lower than $num_msgs, we probably deleted all messages |
e35045b7 |
270 | * in the last page. We need to re-adjust the start_msg |
271 | */ |
4e9f35e4 |
272 | |
8008456a |
273 | if($start_msg > $num_msgs) { |
e35045b7 |
274 | $start_msg -= $show_num; |
275 | if($start_msg < 1) { |
276 | $start_msg = 1; |
277 | } |
bdfb67f8 |
278 | } |
8008456a |
279 | |
280 | /* This code and the next if() block check for |
e35045b7 |
281 | * server-side sorting methods. The $id array is |
282 | * formatted and $sort is set to 6 to disable |
283 | * SM internal sorting |
284 | */ |
285 | if ($thread_sort_messages == 1) { |
8008456a |
286 | $id = get_thread_sort($imapConnection); |
287 | if ($id == 'no') { |
288 | echo '<b><small><center><font color=red>' . |
289 | _("Thread sorting is not supported by your IMAP server.<br>Please report this to the system administrator."). |
290 | '</center></small></b>'; |
e35045b7 |
291 | $thread_sort_messages = 0; |
292 | $id = array(); |
293 | } else { |
294 | $sort = 6; |
295 | if ($start_msg + ($show_num - 1) < $num_msgs) { |
296 | $end_msg = $start_msg + ($show_num-1); |
297 | } else { |
298 | $end_msg = $num_msgs; |
299 | } |
300 | $id = array_slice($id, ($start_msg-1), ($end_msg)); |
301 | } |
7c612fdd |
302 | } |
e3324f30 |
303 | |
8008456a |
304 | if ($allow_server_sort == TRUE && $thread_sort_messages != 1) { |
e35045b7 |
305 | $server_sort_order = $sort; |
306 | $id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse); |
307 | if ($id == 'no') { |
8008456a |
308 | echo '<b><small><center><font color=red>' . |
309 | _( "Server-side sorting is not supported by your IMAP server.<br>Please report this to the system administrator."). |
310 | '</center></small></b>'; |
e35045b7 |
311 | $sort = $server_sort_order; |
312 | $allow_server_sort = FALSE; |
313 | $id = array(); |
314 | } else { |
315 | $sort = 6; |
316 | if ($start_msg + ($show_num - 1) < $num_msgs) { |
317 | $end_msg = $start_msg + ($show_num-1); |
318 | } else { |
319 | $end_msg = $num_msgs; |
320 | } |
321 | $id = array_slice($id, ($start_msg-1), ($end_msg)); |
322 | } |
bdfb67f8 |
323 | } |
bdfb67f8 |
324 | |
8008456a |
325 | if (!$use_cache) { |
e35045b7 |
326 | /* If it is sorted... */ |
327 | if ($num_msgs >= 1) { |
328 | if ($sort < 6 ) { |
329 | $id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse); |
330 | } elseif ($thread_sort_messages != 1 && $allow_server_sort != TRUE && $sort == 6) { |
331 | /* if it's not sorted */ |
332 | $id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse); |
333 | if ($start_msg + ($show_num - 1) < $num_msgs) { |
334 | $end_msg = $start_msg + ($show_num - 1); |
335 | } else { |
336 | $end_msg = $num_msgs; |
337 | } |
338 | if ($end_msg < $start_msg) { |
339 | $start_msg = $start_msg - $show_num; |
340 | if ($start_msg < 1) { |
341 | $start_msg = 1; |
342 | } |
343 | } |
344 | |
345 | $real_startMessage = $num_msgs - $start_msg + 1; |
346 | $real_endMessage = $num_msgs - $start_msg - $show_num + 2; |
347 | if ($real_endMessage <= 0) { |
348 | $real_endMessage = 1; |
349 | } |
350 | $id = array_slice(array_reverse($id), ($start_msg-1), ($end_msg)); |
8008456a |
351 | } |
e35045b7 |
352 | } |
353 | if ($sort == 6) { |
354 | $end = $start_msg + $show_num - 1; |
355 | if ($num_msgs < $show_num) { |
356 | $end_loop = $num_msgs; |
357 | } else if ($end > $num_msgs) { |
358 | $end_loop = $num_msgs - $start_msg + 1; |
359 | } else { |
360 | $end_loop = $show_num; |
361 | } |
362 | } else { |
363 | $end = $num_msgs; |
364 | $end_loop = $end; |
365 | } |
366 | |
367 | $messages = fillMessageArray($imapConnection,$id,$issent,$end_loop); |
368 | if (!isset($messages)) { |
369 | $messages = array(); |
370 | } |
371 | $msgs = $messages; |
372 | |
373 | } |
8008456a |
374 | |
e35045b7 |
375 | $msort = calc_msort($msgs, $sort, $num_msgs, $use_cache); |
8008456a |
376 | |
8008456a |
377 | |
378 | /* There's gotta be messages in the array for it to sort them. */ |
e35045b7 |
379 | } /* if exists > 0 */ |
380 | displayMessageArray($imapConnection, $num_msgs, $start_msg, $msgs, |
381 | $msort, $mailbox, $sort, $color,$show_num); |
382 | /** |
383 | * TODO: Switch to using $_SESSION[] whenever we ditch the 4.0.x series. |
384 | */ |
385 | session_register('msgs'); |
6c930ade |
386 | } |
bdfb67f8 |
387 | |
e35045b7 |
388 | function calc_msort($msgs, $sort, $num_msgs, $use_cache) { |
389 | global $thread_sort_messages, $allow_server_sort; |
8008456a |
390 | |
e35045b7 |
391 | if (($num_msgs > 0) && (!$use_cache)) { |
392 | /* |
393 | * 0 = Date (up) |
394 | * 1 = Date (dn) |
395 | * 2 = Name (up) |
396 | * 3 = Name (dn) |
397 | * 4 = Subject (up) |
398 | * 5 = Subject (dn) |
399 | */ |
400 | session_unregister('msgs'); |
401 | if (($sort == 0) || ($sort == 1)) { |
402 | $msort = array_cleave ($msgs, 'TIME_STAMP'); |
403 | } elseif (($sort == 2) || ($sort == 3)) { |
404 | $msort = array_cleave ($msgs, 'FROM-SORT'); |
405 | } elseif (($sort == 4) || ($sort == 5)) { |
406 | $msort = array_cleave ($msgs, 'SUBJECT-SORT'); |
bdfb67f8 |
407 | } else { |
e35045b7 |
408 | $msort = $msgs; |
bdfb67f8 |
409 | } |
e35045b7 |
410 | if ($sort < 6) { |
411 | if ($sort % 2) { |
412 | asort($msort); |
413 | } else { |
414 | arsort($msort); |
415 | } |
416 | } |
417 | session_register('msort'); |
418 | } elseif ($thread_sort_messages == 1 || $allow_server_sort == TRUE) { |
419 | $msort = $msgs; |
420 | session_unregister('msgs'); |
421 | session_register('msort'); |
422 | } |
423 | return $msort; |
424 | } |
425 | |
426 | function fillMessageArray($imapConnection,$id,$issent,$count) { |
427 | $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent); |
428 | if (sizeof($msgs_list)){ |
429 | foreach ($msgs_list as $hdr) { |
430 | $unique_id[] = $hdr->uid; |
431 | $from[] = $hdr->from; |
432 | $date[] = $hdr->date; |
433 | $subject[] = $hdr->subject; |
434 | $to[] = $hdr->to; |
435 | $priority[] = $hdr->priority; |
436 | $cc[] = $hdr->cc; |
437 | $size[] = $hdr->size; |
438 | $type[] = $hdr->type0; |
439 | $flag_deleted[] = $hdr->flag_deleted; |
440 | $flag_answered[] = $hdr->flag_answered; |
441 | $flag_seen[] = $hdr->flag_seen; |
442 | $flag_flagged[] = $hdr->flag_flagged; |
443 | } |
444 | } |
445 | |
446 | $j = 0; |
447 | while ($j < $count) { |
448 | |
449 | if (isset($date[$j])) { |
450 | $date[$j] = str_replace(' ', ' ', $date[$j]); |
451 | $tmpdate = explode(' ', trim($date[$j])); |
452 | } else { |
453 | $tmpdate = $date = array('', '', '', '', '', ''); |
454 | } |
455 | $i = $unique_id[$j]; |
456 | $messages[$i]['TIME_STAMP'] = getTimeStamp($tmpdate); |
457 | $messages[$i]['DATE_STRING'] = |
458 | getDateString($messages[$i]['TIME_STAMP']); |
459 | $messages[$i]['ID'] = $i; |
460 | $messages[$i]['FROM'] = decodeHeader($from[$j]); |
461 | $messages[$i]['FROM-SORT'] = |
462 | strtolower(sqimap_find_displayable_name(decodeHeader($from[$j]))); |
463 | $messages[$i]['SUBJECT'] = decodeHeader($subject[$j]); |
464 | $messages[$i]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j])); |
465 | $messages[$i]['TO'] = decodeHeader($to[$j]); |
466 | $messages[$i]['PRIORITY'] = $priority[$j]; |
467 | $messages[$i]['CC'] = $cc[$j]; |
468 | $messages[$i]['SIZE'] = $size[$j]; |
469 | $messages[$i]['TYPE0'] = $type[$j]; |
470 | $messages[$i]['FLAG_DELETED'] = $flag_deleted[$j]; |
471 | $messages[$i]['FLAG_ANSWERED'] = $flag_answered[$j]; |
472 | $messages[$i]['FLAG_SEEN'] = $flag_seen[$j]; |
473 | $messages[$i]['FLAG_FLAGGED'] = $flag_flagged[$j]; |
474 | |
475 | |
476 | /* |
477 | * fix SUBJECT-SORT to remove Re: |
478 | * vedr|sv (Danish) |
479 | * re|aw (English) |
480 | * |
481 | * TODO: i18n should be incorporated here. E.g. we catch the ones |
482 | * we know about, but also define in i18n what the localized |
483 | * "Re: " is for this or that locale. |
484 | */ |
485 | if (preg_match("/^(vedr|sv|re|aw):\s*(.*)$/si", |
486 | $messages[$i]['SUBJECT-SORT'], $matches)){ |
487 | $messages[$i]['SUBJECT-SORT'] = $matches[2]; |
488 | } |
489 | $j++; |
490 | } |
491 | return $messages; |
492 | } |
8008456a |
493 | |
e35045b7 |
494 | /* Generic function to convert the msgs array into an HTML table. */ |
495 | function displayMessageArray($imapConnection, $num_msgs, $start_msg, |
496 | &$msgs, $msort, $mailbox, $sort, $color, |
497 | $show_num, $search=false) { |
498 | global $folder_prefix, $sent_folder, |
499 | $imapServerAddress, $data_dir, $username, $use_mailbox_cache, |
500 | $index_order, $real_endMessage, $real_startMessage, $checkall, |
501 | $indent_array, $thread_sort_messages, $allow_server_sort, $server_sort_order; |
502 | |
503 | /* If cache isn't already set, do it now. */ |
504 | if (!session_is_registered('msgs')) { |
505 | session_register('msgs'); |
506 | } |
507 | if (!session_is_registered('msort')) { |
508 | session_register('msort'); |
509 | } |
510 | |
511 | if ($start_msg + ($show_num - 1) < $num_msgs){ |
512 | $end_msg = $start_msg + ($show_num - 1); |
513 | } else { |
514 | $end_msg = $num_msgs; |
515 | } |
516 | |
517 | if ($end_msg < $start_msg) { |
518 | $start_msg = $start_msg - $show_num; |
519 | if ($start_msg < 1) { |
520 | $start_msg = 1; |
94ac35c6 |
521 | } |
e35045b7 |
522 | } |
8008456a |
523 | |
e35045b7 |
524 | $urlMailbox = urlencode($mailbox); |
8008456a |
525 | |
e35045b7 |
526 | do_hook('mailbox_index_before'); |
8008456a |
527 | |
e35045b7 |
528 | $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs); |
529 | $paginator_str = get_paginator_str($urlMailbox, $start_msg, $end_msg, |
530 | $num_msgs, $show_num, $sort); |
8008456a |
531 | |
e35045b7 |
532 | if (!isset($msg)) { |
533 | $msg = ''; |
534 | } |
8008456a |
535 | |
e35045b7 |
536 | /* get indent level for subject display */ |
537 | if ($thread_sort_messages == 1 ) { |
538 | $indent_array = get_parent_level($imapConnection); |
539 | } |
540 | $fstring = "move_messages.php?msg=$msg&mailbox=$urlMailbox" |
8008456a |
541 | . "&startMessage=$start_msg"; |
e35045b7 |
542 | mail_message_listing_beginning($imapConnection, $fstring, |
543 | $mailbox, $sort, $msg_cnt_str, |
544 | $paginator_str, $start_msg); |
545 | |
546 | $groupNum = $start_msg % ($show_num - 1); |
547 | $real_startMessage = $start_msg; |
548 | if ($sort == 6) { |
549 | if ($end_msg - $start_msg < $show_num - 1) { |
550 | $end_msg = $end_msg - $start_msg + 1; |
551 | $start_msg = 1; |
552 | } else if ($start_msg > $show_num) { |
553 | $end_msg = $show_num; |
554 | $start_msg = 1; |
94ac35c6 |
555 | } |
e35045b7 |
556 | } |
557 | $endVar = $end_msg + 1; |
558 | |
559 | /* |
560 | * Loop through and display the info for each message. |
561 | * ($t is used for the checkbox number) |
562 | */ |
563 | $t = 0; |
564 | if ($num_msgs == 0) { |
565 | /* if there's no messages in this folder */ |
8008456a |
566 | echo html_tag( 'tr', |
13cf639b |
567 | html_tag( 'td', |
6b4bd11f |
568 | "<BR><b>" . _("THIS FOLDER IS EMPTY") . "</b><BR> ", |
13cf639b |
569 | 'center', |
570 | $color[4], |
571 | 'COLSPAN="' . count($index_order) . '"' |
572 | ) |
573 | ); |
e35045b7 |
574 | } elseif ($start_msg == $end_msg) { |
575 | /* if there's only one message in the box, handle it differently. */ |
576 | if ($sort != 6){ |
577 | $i = $start_msg; |
94ac35c6 |
578 | } else { |
e35045b7 |
579 | $i = 1; |
94ac35c6 |
580 | } |
e35045b7 |
581 | reset($msort); |
582 | $k = 0; |
583 | do { |
584 | $key = key($msort); |
585 | next($msort); |
586 | $k++; |
587 | } while (isset ($key) && ($k < $i)); |
588 | printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, |
589 | $real_startMessage, 0, 0); |
590 | } else { |
591 | $i = $start_msg; |
592 | reset($msort); |
593 | $k = 0; |
594 | do { |
595 | $key = key($msort); |
596 | next($msort); |
597 | $k++; |
598 | } while (isset ($key) && ($k < $i)); |
599 | do { |
600 | printMessageInfo($imapConnection, $t, $i, $key, $mailbox, |
601 | $sort, $real_startMessage, 0, 0); |
602 | $key = key($msort); |
603 | $t++; |
604 | $i++; |
605 | next($msort); |
606 | } while ($i && $i < $endVar); |
607 | } |
608 | |
609 | echo '</table>'; |
8008456a |
610 | |
611 | echo html_tag( 'table', |
612 | html_tag( 'tr', |
613 | html_tag( 'td', |
614 | html_tag( 'table', |
615 | html_tag( 'tr', |
616 | html_tag( 'td', $paginator_str ) . |
617 | html_tag( 'td', $msg_cnt_str, 'right' ) |
94ac35c6 |
618 | ) |
8008456a |
619 | , '', $color[4], 'width="100%" cellpadding="1" cellspacing="1"' ) |
94ac35c6 |
620 | ) |
8008456a |
621 | , '', $color[4] ) |
622 | , '', $color[9], 'width="100%" cellpadding="1" cellspacing="1"' ); |
623 | |
8008456a |
624 | |
e35045b7 |
625 | /* End of message-list table */ |
626 | |
627 | do_hook('mailbox_index_after'); |
628 | echo "</TABLE></FORM>\n"; |
bdfb67f8 |
629 | } |
630 | |
6c930ade |
631 | /* |
e35045b7 |
632 | * Displays the standard message list header. To finish the table, |
633 | * you need to do a "</table></table>"; |
634 | * |
635 | * $moveURL is the URL to submit the delete/move form to |
636 | * $mailbox is the current mailbox |
637 | * $sort is the current sorting method (-1 for no sorting available [searches]) |
638 | * $Message is a message that is centered on top of the list |
639 | * $More is a second line that is left aligned |
640 | */ |
641 | |
642 | function mail_message_listing_beginning ($imapConnection, $moveURL, |
643 | $mailbox = '', $sort = -1, |
644 | $msg_cnt_str = '', |
645 | $paginator = ' ', |
646 | $start_msg = 1) { |
647 | global $color, $index_order, $auto_expunge, $move_to_trash, $base_uri, |
648 | $checkall, $sent_folder, $draft_folder, $thread_sort_messages, |
649 | $allow_thread_sort, $allow_server_sort, $server_sort_order, |
650 | $lastTargetMailbox, $PHP_SELF; |
651 | |
652 | $urlMailbox = urlencode($mailbox); |
653 | |
654 | if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) { |
655 | $source_url = $regs[1]; |
656 | } else { |
657 | $source_url = $PHP_SELF; |
658 | } |
659 | |
660 | |
661 | /* |
662 | * This is the beginning of the message list table. |
663 | * It wraps around all messages |
664 | */ |
8008456a |
665 | |
8008456a |
666 | echo "<FORM name=\"messageList\" method=post action=\"$moveURL\">\n" |
c1c17724 |
667 | . html_tag( 'table' ,'' , '', '', 'border="0" width="100%" cellpadding="1" cellspacing="0"' ) . |
668 | html_tag( 'tr', |
669 | html_tag( 'td' , |
670 | html_tag( 'table' , |
671 | html_tag( 'tr', |
672 | html_tag( 'td', $paginator, 'left' ) . |
673 | html_tag( 'td', $msg_cnt_str, 'right' ) |
674 | ) |
675 | , '', $color[4], 'border="0" width="100%" cellpadding="2" cellspacing="0"' ) |
676 | , 'left', '', '' ) |
677 | , '', $color[0] ) |
6b4bd11f |
678 | . html_tag( 'tr' ) . "\n" |
c1c17724 |
679 | . html_tag( 'td' ,'' , 'left', $color[0], '' ) |
680 | . html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="0" cellspacing="0"' ) |
681 | . html_tag( 'tr', |
682 | html_tag( 'td', |
6b4bd11f |
683 | '<small> ' . _("Move Selected To:") . '</small>', |
c1c17724 |
684 | 'left', |
685 | '', |
686 | 'valign="middle" nowrap' ) . |
687 | html_tag( 'td', |
6b4bd11f |
688 | '<small>' . _("Transform Selected Messages") . ': </small>', |
c1c17724 |
689 | 'right', |
690 | '', |
691 | 'nowrap' ) |
692 | ) |
6b4bd11f |
693 | . html_tag( 'tr' ) ."\n" |
8008456a |
694 | . html_tag( 'td', '', 'left', '', 'valign="middle" nowrap' ) |
6b4bd11f |
695 | . ' <small> <tt><select name="targetMailbox">'; |
8008456a |
696 | |
e35045b7 |
697 | $boxes = sqimap_mailbox_list($imapConnection); |
698 | foreach ($boxes as $boxes_part) { |
699 | if (!in_array('noselect', $boxes_part['flags'])) { |
700 | $box = $boxes_part['unformatted']; |
701 | $box2 = str_replace(' ', ' ', imap_utf7_decode_local($boxes_part['unformatted-disp'])); |
702 | if( $box2 == 'INBOX' ) { |
703 | $box2 = _("INBOX"); |
704 | } |
705 | if ($lastTargetMailbox == $box) { |
706 | echo " <OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n"; |
707 | } |
708 | else { |
709 | echo " <OPTION VALUE=\"$box\">$box2</OPTION>\n"; |
710 | } |
bdfb67f8 |
711 | } |
e35045b7 |
712 | } |
713 | echo ' </SELECT></TT> ' |
714 | . '<INPUT TYPE="SUBMIT" NAME="moveButton" VALUE="' . _("Move") . '"> ' |
715 | . '<INPUT TYPE="SUBMIT" NAME="attache" VALUE="' . _("Forward") |
716 | . "\"> \n" . "</SMALL>\n"; |
6c930ade |
717 | |
e35045b7 |
718 | echo " </TD>\n" |
6b4bd11f |
719 | . html_tag( 'td', '', 'right', '', 'nowrap' ); |
e35045b7 |
720 | |
721 | if (!$auto_expunge) { |
722 | echo '<INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="' . _("Expunge") |
723 | . '"> ' . _("mailbox") . ' '; |
724 | } |
725 | echo '<INPUT TYPE="SUBMIT" NAME="markRead" VALUE="' . _("Read") . '">' |
726 | . '<INPUT TYPE="SUBMIT" NAME="markUnread" VALUE="' . _("Unread") . '">' |
727 | . '<INPUT TYPE="SUBMIT" VALUE="' . _("Delete") . '"> ' |
728 | . "</TD>\n" |
729 | . " </TR>\n"; |
730 | |
731 | /* draws thread sorting links */ |
732 | if ($allow_thread_sort == TRUE) { |
733 | if ($thread_sort_messages == 1 ) { |
734 | $set_thread = 2; |
735 | $thread_name = _("Unthread View"); |
736 | } |
737 | elseif ($thread_sort_messages == 0) { |
738 | $set_thread = 1; |
739 | $thread_name = _("Thread View"); |
8008456a |
740 | } |
c1c17724 |
741 | echo html_tag( 'tr' , |
742 | html_tag( 'td' , |
e35045b7 |
743 | ' <a href=' . $source_url . '?sort=' |
c1c17724 |
744 | . "$sort" . '&start_messages=1&set_thread=' . "$set_thread" |
745 | . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name |
746 | . '</a></small> ' |
747 | , '', '', '' ) |
748 | , '', '', '' ); |
e35045b7 |
749 | } |
750 | |
751 | echo "</TABLE>\n"; |
8008456a |
752 | |
6b4bd11f |
753 | echo "</table>\n"; |
8008456a |
754 | do_hook('mailbox_form_before'); |
6b4bd11f |
755 | echo '</td></tr>' |
756 | . html_tag( 'tr' ) |
c1c17724 |
757 | . html_tag( 'td' ,'' , '', $color[0], '' ); |
8008456a |
758 | if ($GLOBALS['alt_index_colors']){ |
c1c17724 |
759 | $cellspacing = '0'; |
8008456a |
760 | } else { |
c1c17724 |
761 | $cellspacing = '1'; |
8008456a |
762 | } |
c1c17724 |
763 | echo html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="2" cellspacing="'. $cellspacing .'"' ) |
6b4bd11f |
764 | . html_tag( 'tr' ,'' , 'center', $color[5] ); |
8008456a |
765 | /* if using server sort we highjack the |
766 | * the $sort var and use $server_sort_order |
767 | * instead. but here we reset sort for a bit |
768 | * since its easy |
769 | */ |
770 | if ($allow_server_sort == TRUE) { |
771 | $sort = $server_sort_order; |
772 | } |
773 | /* Print the headers. */ |
774 | for ($i=1; $i <= count($index_order); $i++) { |
775 | switch ($index_order[$i]) { |
776 | case 1: /* checkbox */ |
777 | case 5: /* flags */ |
6b4bd11f |
778 | echo html_tag( 'td' ,' ' , '', '', 'width="1%"' ); |
8008456a |
779 | break; |
780 | case 2: /* from */ |
781 | if (handleAsSent($mailbox)) { |
c1c17724 |
782 | echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' ) |
783 | . '<b>' . _("To") . '</b>'; |
8008456a |
784 | } else { |
c1c17724 |
785 | echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' ) |
786 | . '<b>' . _("From") . '</b>'; |
8008456a |
787 | } |
788 | if ($allow_thread_sort != TRUE || $thread_sort_messages != 1) { |
789 | ShowSortButton($sort, $mailbox, 2, 3); |
790 | } |
6b4bd11f |
791 | echo "</td>\n"; |
8008456a |
792 | break; |
793 | case 3: /* date */ |
c1c17724 |
794 | echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' ) |
795 | . '<b>' . _("Date") . '</b>'; |
8008456a |
796 | if ($allow_thread_sort != TRUE || $thread_sort_messages != 1) { |
797 | ShowSortButton($sort, $mailbox, 0, 1); |
798 | } |
c1c17724 |
799 | echo "</td>\n"; |
8008456a |
800 | break; |
801 | case 4: /* subject */ |
c1c17724 |
802 | echo html_tag( 'td' ,'' , 'left', '', '' ) |
803 | . '<b>' . _("Subject") . '</b>'; |
8008456a |
804 | if ($allow_thread_sort != TRUE || $thread_sort_messages != 1) { |
805 | ShowSortButton($sort, $mailbox, 4, 5); |
806 | } |
6b4bd11f |
807 | echo "</td>\n"; |
8008456a |
808 | break; |
809 | case 6: /* size */ |
810 | echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%"' ); |
811 | break; |
812 | } |
bdfb67f8 |
813 | } |
8008456a |
814 | /* if using server-sorting, |
815 | * send sort back to 6 |
816 | */ |
817 | if ($allow_server_sort == TRUE) { |
818 | $sort = 6; |
819 | } |
6b4bd11f |
820 | echo "</tr>\n"; |
e35045b7 |
821 | |
bdfb67f8 |
822 | } |
823 | |
824 | /* |
e35045b7 |
825 | * This function shows the sort button. Isn't this a good comment? |
826 | */ |
827 | function ShowSortButton($sort, $mailbox, $Up, $Down ) { |
828 | global $PHP_SELF; |
829 | /* Figure out which image we want to use. */ |
830 | if ($sort != $Up && $sort != $Down) { |
831 | $img = 'sort_none.png'; |
832 | $which = $Up; |
833 | } elseif ($sort == $Up) { |
834 | $img = 'up_pointer.png'; |
835 | $which = $Down; |
836 | } else { |
837 | $img = 'down_pointer.png'; |
838 | $which = 6; |
839 | } |
840 | |
841 | if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) { |
842 | $source_url = $regs[1]; |
843 | } else { |
844 | $source_url = $PHP_SELF; |
845 | } |
846 | |
847 | /* Now that we have everything figured out, show the actual button. */ |
848 | echo ' <a href="' . $source_url .'?newsort=' . $which |
6c930ade |
849 | . '&startMessage=1&mailbox=' . urlencode($mailbox) |
e35045b7 |
850 | . '"><IMG SRC="../images/' . $img |
851 | . '" BORDER=0 WIDTH=12 HEIGHT=10 ALT="sort"></a>'; |
bdfb67f8 |
852 | } |
853 | |
854 | function get_selectall_link($start_msg, $sort) { |
e35045b7 |
855 | global $checkall, $what, $where, $mailbox, $javascript_on; |
856 | global $PHP_SELF, $PG_SHOWNUM; |
857 | |
858 | $result = ''; |
859 | if ($javascript_on) { |
860 | $result = |
861 | '<script language="JavaScript" type="text/javascript">' |
862 | . "\n<!-- \n" |
863 | . "function CheckAll() {\n" |
864 | . " for (var i = 0; i < document.messageList.elements.length; i++) {\n" |
865 | . " if(document.messageList.elements[i].type == 'checkbox'){\n" |
866 | . " document.messageList.elements[i].checked = " |
867 | . " !(document.messageList.elements[i].checked);\n" |
868 | . " }\n" |
869 | . " }\n" |
870 | . "}\n" |
871 | . "//-->\n" |
872 | . '</script><a href="#" onClick="CheckAll();">' . _("Toggle All") |
873 | . "</a>\n"; |
874 | } else { |
875 | if (strpos($PHP_SELF, "?")) { |
876 | $result .= "<a href=\"$PHP_SELF&mailbox=" . urlencode($mailbox) |
877 | . "&startMessage=$start_msg&sort=$sort&checkall="; |
6c930ade |
878 | } else { |
e35045b7 |
879 | $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox) |
880 | . "&startMessage=$start_msg&sort=$sort&checkall="; |
881 | } |
882 | if (isset($checkall) && $checkall == '1') { |
883 | $result .= '0'; |
884 | } else { |
885 | $result .= '1'; |
6c930ade |
886 | } |
e35045b7 |
887 | |
888 | if (isset($where) && isset($what)) { |
889 | $result .= '&where=' . urlencode($where) |
890 | . '&what=' . urlencode($what); |
891 | } |
892 | |
893 | $result .= "\">"; |
894 | |
895 | if (isset($checkall) && ($checkall == '1')) { |
896 | $result .= _("Unselect All"); |
897 | } else { |
898 | $result .= _("Select All"); |
899 | } |
900 | |
901 | $result .= "</A>\n"; |
902 | } |
23d6bd09 |
903 | |
e35045b7 |
904 | /* Return our final result. */ |
905 | return ($result); |
bdfb67f8 |
906 | } |
1a0e0983 |
907 | |
6c930ade |
908 | /* |
e35045b7 |
909 | * This function computes the "Viewing Messages..." string. |
910 | */ |
bdfb67f8 |
911 | function get_msgcnt_str($start_msg, $end_msg, $num_msgs) { |
e35045b7 |
912 | /* Compute the $msg_cnt_str. */ |
913 | $result = ''; |
914 | if ($start_msg < $end_msg) { |
915 | $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"), |
916 | $start_msg, $end_msg, $num_msgs); |
917 | } else if ($start_msg == $end_msg) { |
918 | $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg); |
919 | } else { |
920 | $result = '<br>'; |
921 | } |
922 | |
923 | /* Return our result string. */ |
924 | return ($result); |
bdfb67f8 |
925 | } |
926 | |
6c930ade |
927 | /* |
e35045b7 |
928 | * Generate a paginator link. |
929 | */ |
6c930ade |
930 | function get_paginator_link($box, $start_msg, $use, $text) { |
e35045b7 |
931 | global $PHP_SELF; |
932 | |
933 | if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) { |
934 | $source_url = $regs[1]; |
935 | } else { |
936 | $source_url = $PHP_SELF; |
937 | } |
938 | |
939 | $result = '<A HREF="'. $source_url . "?use_mailbox_cache=$use" |
6c930ade |
940 | . "&startMessage=$start_msg&mailbox=$box\" " |
e35045b7 |
941 | . "TARGET=\"right\">$text</A>"; |
942 | return ($result); |
7b294953 |
943 | } |
944 | |
6c930ade |
945 | /* |
e35045b7 |
946 | * This function computes the paginator string. |
947 | */ |
948 | function get_paginator_str($box, $start_msg, $end_msg, $num_msgs, |
949 | $show_num, $sort) { |
950 | global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM; |
951 | |
952 | /* Initialize paginator string chunks. */ |
953 | $prv_str = ''; |
954 | $nxt_str = ''; |
955 | $pg_str = ''; |
956 | $all_str = ''; |
957 | $tgl_str = ''; |
958 | |
959 | /* Create simple strings that will be creating the paginator. */ |
960 | $spc = ' '; /* This will be used as a space. */ |
961 | $sep = '|'; /* This will be used as a seperator. */ |
962 | |
963 | /* Get some paginator preference values. */ |
964 | $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON); |
965 | $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX); |
966 | |
967 | /* Make sure that our start message number is not too big. */ |
968 | $start_msg = min($start_msg, $num_msgs); |
969 | |
970 | /* Decide whether or not we will use the mailbox cache. */ |
971 | /* Not sure why $use_mailbox_cache is even passed in. */ |
972 | if ($sort == 6) { |
973 | $use = 0; |
974 | } else { |
975 | $use = 1; |
976 | } |
977 | |
978 | /* Compute the starting message of the previous and next page group. */ |
979 | $next_grp = $start_msg + $show_num; |
980 | $prev_grp = $start_msg - $show_num; |
981 | |
982 | /* Compute the basic previous and next strings. */ |
983 | if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) { |
984 | $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous")); |
985 | $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next")); |
986 | } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) { |
987 | $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous")); |
988 | $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n"; |
989 | } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) { |
990 | $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>'; |
991 | $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next")); |
992 | } |
993 | |
994 | /* Page selector block. Following code computes page links. */ |
995 | if ($pg_sel && ($num_msgs > $show_num)) { |
996 | /* Most importantly, what is the current page!!! */ |
997 | $cur_pg = intval($start_msg / $show_num) + 1; |
998 | |
999 | /* Compute total # of pages and # of paginator page links. */ |
1000 | $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */ |
1001 | $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */ |
1002 | |
1003 | /* Compute the size of the four quarters of the page links. */ |
1004 | |
1005 | /* If we can, just show all the pages. */ |
1006 | if (($tot_pgs - 1) <= $pg_max) { |
1007 | $q1_pgs = $cur_pg - 1; |
1008 | $q2_pgs = $q3_pgs = 0; |
1009 | $q4_pgs = $tot_pgs - $cur_pg; |
1010 | |
1011 | /* Otherwise, compute some magic to choose the four quarters. */ |
1012 | } else { |
1013 | /* |
1014 | * Compute the magic base values. Added together, |
1015 | * these values will always equal to the $pag_pgs. |
1016 | * NOTE: These are DEFAULT values and do not take |
1017 | * the current page into account. That is below. |
1018 | */ |
1019 | $q1_pgs = floor($vis_pgs/4); |
1020 | $q2_pgs = round($vis_pgs/4, 0); |
1021 | $q3_pgs = ceil($vis_pgs/4); |
1022 | $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0); |
1023 | |
1024 | /* Adjust if the first quarter contains the current page. */ |
1025 | if (($cur_pg - $q1_pgs) < 1) { |
1026 | $extra_pgs = ($q1_pgs - ($cur_pg - 1)) + $q2_pgs; |
1027 | $q1_pgs = $cur_pg - 1; |
1028 | $q2_pgs = 0; |
1029 | $q3_pgs += ceil($extra_pgs / 2); |
1030 | $q4_pgs += floor($extra_pgs / 2); |
1031 | |
1032 | /* Adjust if the first and second quarters intersect. */ |
1033 | } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) { |
1034 | $extra_pgs = $q2_pgs; |
1035 | $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75); |
1036 | $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75); |
1037 | $q3_pgs += ceil($extra_pgs / 2); |
1038 | $q4_pgs += floor($extra_pgs / 2); |
1039 | |
1040 | /* Adjust if the fourth quarter contains the current page. */ |
1041 | } else if (($cur_pg + $q4_pgs) >= $tot_pgs) { |
1042 | $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) + $q3_pgs; |
1043 | $q3_pgs = 0; |
1044 | $q4_pgs = $tot_pgs - $cur_pg; |
1045 | $q1_pgs += floor($extra_pgs / 2); |
1046 | $q2_pgs += ceil($extra_pgs / 2); |
1047 | |
1048 | /* Adjust if the third and fourth quarter intersect. */ |
1049 | } else if (($cur_pg + $q3_pgs + 1) >= ($tot_pgs - $q4_pgs + 1)) { |
1050 | $extra_pgs = $q3_pgs; |
1051 | $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75); |
1052 | $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75); |
1053 | $q1_pgs += floor($extra_pgs / 2); |
1054 | $q2_pgs += ceil($extra_pgs / 2); |
1055 | } |
1056 | } |
1057 | |
1058 | /* |
1059 | * I am leaving this debug code here, commented out, because |
1060 | * it is a really nice way to see what the above code is doing. |
1061 | * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = " |
1062 | * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>'; |
1063 | */ |
1064 | |
1065 | /* Print out the page links from the compute page quarters. */ |
1066 | |
1067 | /* Start with the first quarter. */ |
1068 | if (($q1_pgs == 0) && ($cur_pg > 1)) { |
1069 | $pg_str .= "...$spc"; |
1070 | } else { |
1071 | for ($pg = 1; $pg <= $q1_pgs; ++$pg) { |
1072 | $start = (($pg-1) * $show_num) + 1; |
1073 | $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc; |
1074 | } |
1075 | if ($cur_pg - $q2_pgs - $q1_pgs > 1) { |
1076 | $pg_str .= "...$spc"; |
1077 | } |
1078 | } |
1079 | |
1080 | /* Continue with the second quarter. */ |
1081 | for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++$pg) { |
1082 | $start = (($pg-1) * $show_num) + 1; |
1083 | $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc; |
1084 | } |
1085 | |
1086 | /* Now print the current page. */ |
1087 | $pg_str .= $cur_pg . $spc; |
1088 | |
1089 | /* Next comes the third quarter. */ |
1090 | for ($pg = $cur_pg + 1; $pg <= $cur_pg + $q3_pgs; ++$pg) { |
1091 | $start = (($pg-1) * $show_num) + 1; |
1092 | $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc; |
1093 | } |
1094 | |
1095 | /* And last, print the forth quarter page links. */ |
1096 | if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) { |
1097 | $pg_str .= "...$spc"; |
1098 | } else { |
1099 | if (($tot_pgs - $q4_pgs) > ($cur_pg + $q3_pgs)) { |
1100 | $pg_str .= "...$spc"; |
1101 | } |
1102 | for ($pg = $tot_pgs - $q4_pgs + 1; $pg <= $tot_pgs; ++$pg) { |
1103 | $start = (($pg-1) * $show_num) + 1; |
1104 | $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc; |
1105 | } |
1106 | } |
1107 | } else if ($PG_SHOWNUM == 999999) { |
1108 | $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0" |
1109 | . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" " |
1110 | . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc; |
1111 | } |
1112 | |
1113 | /* If necessary, compute the 'show all' string. */ |
1114 | if (($prv_str != '') || ($nxt_str != '')) { |
1115 | $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1" |
1116 | . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" " |
1117 | . "TARGET=\"right\">" . _("Show All") . '</A>'; |
1118 | } |
1119 | |
1120 | /* Last but not least, get the value for the toggle all link. */ |
1121 | $tgl_str = get_selectall_link($start_msg, $sort); |
1122 | |
1123 | /* Put all the pieces of the paginator string together. */ |
1124 | /** |
1125 | * Hairy code... But let's leave it like it is since I am not certain |
1126 | * a different approach would be any easier to read. ;) |
1127 | */ |
1128 | $result = ''; |
1129 | $result .= ($prv_str != '' ? $prv_str . $spc . $sep . $spc : ''); |
1130 | $result .= ($nxt_str != '' ? $nxt_str . $spc . $sep . $spc : ''); |
1131 | $result .= ($pg_str != '' ? $pg_str : ''); |
1132 | $result .= ($all_str != '' ? $sep . $spc . $all_str . $spc : ''); |
1133 | $result .= ($result != '' ? $sep . $spc . $tgl_str: $tgl_str); |
1134 | |
1135 | /* If the resulting string is blank, return a non-breaking space. */ |
1136 | if ($result == '') { |
1137 | $result = ' '; |
1138 | } |
1139 | |
1140 | /* Return our final magical paginator string. */ |
1141 | return ($result); |
bdfb67f8 |
1142 | } |
1143 | |
1144 | function processSubject($subject) { |
e35045b7 |
1145 | /* Shouldn't ever happen -- caught too many times in the IMAP functions */ |
1146 | if ($subject == '') |
6c930ade |
1147 | return _("(no subject)"); |
e35045b7 |
1148 | |
1149 | if (strlen($subject) <= 55) |
6c930ade |
1150 | return $subject; |
8008456a |
1151 | |
e35045b7 |
1152 | $ent_strlen=strlen($subject); |
1153 | $trim_val=50; |
1154 | $ent_offset=0; |
1155 | /* |
1156 | * see if this is entities-encoded string |
1157 | * If so, Iterate through the whole string, find out |
1158 | * the real number of characters, and if more |
1159 | * than 55, substr with an updated trim value. |
1160 | */ |
1161 | while ( (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) && |
1162 | (($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false) ) { |
1163 | $trim_val += ($ent_loc_end-$ent_loc)+1; |
1164 | $ent_strlen -= $ent_loc_end-$ent_loc; |
1165 | $ent_offset = $ent_loc_end+1; |
1166 | } |
1167 | |
1168 | if ($ent_strlen <= 55){ |
1169 | return $subject; |
1170 | } |
1171 | |
1172 | return substr($subject, 0, $trim_val) . '...'; |
bdfb67f8 |
1173 | } |
f93c93b9 |
1174 | |
a3439b27 |
1175 | function handleAsSent($mailbox) { |
e35045b7 |
1176 | global $sent_folder, $draft_folder, $handleAsSent_result; |
a3439b27 |
1177 | |
e35045b7 |
1178 | /* First check if this is the sent or draft folder. */ |
1179 | $handleAsSent_result = (($mailbox == $sent_folder) |
1180 | || ($mailbox == $draft_folder)); |
1181 | |
1182 | /* Then check the result of the handleAsSent hook. */ |
1183 | do_hook('check_handleAsSent_result', $mailbox); |
a3439b27 |
1184 | |
e35045b7 |
1185 | /* And return the result. */ |
1186 | return ($handleAsSent_result); |
a3439b27 |
1187 | } |
1188 | |
a51dec54 |
1189 | ?> |