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