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