moved address-parsing to the displayable headers
[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 }
ce20ea92 76 $msg['FROM'] = parseAddress($msg['FROM']);
77
e9e5f0fa 78 /*
79 * This is done in case you're looking into Sent folders,
80 * because you can have multiple receivers.
81 */
937c81fa 82
098ea084 83 $senderNames = $msg['FROM'];
84 $senderName = '';
85 if (sizeof($senderNames)){
86 foreach ($senderNames as $senderNames_part) {
e9e5f0fa 87 if ($senderName != '') {
88 $senderName .= ', ';
89 }
098ea084 90 if ($senderNames_part[1]) {
91 $senderName .= decodeHeader($senderNames_part[1]);
92 } else {
93 $senderName .= htmlspecialchars($senderNames_part[0]);
94 }
95 }
937c81fa 96 }
97
306b6393 98 $msg['SUBJECT'] = decodeHeader($msg['SUBJECT']);
99 $subject = processSubject($msg['SUBJECT'], $indent_array[$msg['ID']]);
ce20ea92 100
5786ef5a 101 echo html_tag( 'tr','','','','VALIGN="top"') . "\n";
8008456a 102
103 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
104 $flag = "<font color=\"$color[2]\">";
105 $flag_end = '</font>';
106 } else {
107 $flag = '';
108 $flag_end = '';
bdfb67f8 109 }
8008456a 110 if (!isset($msg['FLAG_SEEN']) || ($msg['FLAG_SEEN'] == false)) {
111 $bold = '<b>';
112 $bold_end = '</b>';
113 } else {
114 $bold = '';
115 $bold_end = '';
bdfb67f8 116 }
8008456a 117 if (handleAsSent($mailbox)) {
118 $italic = '<i>';
119 $italic_end = '</i>';
120 } else {
121 $italic = '';
122 $italic_end = '';
123 }
124 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
125 $fontstr = "<font color=\"$color[9]\">";
126 $fontstr_end = '</font>';
127 } else {
128 $fontstr = '';
129 $fontstr_end = '';
130 }
131
d215ca7d 132 if ($where && $what) {
133 $searchstr = '&amp;where='.$where.'&amp;what='.$what;
134 } else {
135 $searchstr = '';
6a622b59 136 }
8008456a 137 /**
138 * AAAAH! Make my eyes stop bleeding!
139 * Who wrote this?!
140 */
937c81fa 141 if (is_array($message_highlight_list) && count($message_highlight_list)) {
ce20ea92 142 $msg['TO'] = parseAddress($msg['TO']);
143 $msg['CC'] = parseAddress($msg['CC']);
8008456a 144 foreach ($message_highlight_list as $message_highlight_list_part) {
145 if (trim($message_highlight_list_part['value']) != '') {
c0d04f97 146 $high_val = strtolower($message_highlight_list_part['value']);
147 $match_type = strtoupper($message_highlight_list_part['match_type']);
937c81fa 148 switch($match_type) {
149 case('TO'):
150 case('TO_CC'):
151 foreach ($msg['TO'] as $address) {
306b6393 152 $address[0] = decodeHeader($address[0]);
153 $address[1] = decodeHeader($address[1]);
937c81fa 154 if (strstr('^^' . strtolower($address[0]), $high_val) ||
155 strstr('^^' . strtolower($address[1]), $high_val)) {
156 $hlt_color = $message_highlight_list_part['color'];
157 continue;
158 }
098ea084 159 }
937c81fa 160 if($match_type != 'TO_CC') {
161 break;
162 }
163 case('CC'):
164 foreach ($msg['CC'] as $address) {
306b6393 165 $address[0] = decodeHeader($address[0]);
166 $address[1] = decodeHeader($address[1]);
937c81fa 167 if( strstr('^^' . strtolower($address[0]), $high_val) ||
168 strstr('^^' . strtolower($address[1]), $high_val)) {
169 $hlt_color = $message_highlight_list_part['color'];
170 continue;
171 }
172 }
173 break;
174 case('FROM'):
175 foreach ($msg['FROM'] as $address) {
306b6393 176 $address[0] = decodeHeader($address[0]);
177 $address[1] = decodeHeader($address[1]);
937c81fa 178 if( strstr('^^' . strtolower($address[0]), $high_val) ||
179 strstr('^^' . strtolower($address[1]), $high_val)) {
180 $hlt_color = $message_highlight_list_part['color'];
181 continue;
182 }
183 }
184 break;
185 default:
186 if (strstr('^^' . strtolower($msg[$match_type]), $high_val)) {
098ea084 187 $hlt_color = $message_highlight_list_part['color'];
188 continue;
189 }
937c81fa 190 break;
8008456a 191 }
192 }
193 }
194 }
195
196 if (!isset($hlt_color)) {
197 $hlt_color = $color_string;
198 }
59352d08 199 $checked = ($checkall == 1) ? ' CHECKED' : '';
5e0efebf 200 $col = 0;
6a622b59 201 if (sizeof($index_order)) {
8008456a 202 foreach ($index_order as $index_order_part) {
203 switch ($index_order_part) {
204 case 1: /* checkbox */
205 echo html_tag( 'td',
206 "<input type=checkbox name=\"msg[$t]\" value=\"".$msg['ID']."\"$checked>",
6a622b59 207 'center',
8008456a 208 $hlt_color );
209 break;
210 case 2: /* from */
211 echo html_tag( 'td',
098ea084 212 $italic . $bold . $flag . $fontstr . $senderName .
8008456a 213 $fontstr_end . $flag_end . $bold_end . $italic_end,
c1c17724 214 'left',
8008456a 215 $hlt_color );
216 break;
217 case 3: /* date */
53d9fbc5 218 $date_string = $msg['DATE_STRING'] . '';
219 if ($date_string == '') {
220 $date_string = _("Unknown date");
221 }
8008456a 222 echo html_tag( 'td',
53d9fbc5 223 $bold . $flag . $fontstr . $date_string .
8008456a 224 $fontstr_end . $flag_end . $bold_end,
225 'center',
226 $hlt_color,
227 'nowrap' );
228 break;
229 case 4: /* subject */
230 $td_str = $bold;
231 if ($thread_sort_messages == 1) {
6903c7bd 232 if (isset($indent_array[$msg['ID']])) {
8008456a 233 $td_str .= str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;",$indent_array[$msg['ID']]);
234 }
235 }
e9e5f0fa 236 $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox
6a622b59 237 . '&amp;passed_id='. $msg["ID"]
238 . '&amp;startMessage='.$start_msg.$searchstr.'"';
e17d0c83 239 $td_str .= ' ' .concat_hook_function('subject_link');
306b6393 240 if ($subject != $msg['SUBJECT']) {
8008456a 241 $title = get_html_translation_table(HTML_SPECIALCHARS);
242 $title = array_flip($title);
306b6393 243 $title = strtr($msg['SUBJECT'], $title);
8008456a 244 $title = str_replace('"', "''", $title);
245 $td_str .= " title=\"$title\"";
246 }
247 $td_str .= ">$flag$subject$flag_end</a>$bold_end";
c1c17724 248 echo html_tag( 'td', $td_str, 'left', $hlt_color );
8008456a 249 break;
250 case 5: /* flags */
251 $stuff = false;
252 $td_str = "<b><small>";
6a622b59 253
8008456a 254 if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) {
255 $td_str .= _("A");
256 $stuff = true;
257 }
258 if ($msg['TYPE0'] == 'multipart') {
259 $td_str .= '+';
260 $stuff = true;
261 }
262 if ($default_use_priority) {
263 if ( ($msg['PRIORITY'] == 1) || ($msg['PRIORITY'] == 2) ) {
264 $td_str .= "<font color=\"$color[1]\">!</font>";
265 $stuff = true;
266 }
267 if ($msg['PRIORITY'] == 5) {
268 $td_str .= "<font color=\"$color[8]\">?</font>";
269 $stuff = true;
270 }
271 }
272 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) {
273 $td_str .= "<font color=\"$color[1]\">D</font>";
274 $stuff = true;
275 }
276 if (!$stuff) {
277 $td_str .= '&nbsp;';
278 }
2bd00b7b 279 do_hook("msg_envelope");
8008456a 280 $td_str .= '</small></b>';
281 echo html_tag( 'td',
282 $td_str,
283 'center',
284 $hlt_color,
285 'nowrap' );
286 break;
287 case 6: /* size */
8008456a 288 echo html_tag( 'td',
6a622b59 289 $bold . $fontstr . show_readable_size($msg['SIZE']) .
8008456a 290 $fontstr_end . $bold_end,
291 'right',
292 $hlt_color );
293 break;
294 }
ed230bc3 295 ++$col;
8008456a 296 }
bdfb67f8 297 }
7b887886 298 if ($not_last) {
ed230bc3 299 echo '</tr>' . "\n" . '<tr><td COLSPAN="' . $col . '" BGCOLOR="' .
300 $color[0] . '" HEIGHT="1"></td></tr>' . "\n";
6a622b59 301 } else {
7b887886 302 echo '</tr>'."\n";
6a622b59 303 }
e9e5f0fa 304}
305
ed230bc3 306function getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id) {
307 if ($id != 'no') {
098ea084 308 $id = array_slice($id, ($start_msg-1), $show_num);
ed230bc3 309 $end = $start_msg + $show_num - 1;
310 if ($num_msgs < $show_num) {
311 $end_loop = $num_msgs;
312 } else if ($end > $num_msgs) {
313 $end_loop = $num_msgs - $start_msg + 1;
314 } else {
315 $end_loop = $show_num;
316 }
317 return fillMessageArray($imapConnection,$id,$end_loop);
318 } else {
319 return false;
320 }
321}
322
323function getThreadMessages($imapConnection, $start_msg, $show_num, $num_msgs) {
324 $id = get_thread_sort($imapConnection);
325 return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
326}
327
6a622b59 328function getServerSortMessages($imapConnection, $start_msg, $show_num,
ed230bc3 329 $num_msgs, $server_sort_order, $mbxresponse) {
330 $id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse);
331 return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
e9e5f0fa 332}
333
6a622b59 334function getSelfSortMessages($imapConnection, $start_msg, $show_num,
e9e5f0fa 335 $num_msgs, $sort, $mbxresponse) {
ed230bc3 336 $msgs = array();
337 if ($num_msgs >= 1) {
338 $id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse);
339 if ($sort < 6 ) {
340 $end = $num_msgs;
341 $end_loop = $end;
342 } else {
343 /* if it's not sorted */
344 if ($start_msg + ($show_num - 1) < $num_msgs) {
345 $end_msg = $start_msg + ($show_num - 1);
346 } else {
347 $end_msg = $num_msgs;
348 }
349 if ($end_msg < $start_msg) {
350 $start_msg = $start_msg - $show_num;
351 if ($start_msg < 1) {
352 $start_msg = 1;
353 }
354 }
098ea084 355 $id = array_slice(array_reverse($id), ($start_msg-1), $show_num);
ed230bc3 356 $end = $start_msg + $show_num - 1;
357 if ($num_msgs < $show_num) {
358 $end_loop = $num_msgs;
359 } else if ($end > $num_msgs) {
360 $end_loop = $num_msgs - $start_msg + 1;
361 } else {
362 $end_loop = $show_num;
363 }
364 }
36ac3582 365 $msgs = fillMessageArray($imapConnection,$id,$end_loop);
e9e5f0fa 366 }
ed230bc3 367 return $msgs;
e9e5f0fa 368}
369
370
371
6c930ade 372/*
e35045b7 373 * This function loops through a group of messages in the mailbox
374 * and shows them to the user.
375 */
6a622b59 376function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
377 $start_msg, $sort, $color, $show_num,
378 $use_cache, $mode='') {
fcba142a 379 global $msgs, $msort, $auto_expunge, $thread_sort_messages,
6a622b59 380 $allow_server_sort, $server_sort_order;
381
167d7428 382 /*
383 * For some reason, on PHP 4.3+, this being unset, and set in the session causes havoc
384 * so setting it to an empty array beforehand seems to clean up the issue, and stopping the
385 * "Your script possibly relies on a session side-effect which existed until PHP 4.2.3" error
386 */
387
388 if (!isset($msort)) {
389 $msort = array();
390 }
391
49ae9d34 392 if (!isset($msgs)) {
393 $msgs = array();
394 }
395
098ea084 396 $start = microtime();
6a622b59 397 /* If autoexpunge is turned on, then do it now. */
398 $mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox);
399 $srt = $sort;
400 /* If autoexpunge is turned on, then do it now. */
401 if ($auto_expunge == true) {
402 $exp_cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, false, '');
403 $mbxresponse['EXISTS'] = $mbxresponse['EXISTS'] - $exp_cnt;
404 $num_msgs = $mbxresponse['EXISTS'];
405 }
e35045b7 406
6a622b59 407 if ($mbxresponse['EXISTS'] > 0) {
408 /* if $start_msg is lower than $num_msgs, we probably deleted all messages
409 * in the last page. We need to re-adjust the start_msg
410 */
aa0da530 411
6a622b59 412 if($start_msg > $num_msgs) {
413 $start_msg -= $show_num;
414 if($start_msg < 1) {
415 $start_msg = 1;
416 }
e9e5f0fa 417 }
4e9f35e4 418
6a622b59 419 /* This code and the next if() block check for
420 * server-side sorting methods. The $id array is
421 * formatted and $sort is set to 6 to disable
422 * SM internal sorting
423 */
424
425 if ($thread_sort_messages == 1) {
426 $mode = 'thread';
427 } elseif ($allow_server_sort == 1) {
428 $mode = 'serversort';
429 } else {
430 $mode = '';
431 }
8008456a 432
ed230bc3 433 sqsession_unregister('msort');
434 sqsession_unregister('msgs');
6a622b59 435 switch ($mode) {
436 case 'thread':
ed230bc3 437 $id = get_thread_sort($imapConnection);
438 $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
6a622b59 439 if ($msgs === false) {
440 echo '<b><small><center><font color=red>' .
441 _("Thread sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
442 '</center></small></b>';
443 $thread_sort_messages = 0;
444 $msort = $msgs = array();
6a622b59 445 } else {
446 $msort= $msgs;
447 $sort = 6;
6a622b59 448 }
449 break;
450 case 'serversort':
ed230bc3 451 $id = sqimap_get_sort_order($imapConnection, $sort, $mbxresponse);
452 $msgs = getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
6a622b59 453 if ($msgs === false) {
454 echo '<b><small><center><font color=red>' .
455 _( "Server-side sorting is not supported by your IMAP server.<br>Please report this to the system administrator.").
456 '</center></small></b>';
457 $sort = $server_sort_order;
458 $allow_server_sort = FALSE;
459 $msort = $msgs = array();
6a622b59 460 $id = array();
461 } else {
6a622b59 462 $msort = $msgs;
ed230bc3 463 $sort = 6;
6a622b59 464 }
465 break;
466 default:
467 if (!$use_cache) {
6a622b59 468 $msgs = getSelfSortMessages($imapConnection, $start_msg, $show_num,
469 $num_msgs, $sort, $mbxresponse);
470 $msort = calc_msort($msgs, $sort);
6a622b59 471 } /* !use cache */
472 break;
473 } // switch
ed230bc3 474 sqsession_register($msort, 'msort');
475 sqsession_register($msgs, 'msgs');
6a622b59 476 } /* if exists > 0 */
477
478 $res = getEndMessage($start_msg, $show_num, $num_msgs);
479 $start_msg = $res[0];
480 $end_msg = $res[1];
481
482 $paginator_str = get_paginator_str($mailbox, $start_msg, $end_msg,
483 $num_msgs, $show_num, $sort);
484
485 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
486
487 do_hook('mailbox_index_before');
fcba142a 488 echo '<table border="0" width="100%" cellpadding="0" cellspacing="0">';
22642690 489 echo '<tr><td>';
490
491 mail_message_listing_beginning($imapConnection, $mailbox, $sort,
492 $msg_cnt_str, $paginator_str, $start_msg);
493 echo '</td></tr>';
494 /* line between the button area and the list */
495 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>';
496
497 echo '<tr><td>';
498 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
499 echo ' <tr><td>';
500 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[5].'">';
501 echo '<tr><td>';
6a622b59 502 printHeader($mailbox, $srt, $color, !$thread_sort_messages);
503
22642690 504 displayMessageArray($imapConnection, $num_msgs, $start_msg,
505 $msort, $mailbox, $sort, $color, $show_num,0,0);
506 echo '</td></tr></table></td></tr></table>';
6a622b59 507
22642690 508 mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color);
6a622b59 509 echo '</td></tr></table>';
098ea084 510 $t = elapsed($start);
46a49f65 511 //echo("elapsed time = $t seconds\n");
6c930ade 512}
bdfb67f8 513
e9e5f0fa 514function calc_msort($msgs, $sort) {
8008456a 515
e35045b7 516 /*
517 * 0 = Date (up)
518 * 1 = Date (dn)
519 * 2 = Name (up)
520 * 3 = Name (dn)
521 * 4 = Subject (up)
522 * 5 = Subject (dn)
523 */
625c8b78 524
6a622b59 525 if (($sort == 0) || ($sort == 1)) {
625c8b78 526 foreach ($msgs as $item) {
527 $msort[] = $item['TIME_STAMP'];
528 }
6a622b59 529 } elseif (($sort == 2) || ($sort == 3)) {
625c8b78 530 foreach ($msgs as $item) {
531 $msort[] = $item['FROM-SORT'];
532 }
6a622b59 533 } elseif (($sort == 4) || ($sort == 5)) {
625c8b78 534 foreach ($msgs as $item) {
535 $msort[] = $item['SUBJECT-SORT'];
536 }
6a622b59 537 } else {
538 $msort = $msgs;
539 }
540 if ($sort < 6) {
541 if ($sort % 2) {
542 asort($msort);
543 } else {
544 arsort($msort);
545 }
546 }
547 return $msort;
548}
549
550function fillMessageArray($imapConnection, $id, $count) {
cef054e4 551 return sqimap_get_small_header_list($imapConnection, $id);
e35045b7 552}
8008456a 553
e9e5f0fa 554
e35045b7 555/* Generic function to convert the msgs array into an HTML table. */
6a622b59 556function displayMessageArray($imapConnection, $num_msgs, $start_msg,
557 $msort, $mailbox, $sort, $color,
558 $show_num, $where=0, $what=0) {
59352d08 559 global $imapServerAddress, $use_mailbox_cache, $index_order,
6a622b59 560 $indent_array, $thread_sort_messages, $allow_server_sort,
561 $server_sort_order, $PHP_SELF;
562
563 $res = getEndMessage($start_msg, $show_num, $num_msgs);
564 $start_msg = $res[0];
565 $end_msg = $res[1];
a966982b 566
6a622b59 567 $urlMailbox = urlencode($mailbox);
e9e5f0fa 568
6a622b59 569 /* get indent level for subject display */
540c4435 570 if ($thread_sort_messages == 1 && $num_msgs) {
6a622b59 571 $indent_array = get_parent_level($imapConnection);
94ac35c6 572 }
a966982b 573
6a622b59 574 $real_startMessage = $start_msg;
575 if ($sort == 6) {
576 if ($end_msg - $start_msg < $show_num - 1) {
577 $end_msg = $end_msg - $start_msg + 1;
578 $start_msg = 1;
579 } else if ($start_msg > $show_num) {
580 $end_msg = $show_num;
581 $start_msg = 1;
582 }
583 }
584 $endVar = $end_msg + 1;
585
586 /*
587 * Loop through and display the info for each message.
588 * ($t is used for the checkbox number)
589 */
590 $t = 0;
591
592 /* messages display */
593
540c4435 594 if (!$num_msgs) {
e35045b7 595 /* if there's no messages in this folder */
8008456a 596 echo html_tag( 'tr',
13cf639b 597 html_tag( 'td',
6b4bd11f 598 "<BR><b>" . _("THIS FOLDER IS EMPTY") . "</b><BR>&nbsp;",
13cf639b 599 'center',
600 $color[4],
601 'COLSPAN="' . count($index_order) . '"'
602 )
6a622b59 603 );
604 } elseif ($start_msg == $end_msg) {
e35045b7 605 /* if there's only one message in the box, handle it differently. */
6a622b59 606 if ($sort != 6) {
607 $i = $start_msg;
608 } else {
609 $i = 1;
610 }
611 reset($msort);
612 $k = 0;
613 do {
614 $key = key($msort);
615 next($msort);
616 $k++;
617 } while (isset ($key) && ($k < $i));
7b887886 618 printMessageInfo($imapConnection, $t, true, $key, $mailbox,
ed230bc3 619 $real_startMessage, $where, $what);
94ac35c6 620 } else {
6a622b59 621 $i = $start_msg;
622 reset($msort);
623 $k = 0;
624 do {
625 $key = key($msort);
626 next($msort);
627 $k++;
628 } while (isset ($key) && ($k < $i));
ed230bc3 629 $not_last = true;
6a622b59 630 do {
ed230bc3 631 if (!$i || $i == $endVar-1) $not_last = false;
632 printMessageInfo($imapConnection, $t, $not_last, $key, $mailbox,
633 $real_startMessage, $where, $what);
6a622b59 634 $key = key($msort);
635 $t++;
636 $i++;
637 next($msort);
638 } while ($i && $i < $endVar);
94ac35c6 639 }
bdfb67f8 640}
641
6c930ade 642/*
e35045b7 643 * Displays the standard message list header. To finish the table,
644 * you need to do a "</table></table>";
645 *
646 * $moveURL is the URL to submit the delete/move form to
647 * $mailbox is the current mailbox
648 * $sort is the current sorting method (-1 for no sorting available [searches])
649 * $Message is a message that is centered on top of the list
650 * $More is a second line that is left aligned
651 */
e35045b7 652
6a622b59 653function mail_message_listing_beginning ($imapConnection,
654 $mailbox = '', $sort = -1,
655 $msg_cnt_str = '',
656 $paginator = '&nbsp;',
657 $start_msg = 1) {
658 global $color, $auto_expunge, $base_uri, $thread_sort_messages,
659 $allow_thread_sort, $allow_server_sort, $server_sort_order,
660 $PHP_SELF;
661
662 $php_self = $PHP_SELF;
663 /* fix for incorrect $PHP_SELF */
664 if (strpos($php_self, 'move_messages.php')) {
665 $php_self = str_replace('move_messages.php', 'right_main.php', $php_self);
666 }
667 $urlMailbox = urlencode($mailbox);
e35045b7 668
6a622b59 669 if (preg_match('/^(.+)\?.+$/',$php_self,$regs)) {
670 $source_url = $regs[1];
671 } else {
672 $source_url = $php_self;
673 }
674
675 if (!isset($msg)) {
676 $msg = '';
677 }
8fe969f6 678 $moveFields = '<input type="hidden" name="msg" value="'.htmlspecialchars($msg).'">' .
679 '<input type="hidden" name="mailbox" value="'.htmlspecialchars($mailbox).'">' .
680 '<input type="hidden" name="startMessage" value="'.htmlspecialchars($start_msg).'">';
681
682// $moveURL = "move_messages.php?msg=$msg&amp;mailbox=$urlMailbox"
683// . "&amp;startMessage=$start_msg";
6a622b59 684 /*
685 * This is the beginning of the message list table.
686 * It wraps around all messages
687 */
8fe969f6 688 echo '<form name="messageList" method="post" action="move_messages.php">' ."\n"
689 . $moveFields
22642690 690 . html_tag( 'table' ,
c1c17724 691 html_tag( 'tr',
692 html_tag( 'td' ,
693 html_tag( 'table' ,
694 html_tag( 'tr',
695 html_tag( 'td', $paginator, 'left' ) .
22642690 696 html_tag( 'td', $msg_cnt_str, 'right' )
c1c17724 697 )
22642690 698 , '', $color[4], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
c1c17724 699 , 'left', '', '' )
700 , '', $color[0] )
22642690 701 , '', '', 'border="0" width="100%" cellpadding="1" cellspacing="0"' );
4b920601 702 /* line between header and button area */
22642690 703 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'"></td></tr>';
22642690 704
4b920601 705 echo '<tr><td>';
22642690 706 echo html_tag( 'tr' ) . "\n"
707 . html_tag( 'td' ,'' , 'left', '', '' )
708 . html_tag( 'table' ,'' , '', $color[9], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
709 . '<tr><td>'
710 . html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="1" cellspacing="0"' )
c1c17724 711 . html_tag( 'tr',
22642690 712 getSmallStringCell(_("Move Selected To"), 'left', 'nowrap') .
713 getSmallStringCell(_("Transform Selected Messages"), 'right')
c1c17724 714 )
e9e5f0fa 715 . html_tag( 'tr' ) ."\n"
716 . html_tag( 'td', '', 'left', '', 'valign="middle" nowrap' );
22642690 717 getMbxList($imapConnection);
718 echo getButton('SUBMIT', 'moveButton',_("Move")) . "\n";
719 echo getButton('SUBMIT', 'attache',_("Forward")) . "\n";
6c930ade 720
22642690 721 echo " </TD>\n"
6a622b59 722 . html_tag( 'td', '', 'right', '', 'nowrap' );
e35045b7 723
22642690 724
725
6a622b59 726 if (!$auto_expunge) {
727 echo getButton('SUBMIT', 'expungeButton',_("Expunge"))
728 .'&nbsp;' . _("mailbox") . "\n";
729 }
e35045b7 730
6a622b59 731 echo getButton('SUBMIT', 'markRead',_("Read"));
732 echo getButton('SUBMIT', 'markUnread',_("Unread"));
8e724112 733 echo getButton('SUBMIT', 'delete',_("Delete")) ."&nbsp;\n";
6a622b59 734 if (!strpos($php_self,'mailbox')) {
735 $location = $php_self.'?mailbox=INBOX&amp;startMessage=1';
736 } else {
737 $location = $php_self;
8008456a 738 }
6a622b59 739 echo '<INPUT TYPE="HIDDEN" NAME="location" VALUE="'.$location.'">';
740 echo "</TD>\n"
741 . " </TR>\n";
742
743 /* draws thread sorting links */
744 if ($allow_thread_sort == TRUE) {
745 if ($thread_sort_messages == 1 ) {
746 $set_thread = 2;
747 $thread_name = _("Unthread View");
748 } elseif ($thread_sort_messages == 0) {
749 $set_thread = 1;
750 $thread_name = _("Thread View");
751 }
c1c17724 752 echo html_tag( 'tr' ,
753 html_tag( 'td' ,
e35045b7 754 '&nbsp;<a href=' . $source_url . '?sort='
c1c17724 755 . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
756 . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name
757 . '</a></small>&nbsp;'
758 , '', '', '' )
759 , '', '', '' );
6a622b59 760 }
a966982b 761
22642690 762 echo "</TABLE></td></tr></table></td></tr>\n";
a966982b 763
1b91be0c 764 do_hook('mailbox_form_before');
6c766fd5 765
8008456a 766 /* if using server sort we highjack the
6a622b59 767 * the $sort var and use $server_sort_order
768 * instead. but here we reset sort for a bit
769 * since its easy
770 */
8008456a 771 if ($allow_server_sort == TRUE) {
772 $sort = $server_sort_order;
773 }
e9e5f0fa 774}
a966982b 775
e9e5f0fa 776function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color) {
22642690 777 if ($num_msgs) {
4b920601 778 /* space between list and footer */
22642690 779 echo '<tr><td HEIGHT="5" BGCOLOR="'.$color[4].'" COLSPAN="1">';
4b920601 780
22642690 781 echo '</td></tr><tr><td>';
782 echo html_tag( 'table',
e9e5f0fa 783 html_tag( 'tr',
784 html_tag( 'td',
785 html_tag( 'table',
786 html_tag( 'tr',
787 html_tag( 'td', $paginator_str ) .
788 html_tag( 'td', $msg_cnt_str, 'right' )
789 )
22642690 790 , '', $color[4], 'width="100%" border="0" cellpadding="1" cellspacing="0"' )
e9e5f0fa 791 )
22642690 792 )
793 , '', $color[9], 'width="100%" border="0" cellpadding="1" cellspacing="0"' );
794 echo '</td></tr>';
795 }
6a622b59 796 /* End of message-list table */
a966982b 797
6a622b59 798 do_hook('mailbox_index_after');
799 echo "</FORM>\n";
a966982b 800}
801
e9e5f0fa 802function printHeader($mailbox, $sort, $color, $showsort=true) {
6a622b59 803 global $index_order;
1b91be0c 804 echo html_tag( 'tr' ,'' , 'center', $color[5] );
e4b5f9d1 805
806 /* calculate the width of the subject column based on the
807 * widths of the other columns */
808 $widths = array(1=>1,2=>25,3=>5,4=>0,5=>1,6=>5);
809 $subjectwidth = 100;
810 foreach($index_order as $item) {
811 $subjectwidth -= $widths[$item];
812 }
813
814 foreach ($index_order as $item) {
815 switch ($item) {
8008456a 816 case 1: /* checkbox */
817 case 5: /* flags */
1b91be0c 818 echo html_tag( 'td' ,'&nbsp;' , '', '', 'width="1%"' );
8008456a 819 break;
820 case 2: /* from */
821 if (handleAsSent($mailbox)) {
1b91be0c 822 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
6a622b59 823 . '<b>' . _("To") . '</b>';
8008456a 824 } else {
1b91be0c 825 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
6a622b59 826 . '<b>' . _("From") . '</b>';
8008456a 827 }
a966982b 828 if ($showsort) {
1b91be0c 829 ShowSortButton($sort, $mailbox, 2, 3);
8008456a 830 }
1b91be0c 831 echo "</td>\n";
8008456a 832 break;
833 case 3: /* date */
1b91be0c 834 echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
6a622b59 835 . '<b>' . _("Date") . '</b>';
a966982b 836 if ($showsort) {
1b91be0c 837 ShowSortButton($sort, $mailbox, 0, 1);
8008456a 838 }
1b91be0c 839 echo "</td>\n";
8008456a 840 break;
a966982b 841 case 4: /* subject */
e4b5f9d1 842 echo html_tag( 'td' ,'' , 'left', '', 'width="'.$subjectwidth.'%"' )
6a622b59 843 . '<b>' . _("Subject") . '</b>';
a966982b 844 if ($showsort) {
1b91be0c 845 ShowSortButton($sort, $mailbox, 4, 5);
8008456a 846 }
1b91be0c 847 echo "</td>\n";
8008456a 848 break;
849 case 6: /* size */
e842b215 850 echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%" nowrap' );
8008456a 851 break;
852 }
bdfb67f8 853 }
1b91be0c 854 echo "</tr>\n";
bdfb67f8 855}
856
e9e5f0fa 857
bdfb67f8 858/*
e35045b7 859 * This function shows the sort button. Isn't this a good comment?
860 */
861function ShowSortButton($sort, $mailbox, $Up, $Down ) {
6a622b59 862 global $PHP_SELF;
863 /* Figure out which image we want to use. */
864 if ($sort != $Up && $sort != $Down) {
865 $img = 'sort_none.png';
866 $which = $Up;
867 } elseif ($sort == $Up) {
868 $img = 'up_pointer.png';
869 $which = $Down;
6c930ade 870 } else {
6a622b59 871 $img = 'down_pointer.png';
872 $which = 6;
e35045b7 873 }
6a622b59 874
875 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
876 $source_url = $regs[1];
e35045b7 877 } else {
6a622b59 878 $source_url = $PHP_SELF;
6c930ade 879 }
6a622b59 880
881 /* Now that we have everything figured out, show the actual button. */
882 echo ' <a href="' . $source_url .'?newsort=' . $which
883 . '&amp;startMessage=1&amp;mailbox=' . urlencode($mailbox)
884 . '"><IMG SRC="../images/' . $img
885 . '" BORDER=0 WIDTH=12 HEIGHT=10 ALT="sort"></a>';
886}
887
888function get_selectall_link($start_msg, $sort) {
889 global $checkall, $what, $where, $mailbox, $javascript_on;
890 global $PHP_SELF, $PG_SHOWNUM;
891
892 $result = '';
893 if ($javascript_on) {
894 $result = '<script language="JavaScript" type="text/javascript">'
895 . "\n<!-- \n"
896 . "function CheckAll() {\n"
897 . " for (var i = 0; i < document.messageList.elements.length; i++) {\n"
898 . " if(document.messageList.elements[i].type == 'checkbox'){\n"
899 . " document.messageList.elements[i].checked = "
900 . " !(document.messageList.elements[i].checked);\n"
901 . " }\n"
902 . " }\n"
903 . "}\n"
904 . "//-->\n"
905 . '</script><a href="#" onClick="CheckAll();">' . _("Toggle All")
906 . "</a>\n";
e35045b7 907 } else {
6a622b59 908 if (strpos($PHP_SELF, "?")) {
909 $result .= "<a href=\"$PHP_SELF&amp;mailbox=" . urlencode($mailbox)
910 . "&amp;startMessage=$start_msg&amp;sort=$sort&amp;checkall=";
911 } else {
912 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
913 . "&amp;startMessage=$start_msg&amp;sort=$sort&amp;checkall=";
914 }
915 if (isset($checkall) && $checkall == '1') {
916 $result .= '0';
917 } else {
918 $result .= '1';
919 }
920
921 if (isset($where) && isset($what)) {
922 $result .= '&amp;where=' . urlencode($where)
923 . '&amp;what=' . urlencode($what);
924 }
925 $result .= "\">";
926
927 if (isset($checkall) && ($checkall == '1')) {
928 $result .= _("Unselect All");
929 } else {
930 $result .= _("Select All");
931 }
932 $result .= "</A>\n";
e35045b7 933 }
23d6bd09 934
6a622b59 935 /* Return our final result. */
936 return ($result);
bdfb67f8 937}
1a0e0983 938
6c930ade 939/*
e35045b7 940 * This function computes the "Viewing Messages..." string.
941 */
bdfb67f8 942function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
6a622b59 943 /* Compute the $msg_cnt_str. */
944 $result = '';
945 if ($start_msg < $end_msg) {
946 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
947 $start_msg, $end_msg, $num_msgs);
948 } else if ($start_msg == $end_msg) {
949 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
950 } else {
951 $result = '<br>';
952 }
953 /* Return our result string. */
954 return ($result);
bdfb67f8 955}
956
6c930ade 957/*
e35045b7 958 * Generate a paginator link.
959 */
6c930ade 960function get_paginator_link($box, $start_msg, $use, $text) {
6a622b59 961 global $PHP_SELF;
e35045b7 962
6a622b59 963 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
964 . "&amp;startMessage=$start_msg&amp;mailbox=$box\" "
965 . "TARGET=\"right\">$text</A>";
966 return ($result);
756d0680 967/*
6a622b59 968 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
969 $source_url = $regs[1];
970 } else {
971 $source_url = $PHP_SELF;
972 }
973
974 $result = '<A HREF="'. $source_url . "?use_mailbox_cache=$use"
975 . "&amp;startMessage=$start_msg&amp;mailbox=$box\" "
976 . "TARGET=\"right\">$text</A>";
977 return ($result);
978*/
7b294953 979}
980
6c930ade 981/*
e35045b7 982 * This function computes the paginator string.
983 */
6a622b59 984function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
985 $show_num, $sort) {
986 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
987
988 /* Initialize paginator string chunks. */
989 $prv_str = '';
990 $nxt_str = '';
991 $pg_str = '';
992 $all_str = '';
993 $tgl_str = '';
994
995 $box = urlencode($box);
996
997 /* Create simple strings that will be creating the paginator. */
998 $spc = '&nbsp;'; /* 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
e35045b7 1049 /* Otherwise, compute some magic to choose the four quarters. */
6a622b59 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 }
e35045b7 1095
6a622b59 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 . "&amp;use_mailbox_cache=$use&amp;startMessage=1&amp;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 . "&amp;use_mailbox_cache=$use&amp;startMessage=1&amp;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 = '&nbsp;';
1176 }
e35045b7 1177
6a622b59 1178 /* Return our final magical paginator string. */
1179 return ($result);
bdfb67f8 1180}
1181
6903c7bd 1182function processSubject($subject, $threadlevel = 0) {
6fbd125b 1183 global $languages, $squirrelmail_language;
6a622b59 1184 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1185 if ($subject == '')
1186 return _("(no subject)");
e35045b7 1187
6903c7bd 1188 $trim_at = 55;
1189
c2f88417 1190 /* if this is threaded, subtract two chars per indentlevel */
6903c7bd 1191 if($threadlevel > 0 && $threadlevel <= 10)
1192 $trim_at -= (2*$threadlevel);
1193
1194 if (strlen($subject) <= $trim_at)
6a622b59 1195 return $subject;
1196
46a49f65 1197 $ent_strlen = $orig_len = strlen($subject);
6903c7bd 1198 $trim_val = $trim_at - 5;
1199 $ent_offset = 0;
6a622b59 1200 /*
1201 * see if this is entities-encoded string
1202 * If so, Iterate through the whole string, find out
1203 * the real number of characters, and if more
46a49f65 1204 * than 55, substr with an updated trim value.
6a622b59 1205 */
a1440f89 1206 $step = $ent_loc = 0;
1207 while ( $ent_loc < $trim_val && (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1208 (($ent_loc_end = strpos($subject, ';', $ent_loc+3)) !== false) ) {
1209 $trim_val += ($ent_loc_end-$ent_loc);
6a622b59 1210 $ent_offset = $ent_loc_end+1;
a1440f89 1211 ++$step;
6a622b59 1212 }
a1440f89 1213
1214 if (($trim_val > 50) && (strlen($subject) > ($trim_val))&& (strpos($subject,';',$trim_val) < ($trim_val +6))) {
1215 $i = strpos($subject,';',$trim_val);
1216 if ($i) {
1217 $trim_val = strpos($subject,';',$trim_val);
1218 }
46a49f65 1219 }
6903c7bd 1220 if ($ent_strlen <= $trim_at){
6a622b59 1221 return $subject;
1222 }
1223
1224 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
1225 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
1226 return $languages[$squirrelmail_language]['XTRA_CODE']('strimwidth', $subject, $trim_val);
1227 }
6a622b59 1228 return substr($subject, 0, $trim_val) . '...';
bdfb67f8 1229}
f93c93b9 1230
6a622b59 1231function getMbxList($imapConnection) {
1232 global $lastTargetMailbox;
1233 echo ' <small>&nbsp;<tt><select name="targetMailbox">';
be2d5495 1234 echo sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)) );
6a622b59 1235 echo ' </SELECT></TT>&nbsp;';
e9e5f0fa 1236}
1237
1238function getButton($type, $name, $value) {
6a622b59 1239 return '<INPUT TYPE="'.$type.'" NAME="'.$name.'" VALUE="'.$value . '">';
e9e5f0fa 1240}
1241
1242function getSmallStringCell($string, $align) {
6a622b59 1243 return html_tag('td',
1244 '<small>' . $string . ':&nbsp; </small>',
1245 $align,
1246 '',
1247 'nowrap' );
e9e5f0fa 1248}
1249
1250function getEndMessage($start_msg, $show_num, $num_msgs) {
6a622b59 1251 if ($start_msg + ($show_num - 1) < $num_msgs){
1252 $end_msg = $start_msg + ($show_num - 1);
1253 } else {
1254 $end_msg = $num_msgs;
1255 }
e9e5f0fa 1256
6a622b59 1257 if ($end_msg < $start_msg) {
1258 $start_msg = $start_msg - $show_num;
1259 if ($start_msg < 1) {
1260 $start_msg = 1;
1261 }
e9e5f0fa 1262 }
6a622b59 1263 return (array($start_msg,$end_msg));
e9e5f0fa 1264}
1265
a3439b27 1266function handleAsSent($mailbox) {
6a8e7cae 1267 global $handleAsSent_result;
1268
6a622b59 1269 /* First check if this is the sent or draft folder. */
6a8e7cae 1270 $handleAsSent_result = isSentMailbox($mailbox) || isDraftMailbox($mailbox);
a3439b27 1271
6a622b59 1272 /* Then check the result of the handleAsSent hook. */
1273 do_hook('check_handleAsSent_result', $mailbox);
a3439b27 1274
6a622b59 1275 /* And return the result. */
6a8e7cae 1276 return $handleAsSent_result;
6a622b59 1277}
e842b215 1278
937c81fa 1279?>