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