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