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