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