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