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