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