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