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