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