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