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