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