button tweaks
[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');
454
455 mail_message_listing_beginning($imapConnection, $mailbox, $sort,
456 $msg_cnt_str, $paginator_str, $start_msg);
e35045b7 457
86419c0b 458
6206f6c4 459 echo '<table bgcolor="' . $color[0] . '" border="0" width="100%" cellpadding="1" cellspacing="0"><tr><td>';
e9e5f0fa 460 printHeader($mailbox, $srt, $color, !$thread_sort_messages);
8008456a 461
e9e5f0fa 462 displayMessageArray($imapConnection, $num_msgs, $start_msg,
463 $msort, $mailbox, $sort, $color, $show_num,0,0);
8008456a 464
e9e5f0fa 465 mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color);
6206f6c4 466 echo '</td></tr></table>';
e9e5f0fa 467
e35045b7 468 /**
469 * TODO: Switch to using $_SESSION[] whenever we ditch the 4.0.x series.
470 */
6c930ade 471}
bdfb67f8 472
e9e5f0fa 473function calc_msort($msgs, $sort) {
8008456a 474
e35045b7 475 /*
476 * 0 = Date (up)
477 * 1 = Date (dn)
478 * 2 = Name (up)
479 * 3 = Name (dn)
480 * 4 = Subject (up)
481 * 5 = Subject (dn)
482 */
e9e5f0fa 483 if (($sort == 0) || ($sort == 1)) {
484 $msort = array_cleave ($msgs, 'TIME_STAMP');
485 } elseif (($sort == 2) || ($sort == 3)) {
486 $msort = array_cleave ($msgs, 'FROM-SORT');
487 } elseif (($sort == 4) || ($sort == 5)) {
488 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
489 } else {
e35045b7 490 $msort = $msgs;
e9e5f0fa 491 }
492 if ($sort < 6) {
493 if ($sort % 2) {
494 asort($msort);
495 } else {
496 arsort($msort);
497 }
e35045b7 498 }
499 return $msort;
500}
501
e9e5f0fa 502function fillMessageArray($imapConnection,$id,$count) {
503 $msgs_list = sqimap_get_small_header_list($imapConnection, $id);
a966982b 504 $messages = array();
e35045b7 505 if (sizeof($msgs_list)){
506 foreach ($msgs_list as $hdr) {
507 $unique_id[] = $hdr->uid;
508 $from[] = $hdr->from;
509 $date[] = $hdr->date;
510 $subject[] = $hdr->subject;
511 $to[] = $hdr->to;
512 $priority[] = $hdr->priority;
513 $cc[] = $hdr->cc;
514 $size[] = $hdr->size;
515 $type[] = $hdr->type0;
516 $flag_deleted[] = $hdr->flag_deleted;
517 $flag_answered[] = $hdr->flag_answered;
518 $flag_seen[] = $hdr->flag_seen;
519 $flag_flagged[] = $hdr->flag_flagged;
520 }
521 }
522
523 $j = 0;
524 while ($j < $count) {
525
526 if (isset($date[$j])) {
527 $date[$j] = str_replace(' ', ' ', $date[$j]);
528 $tmpdate = explode(' ', trim($date[$j]));
529 } else {
530 $tmpdate = $date = array('', '', '', '', '', '');
531 }
a966982b 532 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
533 $messages[$j]['DATE_STRING'] =
89e334aa 534 getDateString($messages[$j]['TIME_STAMP']);
a966982b 535 $messages[$j]['ID'] = $unique_id[$j];
536 $messages[$j]['FROM'] = decodeHeader($from[$j]);
537 $messages[$j]['FROM-SORT'] =
e35045b7 538 strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
a966982b 539 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
540 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
541 $messages[$j]['TO'] = decodeHeader($to[$j]);
542 $messages[$j]['PRIORITY'] = $priority[$j];
543 $messages[$j]['CC'] = $cc[$j];
544 $messages[$j]['SIZE'] = $size[$j];
545 $messages[$j]['TYPE0'] = $type[$j];
546 $messages[$j]['FLAG_DELETED'] = $flag_deleted[$j];
547 $messages[$j]['FLAG_ANSWERED'] = $flag_answered[$j];
548 $messages[$j]['FLAG_SEEN'] = $flag_seen[$j];
549 $messages[$j]['FLAG_FLAGGED'] = $flag_flagged[$j];
e35045b7 550
551
552 /*
553 * fix SUBJECT-SORT to remove Re:
554 * vedr|sv (Danish)
555 * re|aw (English)
556 *
557 * TODO: i18n should be incorporated here. E.g. we catch the ones
558 * we know about, but also define in i18n what the localized
559 * "Re: " is for this or that locale.
560 */
561 if (preg_match("/^(vedr|sv|re|aw):\s*(.*)$/si",
a966982b 562 $messages[$j]['SUBJECT-SORT'], $matches)){
563 $messages[$j]['SUBJECT-SORT'] = $matches[2];
e35045b7 564 }
565 $j++;
566 }
567 return $messages;
568}
8008456a 569
e9e5f0fa 570
e35045b7 571/* Generic function to convert the msgs array into an HTML table. */
572function displayMessageArray($imapConnection, $num_msgs, $start_msg,
e9e5f0fa 573 $msort, $mailbox, $sort, $color,
574 $show_num, $where=0, $what=0) {
575 global $imapServerAddress, $use_mailbox_cache,
576 $index_order, $checkall,
a966982b 577 $indent_array, $thread_sort_messages, $allow_server_sort,
578 $server_sort_order, $PHP_SELF;
e35045b7 579
44369a30 580 $res = getEndMessage($start_msg, $show_num, $num_msgs);
581 $start_msg = $res[0];
582 $end_msg = $res[1];
8008456a 583
e35045b7 584 $urlMailbox = urlencode($mailbox);
8008456a 585
e35045b7 586 /* get indent level for subject display */
587 if ($thread_sort_messages == 1 ) {
588 $indent_array = get_parent_level($imapConnection);
589 }
a966982b 590
e9e5f0fa 591
e35045b7 592 $real_startMessage = $start_msg;
593 if ($sort == 6) {
594 if ($end_msg - $start_msg < $show_num - 1) {
595 $end_msg = $end_msg - $start_msg + 1;
596 $start_msg = 1;
597 } else if ($start_msg > $show_num) {
598 $end_msg = $show_num;
599 $start_msg = 1;
94ac35c6 600 }
e35045b7 601 }
602 $endVar = $end_msg + 1;
603
604 /*
605 * Loop through and display the info for each message.
606 * ($t is used for the checkbox number)
607 */
608 $t = 0;
a966982b 609
610 /* messages display */
86419c0b 611
e35045b7 612 if ($num_msgs == 0) {
613 /* if there's no messages in this folder */
8008456a 614 echo html_tag( 'tr',
13cf639b 615 html_tag( 'td',
6b4bd11f 616 "<BR><b>" . _("THIS FOLDER IS EMPTY") . "</b><BR>&nbsp;",
13cf639b 617 'center',
618 $color[4],
619 'COLSPAN="' . count($index_order) . '"'
620 )
621 );
e35045b7 622 } elseif ($start_msg == $end_msg) {
623 /* if there's only one message in the box, handle it differently. */
624 if ($sort != 6){
625 $i = $start_msg;
94ac35c6 626 } else {
e35045b7 627 $i = 1;
94ac35c6 628 }
e35045b7 629 reset($msort);
630 $k = 0;
631 do {
632 $key = key($msort);
633 next($msort);
634 $k++;
635 } while (isset ($key) && ($k < $i));
e9e5f0fa 636 printMessageInfo($imapConnection, $t, $i, $key, $mailbox,
4f26958e 637 $real_startMessage, $where, $what);
e35045b7 638 } else {
639 $i = $start_msg;
640 reset($msort);
641 $k = 0;
642 do {
643 $key = key($msort);
644 next($msort);
645 $k++;
646 } while (isset ($key) && ($k < $i));
647 do {
648 printMessageInfo($imapConnection, $t, $i, $key, $mailbox,
d215ca7d 649 $real_startMessage, $where, $what);
e35045b7 650 $key = key($msort);
651 $t++;
652 $i++;
653 next($msort);
654 } while ($i && $i < $endVar);
655 }
e35045b7 656 echo '</table>';
bdfb67f8 657}
658
6c930ade 659/*
e35045b7 660 * Displays the standard message list header. To finish the table,
661 * you need to do a "</table></table>";
662 *
663 * $moveURL is the URL to submit the delete/move form to
664 * $mailbox is the current mailbox
665 * $sort is the current sorting method (-1 for no sorting available [searches])
666 * $Message is a message that is centered on top of the list
667 * $More is a second line that is left aligned
668 */
669
e9e5f0fa 670function mail_message_listing_beginning ($imapConnection,
e35045b7 671 $mailbox = '', $sort = -1,
672 $msg_cnt_str = '',
673 $paginator = '&nbsp;',
674 $start_msg = 1) {
e9e5f0fa 675 global $color, $auto_expunge, $base_uri, $thread_sort_messages,
e35045b7 676 $allow_thread_sort, $allow_server_sort, $server_sort_order,
e9e5f0fa 677 $PHP_SELF;
3ab69ec4 678
679 $php_self = $PHP_SELF;
680 /* fix for incorrect $PHP_SELF */
681 if (strpos($php_self, 'move_messages.php')) {
682 $php_self = str_replace('move_messages.php', 'right_main.php', $php_self);
683 }
e35045b7 684 $urlMailbox = urlencode($mailbox);
685
3ab69ec4 686 if (preg_match('/^(.+)\?.+$/',$php_self,$regs)) {
e35045b7 687 $source_url = $regs[1];
688 } else {
3ab69ec4 689 $source_url = $php_self;
e35045b7 690 }
691
2e716bd9 692 if (!isset($msg)) {
693 $msg = '';
694 }
695 $moveURL = "move_messages.php?msg=$msg&amp;mailbox=$urlMailbox"
696 . "&amp;startMessage=$start_msg";
e35045b7 697 /*
698 * This is the beginning of the message list table.
699 * It wraps around all messages
700 */
8008456a 701
8008456a 702 echo "<FORM name=\"messageList\" method=post action=\"$moveURL\">\n"
c1c17724 703 . html_tag( 'table' ,'' , '', '', 'border="0" width="100%" cellpadding="1" cellspacing="0"' ) .
704 html_tag( 'tr',
705 html_tag( 'td' ,
706 html_tag( 'table' ,
707 html_tag( 'tr',
708 html_tag( 'td', $paginator, 'left' ) .
709 html_tag( 'td', $msg_cnt_str, 'right' )
710 )
711 , '', $color[4], 'border="0" width="100%" cellpadding="2" cellspacing="0"' )
712 , 'left', '', '' )
713 , '', $color[0] )
6b4bd11f 714 . html_tag( 'tr' ) . "\n"
c1c17724 715 . html_tag( 'td' ,'' , 'left', $color[0], '' )
716 . html_tag( 'table' ,'' , '', $color[0], 'border="0" width="100%" cellpadding="0" cellspacing="0"' )
717 . html_tag( 'tr',
91b41a80 718 getSmallStringCell(_("Move Selected To"), 'left') .
e9e5f0fa 719 getSmallStringCell(_("Transform Selected Messages"), 'right')
c1c17724 720 )
e9e5f0fa 721 . html_tag( 'tr' ) ."\n"
722 . html_tag( 'td', '', 'left', '', 'valign="middle" nowrap' );
723 getMbxList($imapConnection);
a8e019f9 724 echo getButton('SUBMIT', 'moveButton',_("Move")) . "\n";
725 echo getButton('SUBMIT', 'attache',_("Forward")) . "\n";
6c930ade 726
e35045b7 727 echo " </TD>\n"
6b4bd11f 728 . html_tag( 'td', '', 'right', '', 'nowrap' );
e35045b7 729
730 if (!$auto_expunge) {
e9e5f0fa 731 echo getButton('SUBMIT', 'expungeButton',_("Expunge"))
a8e019f9 732 .'&nbsp;' . _("mailbox") . "\n";
e35045b7 733 }
e9e5f0fa 734
a8e019f9 735 echo getButton('SUBMIT', 'markRead',_("Read"));
736 echo getButton('SUBMIT', 'markUnread',_("Unread"));
737 echo getButton('SUBMIT', 'delete',_("Delete")) ."&nbsp\n";
3ab69ec4 738 if (!strpos($php_self,'mailbox')) {
739 $location = $php_self.'?mailbox=INBOX&amp;startMessage=1';
a3dd7047 740 } else {
3ab69ec4 741 $location = $php_self;
a3dd7047 742 }
743 echo '<INPUT TYPE="HIDDEN" NAME="location" VALUE="'.$location.'">';
e9e5f0fa 744 echo "</TD>\n"
745 . " </TR>\n";
e35045b7 746
747 /* draws thread sorting links */
748 if ($allow_thread_sort == TRUE) {
749 if ($thread_sort_messages == 1 ) {
750 $set_thread = 2;
751 $thread_name = _("Unthread View");
752 }
753 elseif ($thread_sort_messages == 0) {
754 $set_thread = 1;
755 $thread_name = _("Thread View");
8008456a 756 }
c1c17724 757 echo html_tag( 'tr' ,
758 html_tag( 'td' ,
e35045b7 759 '&nbsp;<a href=' . $source_url . '?sort='
c1c17724 760 . "$sort" . '&start_messages=1&set_thread=' . "$set_thread"
761 . '&mailbox=' . urlencode($mailbox) . '><small>' . $thread_name
762 . '</a></small>&nbsp;'
763 , '', '', '' )
764 , '', '', '' );
e35045b7 765 }
766
767 echo "</TABLE>\n";
8008456a 768
6b4bd11f 769 echo "</table>\n";
a966982b 770
8008456a 771 do_hook('mailbox_form_before');
a966982b 772
6b4bd11f 773 echo '</td></tr>'
a966982b 774 . html_tag( 'tr' )
c1c17724 775 . html_tag( 'td' ,'' , '', $color[0], '' );
e9e5f0fa 776
8008456a 777 /* if using server sort we highjack the
778 * the $sort var and use $server_sort_order
779 * instead. but here we reset sort for a bit
780 * since its easy
781 */
782 if ($allow_server_sort == TRUE) {
783 $sort = $server_sort_order;
784 }
e9e5f0fa 785}
a966982b 786
e9e5f0fa 787function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color) {
788 if ($num_msgs) {
789 echo html_tag( 'table',
790 html_tag( 'tr',
791 html_tag( 'td',
792 html_tag( 'table',
793 html_tag( 'tr',
794 html_tag( 'td', $paginator_str ) .
795 html_tag( 'td', $msg_cnt_str, 'right' )
796 )
797 , '', $color[4], 'width="100%" cellpadding="1" cellspacing="1"' )
798 )
799 , '', $color[4] )
800 , '', $color[9], 'width="100%" cellpadding="1" cellspacing="1"' );
a966982b 801
e9e5f0fa 802 }
803 /* End of message-list table */
804
805 do_hook('mailbox_index_after');
806 echo "</FORM>\n";
a966982b 807
808}
809
e9e5f0fa 810function printHeader($mailbox, $sort, $color, $showsort=true) {
a966982b 811 global $index_order;
6206f6c4 812 echo html_tag( 'table' ,'' , '', $color[4], 'border="0" width="100%" cellpadding="1" cellspacing="0"' );
e9e5f0fa 813 echo html_tag( 'tr' ,'' , 'center', $color[5] );
8008456a 814 for ($i=1; $i <= count($index_order); $i++) {
815 switch ($index_order[$i]) {
816 case 1: /* checkbox */
817 case 5: /* flags */
6b4bd11f 818 echo html_tag( 'td' ,'&nbsp;' , '', '', 'width="1%"' );
8008456a 819 break;
820 case 2: /* from */
821 if (handleAsSent($mailbox)) {
c1c17724 822 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
823 . '<b>' . _("To") . '</b>';
8008456a 824 } else {
c1c17724 825 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
826 . '<b>' . _("From") . '</b>';
8008456a 827 }
a966982b 828 if ($showsort) {
8008456a 829 ShowSortButton($sort, $mailbox, 2, 3);
830 }
6b4bd11f 831 echo "</td>\n";
8008456a 832 break;
833 case 3: /* date */
c1c17724 834 echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
835 . '<b>' . _("Date") . '</b>';
a966982b 836 if ($showsort) {
8008456a 837 ShowSortButton($sort, $mailbox, 0, 1);
838 }
c1c17724 839 echo "</td>\n";
8008456a 840 break;
a966982b 841 case 4: /* subject */
c1c17724 842 echo html_tag( 'td' ,'' , 'left', '', '' )
843 . '<b>' . _("Subject") . '</b>';
a966982b 844 if ($showsort) {
8008456a 845 ShowSortButton($sort, $mailbox, 4, 5);
846 }
6b4bd11f 847 echo "</td>\n";
8008456a 848 break;
849 case 6: /* size */
850 echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%"' );
851 break;
852 }
bdfb67f8 853 }
e9e5f0fa 854 echo "</tr>\n";
bdfb67f8 855}
856
e9e5f0fa 857
bdfb67f8 858/*
e35045b7 859 * This function shows the sort button. Isn't this a good comment?
860 */
861function ShowSortButton($sort, $mailbox, $Up, $Down ) {
862 global $PHP_SELF;
863 /* Figure out which image we want to use. */
864 if ($sort != $Up && $sort != $Down) {
865 $img = 'sort_none.png';
866 $which = $Up;
867 } elseif ($sort == $Up) {
868 $img = 'up_pointer.png';
869 $which = $Down;
870 } else {
871 $img = 'down_pointer.png';
872 $which = 6;
873 }
874
875 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
876 $source_url = $regs[1];
877 } else {
878 $source_url = $PHP_SELF;
879 }
880
881 /* Now that we have everything figured out, show the actual button. */
882 echo ' <a href="' . $source_url .'?newsort=' . $which
6c930ade 883 . '&amp;startMessage=1&amp;mailbox=' . urlencode($mailbox)
e35045b7 884 . '"><IMG SRC="../images/' . $img
885 . '" BORDER=0 WIDTH=12 HEIGHT=10 ALT="sort"></a>';
bdfb67f8 886}
887
888function get_selectall_link($start_msg, $sort) {
e35045b7 889 global $checkall, $what, $where, $mailbox, $javascript_on;
890 global $PHP_SELF, $PG_SHOWNUM;
891
892 $result = '';
893 if ($javascript_on) {
894 $result =
895 '<script language="JavaScript" type="text/javascript">'
896 . "\n<!-- \n"
897 . "function CheckAll() {\n"
898 . " for (var i = 0; i < document.messageList.elements.length; i++) {\n"
899 . " if(document.messageList.elements[i].type == 'checkbox'){\n"
900 . " document.messageList.elements[i].checked = "
901 . " !(document.messageList.elements[i].checked);\n"
902 . " }\n"
903 . " }\n"
904 . "}\n"
905 . "//-->\n"
906 . '</script><a href="#" onClick="CheckAll();">' . _("Toggle All")
907 . "</a>\n";
908 } else {
909 if (strpos($PHP_SELF, "?")) {
910 $result .= "<a href=\"$PHP_SELF&amp;mailbox=" . urlencode($mailbox)
911 . "&amp;startMessage=$start_msg&amp;sort=$sort&amp;checkall=";
6c930ade 912 } else {
e35045b7 913 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
914 . "&amp;startMessage=$start_msg&amp;sort=$sort&amp;checkall=";
915 }
916 if (isset($checkall) && $checkall == '1') {
917 $result .= '0';
918 } else {
919 $result .= '1';
6c930ade 920 }
e35045b7 921
922 if (isset($where) && isset($what)) {
923 $result .= '&amp;where=' . urlencode($where)
924 . '&amp;what=' . urlencode($what);
925 }
926
927 $result .= "\">";
928
929 if (isset($checkall) && ($checkall == '1')) {
930 $result .= _("Unselect All");
931 } else {
932 $result .= _("Select All");
933 }
934
935 $result .= "</A>\n";
936 }
23d6bd09 937
e35045b7 938 /* Return our final result. */
939 return ($result);
bdfb67f8 940}
1a0e0983 941
6c930ade 942/*
e35045b7 943 * This function computes the "Viewing Messages..." string.
944 */
bdfb67f8 945function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
e35045b7 946 /* Compute the $msg_cnt_str. */
947 $result = '';
948 if ($start_msg < $end_msg) {
949 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"),
950 $start_msg, $end_msg, $num_msgs);
951 } else if ($start_msg == $end_msg) {
952 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
953 } else {
954 $result = '<br>';
955 }
e35045b7 956 /* Return our result string. */
957 return ($result);
bdfb67f8 958}
959
6c930ade 960/*
e35045b7 961 * Generate a paginator link.
962 */
6c930ade 963function get_paginator_link($box, $start_msg, $use, $text) {
e35045b7 964 global $PHP_SELF;
965
756d0680 966 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
967 . "&amp;startMessage=$start_msg&amp;mailbox=$box\" "
968 . "TARGET=\"right\">$text</A>";
969 return ($result);
970/*
e35045b7 971 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
972 $source_url = $regs[1];
973 } else {
974 $source_url = $PHP_SELF;
975 }
e9e5f0fa 976
e35045b7 977 $result = '<A HREF="'. $source_url . "?use_mailbox_cache=$use"
6c930ade 978 . "&amp;startMessage=$start_msg&amp;mailbox=$box\" "
e35045b7 979 . "TARGET=\"right\">$text</A>";
980 return ($result);
756d0680 981*/
7b294953 982}
983
6c930ade 984/*
e35045b7 985 * This function computes the paginator string.
986 */
987function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
988 $show_num, $sort) {
989 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
990
991 /* Initialize paginator string chunks. */
992 $prv_str = '';
993 $nxt_str = '';
994 $pg_str = '';
995 $all_str = '';
996 $tgl_str = '';
997
e9e5f0fa 998 $box = urlencode($box);
999
e35045b7 1000 /* Create simple strings that will be creating the paginator. */
1001 $spc = '&nbsp;'; /* This will be used as a space. */
1002 $sep = '|'; /* This will be used as a seperator. */
1003
1004 /* Get some paginator preference values. */
1005 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON);
1006 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX);
1007
1008 /* Make sure that our start message number is not too big. */
1009 $start_msg = min($start_msg, $num_msgs);
1010
1011 /* Decide whether or not we will use the mailbox cache. */
1012 /* Not sure why $use_mailbox_cache is even passed in. */
1013 if ($sort == 6) {
1014 $use = 0;
1015 } else {
1016 $use = 1;
1017 }
1018
1019 /* Compute the starting message of the previous and next page group. */
1020 $next_grp = $start_msg + $show_num;
1021 $prev_grp = $start_msg - $show_num;
1022
1023 /* Compute the basic previous and next strings. */
1024 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
1025 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1026 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1027 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
1028 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1029 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
1030 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
1031 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
1032 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1033 }
1034
1035 /* Page selector block. Following code computes page links. */
1036 if ($pg_sel && ($num_msgs > $show_num)) {
1037 /* Most importantly, what is the current page!!! */
1038 $cur_pg = intval($start_msg / $show_num) + 1;
1039
1040 /* Compute total # of pages and # of paginator page links. */
1041 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
1042 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
1043
1044 /* Compute the size of the four quarters of the page links. */
1045
1046 /* If we can, just show all the pages. */
1047 if (($tot_pgs - 1) <= $pg_max) {
1048 $q1_pgs = $cur_pg - 1;
1049 $q2_pgs = $q3_pgs = 0;
1050 $q4_pgs = $tot_pgs - $cur_pg;
1051
1052 /* Otherwise, compute some magic to choose the four quarters. */
1053 } else {
1054 /*
1055 * Compute the magic base values. Added together,
1056 * these values will always equal to the $pag_pgs.
1057 * NOTE: These are DEFAULT values and do not take
1058 * the current page into account. That is below.
1059 */
1060 $q1_pgs = floor($vis_pgs/4);
1061 $q2_pgs = round($vis_pgs/4, 0);
1062 $q3_pgs = ceil($vis_pgs/4);
1063 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
1064
1065 /* Adjust if the first quarter contains the current page. */
1066 if (($cur_pg - $q1_pgs) < 1) {
1067 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) + $q2_pgs;
1068 $q1_pgs = $cur_pg - 1;
1069 $q2_pgs = 0;
1070 $q3_pgs += ceil($extra_pgs / 2);
1071 $q4_pgs += floor($extra_pgs / 2);
1072
1073 /* Adjust if the first and second quarters intersect. */
1074 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
1075 $extra_pgs = $q2_pgs;
1076 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1077 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
1078 $q3_pgs += ceil($extra_pgs / 2);
1079 $q4_pgs += floor($extra_pgs / 2);
1080
1081 /* Adjust if the fourth quarter contains the current page. */
1082 } else if (($cur_pg + $q4_pgs) >= $tot_pgs) {
1083 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) + $q3_pgs;
1084 $q3_pgs = 0;
1085 $q4_pgs = $tot_pgs - $cur_pg;
1086 $q1_pgs += floor($extra_pgs / 2);
1087 $q2_pgs += ceil($extra_pgs / 2);
1088
1089 /* Adjust if the third and fourth quarter intersect. */
1090 } else if (($cur_pg + $q3_pgs + 1) >= ($tot_pgs - $q4_pgs + 1)) {
1091 $extra_pgs = $q3_pgs;
1092 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1093 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
1094 $q1_pgs += floor($extra_pgs / 2);
1095 $q2_pgs += ceil($extra_pgs / 2);
1096 }
1097 }
1098
1099 /*
1100 * I am leaving this debug code here, commented out, because
1101 * it is a really nice way to see what the above code is doing.
1102 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
1103 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>';
1104 */
1105
1106 /* Print out the page links from the compute page quarters. */
1107
1108 /* Start with the first quarter. */
1109 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1110 $pg_str .= "...$spc";
1111 } else {
1112 for ($pg = 1; $pg <= $q1_pgs; ++$pg) {
1113 $start = (($pg-1) * $show_num) + 1;
1114 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1115 }
1116 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1117 $pg_str .= "...$spc";
1118 }
1119 }
1120
1121 /* Continue with the second quarter. */
1122 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++$pg) {
1123 $start = (($pg-1) * $show_num) + 1;
1124 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1125 }
1126
1127 /* Now print the current page. */
1128 $pg_str .= $cur_pg . $spc;
1129
1130 /* Next comes the third quarter. */
1131 for ($pg = $cur_pg + 1; $pg <= $cur_pg + $q3_pgs; ++$pg) {
1132 $start = (($pg-1) * $show_num) + 1;
1133 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1134 }
1135
1136 /* And last, print the forth quarter page links. */
1137 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1138 $pg_str .= "...$spc";
1139 } else {
1140 if (($tot_pgs - $q4_pgs) > ($cur_pg + $q3_pgs)) {
1141 $pg_str .= "...$spc";
1142 }
1143 for ($pg = $tot_pgs - $q4_pgs + 1; $pg <= $tot_pgs; ++$pg) {
1144 $start = (($pg-1) * $show_num) + 1;
1145 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1146 }
1147 }
1148 } else if ($PG_SHOWNUM == 999999) {
1149 $pg_str = "<A HREF=\"right_main.php?PG_SHOWALL=0"
1150 . "&amp;use_mailbox_cache=$use&amp;startMessage=1&amp;mailbox=$box\" "
1151 . "TARGET=\"right\">" ._("Paginate") . '</A>' . $spc;
1152 }
1153
1154 /* If necessary, compute the 'show all' string. */
1155 if (($prv_str != '') || ($nxt_str != '')) {
1156 $all_str = "<A HREF=\"right_main.php?PG_SHOWALL=1"
1157 . "&amp;use_mailbox_cache=$use&amp;startMessage=1&amp;mailbox=$box\" "
1158 . "TARGET=\"right\">" . _("Show All") . '</A>';
1159 }
1160
1161 /* Last but not least, get the value for the toggle all link. */
1162 $tgl_str = get_selectall_link($start_msg, $sort);
1163
1164 /* Put all the pieces of the paginator string together. */
1165 /**
1166 * Hairy code... But let's leave it like it is since I am not certain
1167 * a different approach would be any easier to read. ;)
1168 */
1169 $result = '';
1170 $result .= ($prv_str != '' ? $prv_str . $spc . $sep . $spc : '');
1171 $result .= ($nxt_str != '' ? $nxt_str . $spc . $sep . $spc : '');
1172 $result .= ($pg_str != '' ? $pg_str : '');
1173 $result .= ($all_str != '' ? $sep . $spc . $all_str . $spc : '');
1174 $result .= ($result != '' ? $sep . $spc . $tgl_str: $tgl_str);
1175
1176 /* If the resulting string is blank, return a non-breaking space. */
1177 if ($result == '') {
1178 $result = '&nbsp;';
1179 }
1180
1181 /* Return our final magical paginator string. */
1182 return ($result);
bdfb67f8 1183}
1184
1185function processSubject($subject) {
6fbd125b 1186 global $languages, $squirrelmail_language;
e35045b7 1187 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1188 if ($subject == '')
6c930ade 1189 return _("(no subject)");
e35045b7 1190
1191 if (strlen($subject) <= 55)
6c930ade 1192 return $subject;
8008456a 1193
e35045b7 1194 $ent_strlen=strlen($subject);
1195 $trim_val=50;
1196 $ent_offset=0;
1197 /*
1198 * see if this is entities-encoded string
1199 * If so, Iterate through the whole string, find out
1200 * the real number of characters, and if more
1201 * than 55, substr with an updated trim value.
1202 */
1203 while ( (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1204 (($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false) ) {
1205 $trim_val += ($ent_loc_end-$ent_loc)+1;
1206 $ent_strlen -= $ent_loc_end-$ent_loc;
1207 $ent_offset = $ent_loc_end+1;
1208 }
1209
1210 if ($ent_strlen <= 55){
1211 return $subject;
1212 }
1213
10dec454 1214 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
1215 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
6fbd125b 1216 return $languages[$squirrelmail_language]['XTRA_CODE']('strimwidth', $subject, $trim_val);
83be314a 1217 }
1218
e35045b7 1219 return substr($subject, 0, $trim_val) . '...';
bdfb67f8 1220}
f93c93b9 1221
e9e5f0fa 1222function getMbxList($imapConnection) {
1223 global $lastTargetMailbox;
1224 echo ' <small>&nbsp;<tt><select name="targetMailbox">';
1225 $boxes = sqimap_mailbox_list($imapConnection);
1226 foreach ($boxes as $boxes_part) {
1227 if (!in_array('noselect', $boxes_part['flags'])) {
1228 $box = $boxes_part['unformatted'];
1229 $box2 = str_replace(' ', '&nbsp;', imap_utf7_decode_local($boxes_part['unformatted-disp']));
1230 if( $box2 == 'INBOX' ) {
1231 $box2 = _("INBOX");
1232 }
1233 if ($lastTargetMailbox == $box) {
1234 echo " <OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
1235 }
1236 else {
1237 echo " <OPTION VALUE=\"$box\">$box2</OPTION>\n";
1238 }
1239 }
1240 }
1241 echo ' </SELECT></TT>&nbsp;';
1242}
1243
1244function getButton($type, $name, $value) {
b1916700 1245global $color;
1246$style = ' STYLE="background:'.$color[3].';font-size:xx-small;font-weight:bold;'.
1247 'color:'.$color[8].';margin:0.05em;border:0.2em outset '.
1248 $color[9].';"';
1249$javascript = " onmouseover=\"this.style.borderColor='$color[8]'".
1250 ";this.style.borderStyle='inset'" .
1251 ";this.style.background='$color[0]';\";" .
1252 " onmouseout=\"this.style.borderColor='$color[9]'".
1253 ";this.style.borderStyle='outset'" .
1254 ";this.style.background='$color[3]';\";";
1255
1256return '<INPUT TYPE="'.$type.'" NAME="'.$name.'" VALUE="'.$value . '"'.$style.$javascript.'>';
e9e5f0fa 1257}
1258
1259function getSmallStringCell($string, $align) {
1260 return html_tag( 'td',
a8e019f9 1261 '<small>' . $string . ':&nbsp; </small>',
e9e5f0fa 1262 $align,
1263 '',
1264 'nowrap' );
1265}
1266
1267function getEndMessage($start_msg, $show_num, $num_msgs) {
1268 if ($start_msg + ($show_num - 1) < $num_msgs){
1269 $end_msg = $start_msg + ($show_num - 1);
1270 } else {
1271 $end_msg = $num_msgs;
1272 }
1273
1274 if ($end_msg < $start_msg) {
1275 $start_msg = $start_msg - $show_num;
1276 if ($start_msg < 1) {
1277 $start_msg = 1;
1278 }
1279 }
44369a30 1280 return (array($start_msg,$end_msg));
e9e5f0fa 1281}
1282
a3439b27 1283function handleAsSent($mailbox) {
e35045b7 1284 global $sent_folder, $draft_folder, $handleAsSent_result;
a3439b27 1285
e35045b7 1286 /* First check if this is the sent or draft folder. */
1287 $handleAsSent_result = (($mailbox == $sent_folder)
1288 || ($mailbox == $draft_folder));
1289
1290 /* Then check the result of the handleAsSent hook. */
1291 do_hook('check_handleAsSent_result', $mailbox);
a3439b27 1292
e35045b7 1293 /* And return the result. */
1294 return ($handleAsSent_result);
a3439b27 1295}
1296
a51dec54 1297?>