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