Code cleanup.
[squirrelmail.git] / functions / mailbox_display.php
CommitLineData
59177427 1<?php
2ba13803 2
35586184 3/**
4 * mailbox_display.php
5 *
82d304a0 6 * Copyright (c) 1999-2004 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$
d6c32258 13 * @package squirrelmail
35586184 14 */
a4c2cd49 15
d6c32258 16/** The standard includes.. */
b68edc75 17require_once(SM_PATH . 'functions/strings.php');
18require_once(SM_PATH . 'functions/html.php');
19require_once(SM_PATH . 'class/html.class.php');
20require_once(SM_PATH . 'functions/imap_mailbox.php');
26454147 21require_once(SM_PATH . 'functions/imap_messages.php');
22require_once(SM_PATH . 'functions/mime.php');
b531f8ea 23require_once(SM_PATH . 'functions/forms.php');
43fdb2a4 24
d6c32258 25/**
26 * default value for page_selector_max
6dc5eca4 27 */
6c930ade 28define('PG_SEL_MAX', 10);
29
d6c32258 30/**
31 * @param mixed $start UNDOCUMENTED
32 */
098ea084 33function elapsed($start)
34{
35 $end = microtime();
36 list($start2, $start1) = explode(" ", $start);
37 list($end2, $end1) = explode(" ", $end);
38 $diff1 = $end1 - $start1;
39 $diff2 = $end2 - $start2;
40 if( $diff2 < 0 ){
41 $diff1 -= 1;
42 $diff2 += 1.0;
43 }
44 return $diff2 + $diff1;
45}
46
c7df3f1b 47/**
48 * Displays message listing
49 *
50 * @param mixed $imapConnection
51 * @param mixed $t UNDOCUMENTED
52 * @param bool $not_last UNDOCUMENTED
53 * @param mixed $key UNDOCUMENTED
54 * @param string $mailbox mail folder
55 * @param mixed $start_msg UNDOCUMENTED
56 * @param mixed $where UNDOCUMENTED
57 * @param mixed $what UNDOCUMENTED
58 */
1c198ef7 59function printMessageInfo($imapConnection, $t, $last=false, $msg, $mailbox,
d215ca7d 60 $start_msg, $where, $what) {
8008456a 61 global $checkall,
1c198ef7 62 $color, $msgs, $msort, $td_str,
c1c17724 63 $default_use_priority,
64 $message_highlight_list,
65 $index_order,
459e3347 66 $indent_array, /* indent subject by */
67 $pos, /* Search postion (if any) */
c1c17724 68 $thread_sort_messages, /* thread sorting on/off */
459e3347 69 $server_sort_order, /* sort value when using server-sorting */
c1c17724 70 $row_count,
459e3347 71 $allow_server_sort, /* enable/disable server-side sorting */
53ad5f60 72 $truncate_sender, /* number of characters for From/To field (<= 0 for unchanged) */
1ae2832e 73 $email_address,
6395c46d 74 $show_recipient_instead, /* show recipient name instead of default identity */
75 $use_icons, /* indicates to use icons or text markers */
76 $icon_theme; /* icons theming */
459e3347 77
e9e5f0fa 78 $color_string = $color[4];
8008456a 79
80 if ($GLOBALS['alt_index_colors']) {
81 if (!isset($row_count)) {
82 $row_count = 0;
83 }
84 $row_count++;
85 if ($row_count % 2) {
86 if (!isset($color[12])) {
87 $color[12] = '#EAEAEA';
88 }
89 $color_string = $color[12];
90 }
bdfb67f8 91 }
8008456a 92
6a622b59 93 if($mailbox == 'None') {
94 $boxes = sqimap_mailbox_list($imapConnection);
8008456a 95 $mailbox = $boxes[0]['unformatted'];
6a622b59 96 unset($boxes);
bdfb67f8 97 }
8008456a 98 $urlMailbox = urlencode($mailbox);
e9e5f0fa 99
53ad5f60 100 $bSentFolder = handleAsSent($mailbox);
1ae2832e 101 if ((!$bSentFolder) && ($show_recipient_instead)) {
102 // If the From address is the same as $email_address, then handle as Sent
103 $from_array = parseAddress($msg['FROM'], 1);
104 if (!isset($email_address)) {
105 global $datadir, $username;
106 $email_address = getPref($datadir, $username, 'email_address');
107 }
108 $bHandleAsSent = ((isset($from_array[0][0])) && ($from_array[0][0] == $email_address));
098ea084 109 }
1ae2832e 110 else
111 $bHandleAsSent = $bSentFolder;
53ad5f60 112 // If this is a Sent message, display To address instead of From
4669e892 113 if ($bHandleAsSent)
53ad5f60 114 $msg['FROM'] = $msg['TO'];
115 // Passing 1 below results in only 1 address being parsed, thus defeating the following code
116 $msg['FROM'] = parseAddress($msg['FROM']/*,1*/);
9701e9c8 117
e9e5f0fa 118 /*
119 * This is done in case you're looking into Sent folders,
120 * because you can have multiple receivers.
121 */
098ea084 122 $senderNames = $msg['FROM'];
123 $senderName = '';
26454147 124 $senderAddress = '';
098ea084 125 if (sizeof($senderNames)){
126 foreach ($senderNames as $senderNames_part) {
e9e5f0fa 127 if ($senderName != '') {
128 $senderName .= ', ';
26454147 129 $senderAddress .= ', ';
e9e5f0fa 130 }
26454147 131 $sender_address_part = htmlspecialchars($senderNames_part[0]);
53ad5f60 132 $sender_name_part = str_replace('&nbsp;',' ', decodeHeader($senderNames_part[1]));
26454147 133 if ($sender_name_part) {
134 $senderName .= $sender_name_part;
135 $senderAddress .= $sender_name_part . ' <' . $sender_address_part . '>';
098ea084 136 } else {
26454147 137 $senderName .= $sender_address_part;
138 $senderAddress .= $sender_address_part;
098ea084 139 }
140 }
937c81fa 141 }
53ad5f60 142 // If Sent, prefix with To: but only if not Sent folder
143 if ($bHandleAsSent ^ $bSentFolder) {
144 $senderName = _("To:") . ' ' . $senderName;
145 $senderAddress = _("To:") . ' ' . $senderAddress;
146 }
459e3347 147
eaa4f45f 148 if ($truncate_sender > 0)
149 $senderName = truncateWithEntities($senderName, $truncate_sender);
459e3347 150
5786ef5a 151 echo html_tag( 'tr','','','','VALIGN="top"') . "\n";
8008456a 152
153 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
154 $flag = "<font color=\"$color[2]\">";
155 $flag_end = '</font>';
156 } else {
157 $flag = '';
158 $flag_end = '';
bdfb67f8 159 }
8008456a 160 if (!isset($msg['FLAG_SEEN']) || ($msg['FLAG_SEEN'] == false)) {
161 $bold = '<b>';
162 $bold_end = '</b>';
163 } else {
164 $bold = '';
165 $bold_end = '';
bdfb67f8 166 }
53ad5f60 167 if ($bHandleAsSent) {
8008456a 168 $italic = '<i>';
169 $italic_end = '</i>';
170 } else {
171 $italic = '';
172 $italic_end = '';
173 }
174 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
175 $fontstr = "<font color=\"$color[9]\">";
176 $fontstr_end = '</font>';
177 } else {
178 $fontstr = '';
179 $fontstr_end = '';
180 }
181
d215ca7d 182 if ($where && $what) {
183 $searchstr = '&amp;where='.$where.'&amp;what='.$what;
184 } else {
185 $searchstr = '';
6a622b59 186 }
9701e9c8 187
937c81fa 188 if (is_array($message_highlight_list) && count($message_highlight_list)) {
8415b2d3 189 $msg['TO'] = parseAddress($msg['TO']);
190 $msg['CC'] = parseAddress($msg['CC']);
8008456a 191 foreach ($message_highlight_list as $message_highlight_list_part) {
192 if (trim($message_highlight_list_part['value']) != '') {
c0d04f97 193 $high_val = strtolower($message_highlight_list_part['value']);
194 $match_type = strtoupper($message_highlight_list_part['match_type']);
8415b2d3 195 if($match_type == 'TO_CC') {
196 $match = array('TO', 'CC');
197 } else {
198 $match = array($match_type);
199 }
200 foreach($match as $match_type) {
201 switch($match_type) {
202 case('TO'):
203 case('CC'):
204 case('FROM'):
205 foreach ($msg[$match_type] as $address) {
9701e9c8 206 $address[0] = decodeHeader($address[0], true, false);
207 $address[1] = decodeHeader($address[1], true, false);
8415b2d3 208 if (strstr('^^' . strtolower($address[0]), $high_val) ||
209 strstr('^^' . strtolower($address[1]), $high_val)) {
210 $hlt_color = $message_highlight_list_part['color'];
211 break 4;
212 }
937c81fa 213 }
937c81fa 214 break;
8415b2d3 215 default:
9701e9c8 216 $headertest = strtolower(decodeHeader($msg[$match_type], true, false));
217 if (strstr('^^' . $headertest, $high_val)) {
937c81fa 218 $hlt_color = $message_highlight_list_part['color'];
4669e892 219 break 3;
937c81fa 220 }
8415b2d3 221 break;
222 }
8008456a 223 }
224 }
225 }
226 }
227
228 if (!isset($hlt_color)) {
229 $hlt_color = $color_string;
230 }
5e0efebf 231 $col = 0;
26454147 232 $msg['SUBJECT'] = str_replace('&nbsp;', ' ', decodeHeader($msg['SUBJECT']));
9701e9c8 233 $subject = processSubject($msg['SUBJECT'], $indent_array[$msg['ID']]);
6a622b59 234 if (sizeof($index_order)) {
8008456a 235 foreach ($index_order as $index_order_part) {
236 switch ($index_order_part) {
237 case 1: /* checkbox */
238 echo html_tag( 'td',
4669e892 239 addCheckBox("msg[$t]", $checkall, $msg['ID']),
6a622b59 240 'center',
8008456a 241 $hlt_color );
242 break;
243 case 2: /* from */
26454147 244 if ($senderAddress != $senderName) {
245 $senderAddress = strtr($senderAddress, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
246 $title = ' title="' . str_replace('"', "''", $senderAddress) . '"';
247 }
248 else
249 $title = '';
8008456a 250 echo html_tag( 'td',
098ea084 251 $italic . $bold . $flag . $fontstr . $senderName .
8008456a 252 $fontstr_end . $flag_end . $bold_end . $italic_end,
c1c17724 253 'left',
26454147 254 $hlt_color, $title );
8008456a 255 break;
256 case 3: /* date */
53d9fbc5 257 $date_string = $msg['DATE_STRING'] . '';
258 if ($date_string == '') {
259 $date_string = _("Unknown date");
260 }
8008456a 261 echo html_tag( 'td',
53d9fbc5 262 $bold . $flag . $fontstr . $date_string .
8008456a 263 $fontstr_end . $flag_end . $bold_end,
264 'center',
265 $hlt_color,
266 'nowrap' );
267 break;
268 case 4: /* subject */
269 $td_str = $bold;
270 if ($thread_sort_messages == 1) {
6903c7bd 271 if (isset($indent_array[$msg['ID']])) {
8008456a 272 $td_str .= str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;",$indent_array[$msg['ID']]);
273 }
274 }
e9e5f0fa 275 $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox
6a622b59 276 . '&amp;passed_id='. $msg["ID"]
277 . '&amp;startMessage='.$start_msg.$searchstr.'"';
158fa340 278 $td_str .= ' ' .concat_hook_function('subject_link', array($start_msg, $searchstr));
306b6393 279 if ($subject != $msg['SUBJECT']) {
8008456a 280 $title = get_html_translation_table(HTML_SPECIALCHARS);
281 $title = array_flip($title);
306b6393 282 $title = strtr($msg['SUBJECT'], $title);
8008456a 283 $title = str_replace('"', "''", $title);
284 $td_str .= " title=\"$title\"";
285 }
286 $td_str .= ">$flag$subject$flag_end</a>$bold_end";
c1c17724 287 echo html_tag( 'td', $td_str, 'left', $hlt_color );
8008456a 288 break;
289 case 5: /* flags */
6a622b59 290
6395c46d 291 // icon message markers
292 //
293 if ($use_icons && $icon_theme != 'none') {
294 $td_str = "<b><small>";
295 if (isset($msg['FLAG_FLAGGED']) && $msg['FLAG_FLAGGED'] == true) {
55103ede 296 $td_str .= '<img src="' . SM_PATH . 'images/themes/' . $icon_theme . '/flagged.png" border="0" height="10" width="10" /> ';
6395c46d 297 }
298 if ($default_use_priority) {
299 if ( ($msg['PRIORITY'] == 1) || ($msg['PRIORITY'] == 2) ) {
55103ede 300 $td_str .= '<img src="' . SM_PATH . 'images/themes/' . $icon_theme . '/prio_high.png" border="0" height="10" width="5" /> ';
6395c46d 301 }
302 else if ($msg['PRIORITY'] == 5) {
55103ede 303 $td_str .= '<img src="' . SM_PATH . 'images/themes/' . $icon_theme . '/prio_low.png" border="0" height="10" width="5" /> ';
6395c46d 304 }
305 else
306 {
55103ede 307 $td_str .= '<img src="' . SM_PATH . 'images/themes/' . $icon_theme . '/transparent.png" border="0" width="5" /> ';
6395c46d 308 }
309 }
310 if ($msg['TYPE0'] == 'multipart') {
55103ede 311 $td_str .= '<img src="' . SM_PATH . 'images/themes/' . $icon_theme . '/attach.png" border="0" height="10" width="6" />';
6395c46d 312 }
313 else
314 {
55103ede 315 $td_str .= '<img src="' . SM_PATH . 'images/themes/' . $icon_theme . '/transparent.png" border="0" width="6" />';
6395c46d 316 }
317
318 $msg_icon = '';
319 if (!isset($msg['FLAG_SEEN']) || ($msg['FLAG_SEEN']) == false)
320 {
321 $msg_alt = '(' . _("New") . ')';
322 $msg_title = '(' . _("New") . ')';
323 $msg_icon .= SM_PATH . 'images/themes/' . $icon_theme . '/msg_new';
324 }
325 else
326 {
327 $msg_alt = '(' . _("Read") . ')';
328 $msg_title = '(' . _("Read") . ')';
329 $msg_icon .= SM_PATH . 'images/themes/' . $icon_theme . '/msg_read';
330 }
331 if (isset($msg['FLAG_DELETED']) && ($msg['FLAG_DELETED']) == true)
332 {
333 $msg_icon .= '_deleted';
334 }
335 if (isset($msg['FLAG_ANSWERED']) && ($msg['FLAG_ANSWERED']) == true)
336 {
d3685401 337 $msg_alt = '(' . _("Answered") . ')';
338 $msg_title = '(' . _("Answered") . ')';
6395c46d 339 $msg_icon .= '_reply';
340 }
55103ede 341 $td_str .= '<img src="' . $msg_icon . '.png" border="0" alt="'. $msg_alt . '" title="' . $msg_title . '" height="12" width="18" />';
6395c46d 342 $td_str .= '</small></b>';
343 echo html_tag( 'td',
344 $td_str,
345 'right',
346 $hlt_color,
347 'nowrap' );
8008456a 348 }
6395c46d 349
350
351 // plain text message markers
352 //
353 else {
354 $stuff = false;
355 $td_str = "<b><small>";
356 if (isset($msg['FLAG_ANSWERED']) && $msg['FLAG_ANSWERED'] == true) {
357 $td_str .= _("A");
8008456a 358 $stuff = true;
359 }
6395c46d 360 if ($msg['TYPE0'] == 'multipart') {
361 $td_str .= '+';
8008456a 362 $stuff = true;
363 }
6395c46d 364 if ($default_use_priority) {
365 if ( ($msg['PRIORITY'] == 1) || ($msg['PRIORITY'] == 2) ) {
366 $td_str .= "<font color=\"$color[1]\">!</font>";
367 $stuff = true;
368 }
369 if ($msg['PRIORITY'] == 5) {
370 $td_str .= "<font color=\"$color[8]\">?</font>";
371 $stuff = true;
372 }
373 }
374 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'] == true) {
375 $td_str .= "<font color=\"$color[1]\">D</font>";
376 $stuff = true;
377 }
378 if (!$stuff) {
379 $td_str .= '&nbsp;';
380 }
381 $td_str .= '</small></b>';
382 echo html_tag( 'td',
383 $td_str,
384 'center',
385 $hlt_color,
386 'nowrap' );
8008456a 387 }
8008456a 388 break;
389 case 6: /* size */
8008456a 390 echo html_tag( 'td',
6a622b59 391 $bold . $fontstr . show_readable_size($msg['SIZE']) .
8008456a 392 $fontstr_end . $bold_end,
393 'right',
394 $hlt_color );
395 break;
396 }
ed230bc3 397 ++$col;
8008456a 398 }
bdfb67f8 399 }
1c198ef7 400 if ($last) {
401 echo '</tr>'."\n";
402 } else {
55103ede 403 echo '</tr>' . "\n" . '<tr><td colspan="' . $col . '" bgcolor="' .
404 $color[0] . '" height="1"></td></tr>' . "\n";
6a622b59 405 }
e9e5f0fa 406}
407
c7df3f1b 408/**
409 * FIXME: Undocumented function
410 *
411 * @param mixed $imapConnection
412 * @param mixed $start_msg
413 * @param mixed $show_num
414 * @param mixed $num_msgs
415 * @param mixed $id
416 * @return array
417 */
ed230bc3 418function getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id) {
419 if ($id != 'no') {
098ea084 420 $id = array_slice($id, ($start_msg-1), $show_num);
ed230bc3 421 $end = $start_msg + $show_num - 1;
422 if ($num_msgs < $show_num) {
423 $end_loop = $num_msgs;
424 } else if ($end > $num_msgs) {
425 $end_loop = $num_msgs - $start_msg + 1;
426 } else {
427 $end_loop = $show_num;
83cdc70b 428 }
429 return fillMessageArray($imapConnection,$id,$end_loop,$show_num);
ed230bc3 430 } else {
431 return false;
432 }
433}
434
c7df3f1b 435/**
436 * FIXME: Undocumented function
437 *
438 * @param mixed $imapConnection
439 * @param mixed $start_msg
440 * @param mixed $show_num
441 * @param mixed $num_msgs
442 * @return array
443 */
ed230bc3 444function getThreadMessages($imapConnection, $start_msg, $show_num, $num_msgs) {
445 $id = get_thread_sort($imapConnection);
446 return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
447}
448
c7df3f1b 449/**
450 * FIXME: Undocumented function
451 *
452 * @param mixed $imapConnection
453 * @param mixed $start_msg
454 * @param mixed $show_num
455 * @param mixed $num_msgs
456 * @param mixed $server_sort_order
457 * @param mixed $mbxresponse
458 * @return array
459 */
6a622b59 460function getServerSortMessages($imapConnection, $start_msg, $show_num,
ed230bc3 461 $num_msgs, $server_sort_order, $mbxresponse) {
26e90c74 462 if (isset($mbxresponse['SORT_ARRAY']) && is_array($mbxresponse['SORT_ARRAY'])) {
fe6efa94 463 $id = $mbxresponse['SORT_ARRAY'];
464 } else {
465 $id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse);
466 }
ed230bc3 467 return getServerMessages($imapConnection, $start_msg, $show_num, $num_msgs, $id);
e9e5f0fa 468}
469
c7df3f1b 470/**
471 * FIXME: Undocumented function
472 *
473 * @param mixed $imapConnection
474 * @param mixed $start_msg
475 * @param mixed $show_num
476 * @param mixed $num_msgs
477 * @param mixed $sort
478 * @param mixed $mbxresponse
479 * @return array
480 */
6a622b59 481function getSelfSortMessages($imapConnection, $start_msg, $show_num,
e9e5f0fa 482 $num_msgs, $sort, $mbxresponse) {
ed230bc3 483 $msgs = array();
484 if ($num_msgs >= 1) {
485 $id = sqimap_get_php_sort_order ($imapConnection, $mbxresponse);
486 if ($sort < 6 ) {
487 $end = $num_msgs;
488 $end_loop = $end;
7b73b809 489 /* set shownum to 999999 to fool sqimap_get_small_header_list
490 and rebuild the msgs_str to 1:* */
491 $show_num = 999999;
ed230bc3 492 } else {
493 /* if it's not sorted */
494 if ($start_msg + ($show_num - 1) < $num_msgs) {
495 $end_msg = $start_msg + ($show_num - 1);
496 } else {
497 $end_msg = $num_msgs;
498 }
499 if ($end_msg < $start_msg) {
500 $start_msg = $start_msg - $show_num;
501 if ($start_msg < 1) {
502 $start_msg = 1;
503 }
504 }
098ea084 505 $id = array_slice(array_reverse($id), ($start_msg-1), $show_num);
ed230bc3 506 $end = $start_msg + $show_num - 1;
507 if ($num_msgs < $show_num) {
508 $end_loop = $num_msgs;
509 } else if ($end > $num_msgs) {
510 $end_loop = $num_msgs - $start_msg + 1;
511 } else {
512 $end_loop = $show_num;
513 }
83cdc70b 514 }
515 $msgs = fillMessageArray($imapConnection,$id,$end_loop, $show_num);
e9e5f0fa 516 }
ed230bc3 517 return $msgs;
e9e5f0fa 518}
519
520
521
c7df3f1b 522/**
e35045b7 523 * This function loops through a group of messages in the mailbox
524 * and shows them to the user.
c7df3f1b 525 *
526 * @param mixed $imapConnection
527 * @param string $mailbox mail folder
528 * @param mixed $num_msgs
529 * @param mixed $start_msg
530 * @param mixed $sort
531 * @param mixed $color
532 * @param mixed $show_num
533 * @param mixed $use_cache
534 * @param mixed $mode
e35045b7 535 */
6a622b59 536function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
537 $start_msg, $sort, $color, $show_num,
fb75a74e 538 $use_cache, $mode='',$mbxresponse) {
fcba142a 539 global $msgs, $msort, $auto_expunge, $thread_sort_messages,
d741b4ec 540 $allow_server_sort, $server_sort_order;
1c198ef7 541 /* if there's no messages in this folder */
542 if ($mbxresponse['EXISTS'] == 0) {
543 $string = '<b>' . _("THIS FOLDER IS EMPTY") . '</b>';
544 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
545 echo ' <tr><td>';
546 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
547 echo ' <tr><td><br />';
548 echo ' <table cellpadding="1" cellspacing="5" align="center" border="0">';
549 echo ' <tr>' . html_tag( 'td', $string."\n", 'left')
550 . '</tr>';
551 echo ' </table>';
552 echo ' <br /></td></tr>';
553 echo ' </table></td></tr>';
554 echo ' </table>';
555 return;
556 }
557
558
6a622b59 559
167d7428 560 /*
561 * For some reason, on PHP 4.3+, this being unset, and set in the session causes havoc
562 * so setting it to an empty array beforehand seems to clean up the issue, and stopping the
563 * "Your script possibly relies on a session side-effect which existed until PHP 4.2.3" error
564 */
565
566 if (!isset($msort)) {
567 $msort = array();
568 }
569
49ae9d34 570 if (!isset($msgs)) {
571 $msgs = array();
572 }
573
8415b2d3 574 //$start = microtime();
6a622b59 575 /* If autoexpunge is turned on, then do it now. */
fb75a74e 576 //$mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox);
6a622b59 577 $srt = $sort;
578 /* If autoexpunge is turned on, then do it now. */
fb75a74e 579 //if ($auto_expunge == true) {
580 // $exp_cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, false, '');
581 // $mbxresponse['EXISTS'] = $mbxresponse['EXISTS'] - $exp_cnt;
582 // $num_msgs = $mbxresponse['EXISTS'];
583 //}
e35045b7 584
6a622b59 585 if ($mbxresponse['EXISTS'] > 0) {
586 /* if $start_msg is lower than $num_msgs, we probably deleted all messages
587 * in the last page. We need to re-adjust the start_msg
588 */
aa0da530 589
6a622b59 590 if($start_msg > $num_msgs) {
591 $start_msg -= $show_num;
592 if($start_msg < 1) {
593 $start_msg = 1;
594 }
e9e5f0fa 595 }
4e9f35e4 596
6a622b59 597 /* This code and the next if() block check for
598 * server-side sorting methods. The $id array is
599 * formatted and $sort is set to 6 to disable
600 * SM internal sorting
601 */
602
603 if ($thread_sort_messages == 1) {
604 $mode = 'thread';
d741b4ec 605 } elseif ($allow_server_sort == 1) {
6a622b59 606 $mode = 'serversort';
607 } else {
608 $mode = '';
609 }
8008456a 610
7b73b809 611 if ($use_cache) {
612 sqgetGlobalVar('msgs', $msgs, SQ_SESSION);
613 sqgetGlobalVar('msort', $msort, SQ_SESSION);
614 } else {
615 sqsession_unregister('msort');
d3714d3a 616 sqsession_unregister('msgs'); }
6a622b59 617 switch ($mode) {
618 case 'thread':
94a4ea53 619 $msgs = getThreadMessages($imapConnection, $start_msg, $show_num, $num_msgs);
6a622b59 620 if ($msgs === false) {
621 echo '<b><small><center><font color=red>' .
74091b64 622 _("Thread sorting is not supported by your IMAP server.") . '<br />' .
c7df3f1b 623 _("Please report this to the system administrator.").
6a622b59 624 '</center></small></b>';
625 $thread_sort_messages = 0;
626 $msort = $msgs = array();
6a622b59 627 } else {
6a622b59 628 $sort = 6;
1c198ef7 629 $msort = calc_msort($msgs, $sort);
6a622b59 630 }
631 break;
632 case 'serversort':
94a4ea53 633 $msgs = getServerSortMessages($imapConnection, $start_msg, $show_num,
634 $num_msgs, $sort, $mbxresponse);
6a622b59 635 if ($msgs === false) {
636 echo '<b><small><center><font color=red>' .
74091b64 637 _( "Server-side sorting is not supported by your IMAP server.") . '<br />' .
c7df3f1b 638 _("Please report this to the system administrator.").
6a622b59 639 '</center></small></b>';
640 $sort = $server_sort_order;
641 $allow_server_sort = FALSE;
642 $msort = $msgs = array();
6a622b59 643 $id = array();
644 } else {
ed230bc3 645 $sort = 6;
1c198ef7 646 $msort = calc_msort($msgs, $sort);
6a622b59 647 }
648 break;
649 default:
1c198ef7 650 $msgs = getSelfSortMessages($imapConnection, $start_msg, $show_num,
651 $num_msgs, $sort, $mbxresponse);
652 $msort = calc_msort($msgs, $sort);
6a622b59 653 break;
654 } // switch
ed230bc3 655 sqsession_register($msort, 'msort');
656 sqsession_register($msgs, 'msgs');
7b73b809 657
6a622b59 658 } /* if exists > 0 */
659
660 $res = getEndMessage($start_msg, $show_num, $num_msgs);
661 $start_msg = $res[0];
662 $end_msg = $res[1];
663
664 $paginator_str = get_paginator_str($mailbox, $start_msg, $end_msg,
665 $num_msgs, $show_num, $sort);
666
667 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
668
669 do_hook('mailbox_index_before');
abafb676 670?>
671<table border="0" width="100%" cellpadding="0" cellspacing="0">
672 <tr>
673 <td>
4669e892 674 <?php mail_message_listing_beginning($imapConnection, $mbxresponse, $mailbox, $sort,
abafb676 675 $msg_cnt_str, $paginator_str, $start_msg); ?>
676 </td>
677 </tr>
c7df3f1b 678 <tr><td height="5" bgcolor="<?php echo $color[4]; ?>"></td></tr>
abafb676 679 <tr>
680 <td>
681 <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="<?php echo $color[9]; ?>">
682 <tr>
683 <td>
684 <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="<?php echo $color[5]; ?>">
685 <tr>
686 <td>
4669e892 687 <?php
94a4ea53 688 printHeader($mailbox, $srt, $color, !$thread_sort_messages, $start_msg);
4669e892 689 displayMessageArray($imapConnection, $num_msgs, $start_msg,
abafb676 690 $msort, $mailbox, $sort, $color, $show_num,0,0);
691 ?>
692 </td>
693 </tr>
694 </table>
695 </td>
696 </tr>
697 </table>
698 <?php
4669e892 699 mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color);
abafb676 700 ?>
701 </td>
702 </tr>
703</table>
704<?php
8415b2d3 705 //$t = elapsed($start);
46a49f65 706 //echo("elapsed time = $t seconds\n");
6c930ade 707}
bdfb67f8 708
c7df3f1b 709/**
710 * FIXME: Undocumented function
711 *
712 * @param array $messages
713 * @param integer $sort sorting order
714 * @return array
715 */
e9e5f0fa 716function calc_msort($msgs, $sort) {
e35045b7 717 /*
718 * 0 = Date (up)
719 * 1 = Date (dn)
720 * 2 = Name (up)
721 * 3 = Name (dn)
722 * 4 = Subject (up)
723 * 5 = Subject (dn)
724 */
625c8b78 725
6a622b59 726 if (($sort == 0) || ($sort == 1)) {
625c8b78 727 foreach ($msgs as $item) {
1c198ef7 728 $msort[$item['ID']] = $item['TIME_STAMP'];
625c8b78 729 }
6a622b59 730 } elseif (($sort == 2) || ($sort == 3)) {
625c8b78 731 foreach ($msgs as $item) {
1c198ef7 732 $msort[$item['ID']] = $item['FROM-SORT'];
625c8b78 733 }
6a622b59 734 } elseif (($sort == 4) || ($sort == 5)) {
625c8b78 735 foreach ($msgs as $item) {
1c198ef7 736 //echo $item['SUBJECT-SORT'] . "<br />";
737 $msort[$item['ID']] = $item['SUBJECT-SORT'];
625c8b78 738 }
6a622b59 739 } else {
1c198ef7 740 return array_keys($msgs); //array_walk($msort, create_function('&$v,$k', '$v = $v["ID"];'));
6a622b59 741 }
742 if ($sort < 6) {
743 if ($sort % 2) {
744 asort($msort);
745 } else {
746 arsort($msort);
747 }
1c198ef7 748 $msort = array_keys($msort);
6a622b59 749 }
750 return $msort;
751}
752
c7df3f1b 753/**
754 * FIXME: Undocumented function
755 *
756 * @param mixed $imapConnection
757 * @param mixed $id
758 * @param mixed $count
759 * @param bool $show_num
760 */
fc60dc76 761function fillMessageArray($imapConnection, $id, $count, $show_num=false) {
a18594b2 762 return sqimap_get_small_header_list($imapConnection, $id, $show_num);
e35045b7 763}
8008456a 764
e9e5f0fa 765
c7df3f1b 766/**
767 * Generic function to convert the msgs array into an HTML table.
768 *
1c198ef7 769 * @param resource $imapConnection
770 * @param int $num_msgs total number of messages in the mailbox
771 * @param int $start_msg offset in messages to sisplay
772 * @param array $msort sorted array which is used to map the index to the unsorted $msgs index
c7df3f1b 773 * @param string $mailbox mail folder name
1c198ef7 774 * @param int $sort sort order. 6 means no sorting or server side / thread sort
775 * @param array $color
776 * @param int $show_num number of messages to show
c7df3f1b 777 * @param mixed $where
778 * @param mixed $what
779 */
6a622b59 780function displayMessageArray($imapConnection, $num_msgs, $start_msg,
781 $msort, $mailbox, $sort, $color,
782 $show_num, $where=0, $what=0) {
59352d08 783 global $imapServerAddress, $use_mailbox_cache, $index_order,
6a622b59 784 $indent_array, $thread_sort_messages, $allow_server_sort,
1c198ef7 785 $server_sort_order, $PHP_SELF, $msgs;
6a622b59 786
a966982b 787
6a622b59 788 $urlMailbox = urlencode($mailbox);
e9e5f0fa 789
6a622b59 790 /* get indent level for subject display */
1c198ef7 791
792 // FIX ME this call is at the wrong place
540c4435 793 if ($thread_sort_messages == 1 && $num_msgs) {
6a622b59 794 $indent_array = get_parent_level($imapConnection);
94ac35c6 795 }
a966982b 796
1c198ef7 797 /* messages display */
798
799 // if client side sorting and no sort we only fetch num_msgs so the start_msg in the $msgs
800 // array must be corrected
6a622b59 801 if ($sort == 6) {
1c198ef7 802 $i = 0;
803 } else {
804 $i = $start_msg -1;
6a622b59 805 }
6a622b59 806
807 /*
808 * Loop through and display the info for each message.
809 * ($t is used for the checkbox number)
810 */
1c198ef7 811 $iEnd = $i +$show_num;
812 for ($j=$i,$t=0;$j<$iEnd;++$j) {
813 if (isset($msort[$j])) {
814 $msg = $msgs[$msort[$j]];
815 $last = (isset($msort[$j+1]) || $j == $iEnd) ? false : true;
816 printMessageInfo($imapConnection, $t, $last, $msg, $mailbox,
817 $start_msg, $where, $what);
818 $t++;
6a622b59 819 } else {
1c198ef7 820 break;
6a622b59 821 }
94ac35c6 822 }
bdfb67f8 823}
824
c7df3f1b 825/**
826 * Displays the standard message list header.
827 *
828 * To finish the table, you need to do a "</table></table>";
e35045b7 829 *
c7df3f1b 830 * @param mixed $imapConnection
4669e892 831 * @param array $mbxresponse the array with the results of SELECT against the current mailbox
c7df3f1b 832 * @param string $mailbox the current mailbox
833 * @param mixed $sort the current sorting method (-1 for no sorting available [searches])
834 * @param mixed $msg_cnt_str
835 * @param mixed $paginator
836 * @param mixed $start_msg
e35045b7 837 */
6a622b59 838function mail_message_listing_beginning ($imapConnection,
fd181f53 839 $mbxresponse,
6a622b59 840 $mailbox = '', $sort = -1,
841 $msg_cnt_str = '',
842 $paginator = '&nbsp;',
843 $start_msg = 1) {
fd181f53 844 global $color, $auto_expunge, $base_uri, $show_flag_buttons,
abafb676 845 $allow_server_sort, $server_sort_order,
da291e62 846 $PHP_SELF, $allow_thread_sort, $thread_sort_messages;
6a622b59 847
848 $php_self = $PHP_SELF;
849 /* fix for incorrect $PHP_SELF */
850 if (strpos($php_self, 'move_messages.php')) {
851 $php_self = str_replace('move_messages.php', 'right_main.php', $php_self);
852 }
853 $urlMailbox = urlencode($mailbox);
e35045b7 854
6a622b59 855 if (preg_match('/^(.+)\?.+$/',$php_self,$regs)) {
856 $source_url = $regs[1];
857 } else {
858 $source_url = $php_self;
859 }
860
861 if (!isset($msg)) {
862 $msg = '';
863 }
abafb676 864
865 if (!strpos($php_self,'?')) {
866 $location = $php_self.'?mailbox=INBOX&amp;startMessage=1';
867 } else {
868 $location = $php_self;
869 }
870
b531f8ea 871 $moveFields = addHidden('msg', $msg).
872 addHidden('mailbox', $mailbox).
873 addHidden('startMessage', $start_msg).
874 addHidden('location', $location);
8fe969f6 875
5e0539cd 876 /* build thread sorting links */
877 if ($allow_thread_sort == TRUE) {
878 if ($thread_sort_messages == 1 ) {
879 $set_thread = 2;
880 $thread_name = _("Unthread View");
881 } elseif ($thread_sort_messages == 0) {
882 $set_thread = 1;
883 $thread_name = _("Thread View");
884 }
d8a255fe 885 $thread_link_str = '<small>[<a href="' . $source_url . '?sort='
5e0539cd 886 . $sort . '&start_messages=1&set_thread=' . $set_thread
887 . '&mailbox=' . urlencode($mailbox) . '">' . $thread_name
888 . '</a>]</small>';
889 }
890 else
891 $thread_link_str ='';
892
6a622b59 893 /*
894 * This is the beginning of the message list table.
895 * It wraps around all messages
896 */
3027826a 897 $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox);
898 $form_name = "FormMsgs" . $safe_name;
3da12e67 899
3027826a 900 echo '<form name="' . $form_name . '" method="post" action="move_messages.php">' ."\n"
abafb676 901 . $moveFields;
902?>
903 <table width="100%" cellpadding="1" cellspacing="0" style="border: 1px solid <?php echo $color[0]; ?>">
904 <tr>
905 <td>
906 <table bgcolor="<?php echo $color[4]; ?>" border="0" width="100%" cellpadding="1" cellspacing="0">
907 <tr>
74091b64 908 <td align="left"><small><?php echo $paginator . $thread_link_str; ?></small></td>
d8a255fe 909 <td align="center"></td>
abafb676 910 <td align="right"><small><?php echo $msg_cnt_str; ?></small></td>
911 </tr>
912 </table>
913 </td>
914 </tr>
915 <tr width="100%" cellpadding="1" cellspacing="0" border="0" bgcolor="<?php echo $color[0]; ?>">
916 <td>
917 <table border="0" width="100%" cellpadding="1" cellspacing="0">
918 <tr>
919 <td align="left">
920 <small><?php
4669e892 921
fd181f53 922 // display flag buttons only if supported
4669e892 923 if ($show_flag_buttons && $mbxresponse != NULL &&
924 array_search('\\flagged',$mbxresponse['PERMANENTFLAGS'], true) !== FALSE) {
1a531551 925 echo getButton('SUBMIT', 'markUnflagged',_("Unflag"));
fd181f53 926 echo getButton('SUBMIT', 'markFlagged',_("Flag"));
927 echo '&nbsp;';
fd181f53 928 }
4669e892 929 if (array_search('\\seen',$mbxresponse['PERMANENTFLAGS'], true) !== FALSE) {
930 echo getButton('SUBMIT', 'markUnread',_("Unread"));
931 echo getButton('SUBMIT', 'markRead',_("Read"));
932 echo '&nbsp;';
933 }
98a9cc03 934
abafb676 935 echo getButton('SUBMIT', 'attache',_("Forward"));
936 echo '&nbsp;';
4669e892 937 if (array_search('\\deleted',$mbxresponse['PERMANENTFLAGS'], true) !== FALSE) {
938 echo getButton('SUBMIT', 'delete',_("Delete"));
939 echo '<input type="checkbox" name="bypass_trash" />' . _("Bypass Trash");
940 echo '&nbsp;';
941 }
942 if (!$auto_expunge && $mbxresponse['RIGHTS'] != 'READ-ONLY') {
abafb676 943 echo getButton('SUBMIT', 'expungeButton',_("Expunge")) .'&nbsp;' . _("mailbox") . "\n";
944 echo '&nbsp;';
945 }
946 do_hook('mailbox_display_buttons');
947 ?></small>
948 </td>
4669e892 949 <?php
950 if (array_search('\\deleted',$mbxresponse['PERMANENTFLAGS'], true) !== FALSE) {
951 echo '<td align="right">
952 <small>';
5e0539cd 953 //echo $thread_link_str; //previous behaviour
4669e892 954 getMbxList($imapConnection);
955 echo getButton('SUBMIT', 'moveButton',_("Move")) . "\n
956 </small>";
957 }
958 ?>
abafb676 959 </td>
960 </tr>
961 </table>
4669e892 962 </td>
abafb676 963 </tr>
964 </table>
a966982b 965
abafb676 966<?php
1b91be0c 967 do_hook('mailbox_form_before');
6c766fd5 968
8008456a 969 /* if using server sort we highjack the
6a622b59 970 * the $sort var and use $server_sort_order
971 * instead. but here we reset sort for a bit
972 * since its easy
973 */
8008456a 974 if ($allow_server_sort == TRUE) {
975 $sort = $server_sort_order;
976 }
e9e5f0fa 977}
a966982b 978
c7df3f1b 979/**
980 * FIXME: Undocumented function
981 *
982 * @param mixed $num_msgs
983 * @param mixed $paginator_str
984 * @param mixed $msg_cnt_str
985 * @param mixed $color
986 */
e9e5f0fa 987function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str, $color) {
22642690 988 if ($num_msgs) {
4b920601 989 /* space between list and footer */
abafb676 990?>
c7df3f1b 991 <tr><td height="5" bgcolor="<?php echo $color[4]; ?>" colspan="1"></td></tr>
4669e892 992 <tr>
abafb676 993 <td>
994 <table width="100%" cellpadding="1" cellspacing="0" style="border: 1px solid <?php echo $color[0]; ?>">
995 <tr>
996 <td>
997 <table bgcolor="<?php echo $color[4]; ?>" border="0" width="100%" cellpadding="1" cellspacing="0">
998 <tr>
999 <td align="left"><small><?php echo $paginator_str; ?></small></td>
1000 <td align="right"><small><?php echo $msg_cnt_str; ?></small></td>
1001 </tr>
1002 </table>
1003 </td>
1004 </tr>
1005 </table>
1006 </td>
1007 </tr>
1008<?php
22642690 1009 }
6a622b59 1010 /* End of message-list table */
a966982b 1011
6a622b59 1012 do_hook('mailbox_index_after');
c7df3f1b 1013 echo "</form>\n";
a966982b 1014}
1015
c7df3f1b 1016/**
1017 * FIXME: Undocumented function
1018 *
1019 * @param string $mailbox
1020 * @param mixed $sort
1021 * @param mixed $color
1022 * @param bool $showsort
1023 * @param mixed $start_msg
1024 */
97006a72 1025function printHeader($mailbox, $sort, $color, $showsort=true, $start_msg=1) {
6a622b59 1026 global $index_order;
1b91be0c 1027 echo html_tag( 'tr' ,'' , 'center', $color[5] );
e4b5f9d1 1028
1029 /* calculate the width of the subject column based on the
1030 * widths of the other columns */
1031 $widths = array(1=>1,2=>25,3=>5,4=>0,5=>1,6=>5);
1032 $subjectwidth = 100;
1033 foreach($index_order as $item) {
4669e892 1034 $subjectwidth -= $widths[$item];
e4b5f9d1 1035 }
1036
1037 foreach ($index_order as $item) {
1038 switch ($item) {
8008456a 1039 case 1: /* checkbox */
3da12e67 1040 echo html_tag( 'td',get_selectall_link($start_msg, $sort, $mailbox) , '', '', 'width="1%"' );
abafb676 1041 break;
8008456a 1042 case 5: /* flags */
abafb676 1043 echo html_tag( 'td','' , '', '', 'width="1%"' );
8008456a 1044 break;
1045 case 2: /* from */
1046 if (handleAsSent($mailbox)) {
1b91be0c 1047 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
6a622b59 1048 . '<b>' . _("To") . '</b>';
8008456a 1049 } else {
1b91be0c 1050 echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
6a622b59 1051 . '<b>' . _("From") . '</b>';
8008456a 1052 }
a966982b 1053 if ($showsort) {
1b91be0c 1054 ShowSortButton($sort, $mailbox, 2, 3);
8008456a 1055 }
1b91be0c 1056 echo "</td>\n";
8008456a 1057 break;
1058 case 3: /* date */
1b91be0c 1059 echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
6a622b59 1060 . '<b>' . _("Date") . '</b>';
a966982b 1061 if ($showsort) {
1b91be0c 1062 ShowSortButton($sort, $mailbox, 0, 1);
8008456a 1063 }
1b91be0c 1064 echo "</td>\n";
8008456a 1065 break;
a966982b 1066 case 4: /* subject */
e4b5f9d1 1067 echo html_tag( 'td' ,'' , 'left', '', 'width="'.$subjectwidth.'%"' )
6a622b59 1068 . '<b>' . _("Subject") . '</b>';
a966982b 1069 if ($showsort) {
1b91be0c 1070 ShowSortButton($sort, $mailbox, 4, 5);
8008456a 1071 }
1b91be0c 1072 echo "</td>\n";
8008456a 1073 break;
1074 case 6: /* size */
e842b215 1075 echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%" nowrap' );
8008456a 1076 break;
1077 }
bdfb67f8 1078 }
1b91be0c 1079 echo "</tr>\n";
bdfb67f8 1080}
1081
e9e5f0fa 1082
c7df3f1b 1083/**
e35045b7 1084 * This function shows the sort button. Isn't this a good comment?
c7df3f1b 1085 *
1086 * @param mixed $sort
1087 * @param string $mailbox
1088 * @param mixed $Down
1089 * @param mixed $Up
e35045b7 1090 */
94a4ea53 1091function ShowSortButton($sort, $mailbox, $Down, $Up ) {
6a622b59 1092 global $PHP_SELF;
94a4ea53 1093
6a622b59 1094 /* Figure out which image we want to use. */
1095 if ($sort != $Up && $sort != $Down) {
1096 $img = 'sort_none.png';
1097 $which = $Up;
1098 } elseif ($sort == $Up) {
1099 $img = 'up_pointer.png';
1100 $which = $Down;
6c930ade 1101 } else {
6a622b59 1102 $img = 'down_pointer.png';
1103 $which = 6;
e35045b7 1104 }
6a622b59 1105
1106 if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
1107 $source_url = $regs[1];
e35045b7 1108 } else {
6a622b59 1109 $source_url = $PHP_SELF;
6c930ade 1110 }
6a622b59 1111
1112 /* Now that we have everything figured out, show the actual button. */
1113 echo ' <a href="' . $source_url .'?newsort=' . $which
1114 . '&amp;startMessage=1&amp;mailbox=' . urlencode($mailbox)
da9a8410 1115 . '"><img src="../images/' . $img
1116 . '" border="0" width="12" height="10" alt="sort" title="'
74091b64 1117 . _("Click here to change the sorting of the message list") .' /"></a>';
6a622b59 1118}
1119
c7df3f1b 1120/**
1121 * FIXME: Undocumented function
1122 *
1123 * @param mixed $start_msg
1124 * @param mixed $sort
1125 * @param string $mailbox
1126 */
3da12e67 1127function get_selectall_link($start_msg, $sort, $mailbox) {
1128 global $checkall, $what, $where, $javascript_on;
6a622b59 1129 global $PHP_SELF, $PG_SHOWNUM;
1130
1131 $result = '';
1132 if ($javascript_on) {
3027826a 1133 $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $mailbox);
1134 $func_name = "CheckAll" . $safe_name;
1135 $form_name = "FormMsgs" . $safe_name;
6a622b59 1136 $result = '<script language="JavaScript" type="text/javascript">'
1137 . "\n<!-- \n"
3027826a 1138 . "function " . $func_name . "() {\n"
1139 . " for (var i = 0; i < document." . $form_name . ".elements.length; i++) {\n"
3962deff 1140 . " if(document." . $form_name . ".elements[i].type == 'checkbox' && "
e0b57c62 1141 . " document." . $form_name . ".elements[i].name.substring(0,3) == 'msg'){\n"
3027826a 1142 . " document." . $form_name . ".elements[i].checked = "
1143 . " !(document." . $form_name . ".elements[i].checked);\n"
6a622b59 1144 . " }\n"
1145 . " }\n"
1146 . "}\n"
1147 . "//-->\n"
abafb676 1148 . '</script>'
c7df3f1b 1149 . '<input type="checkbox" name="toggleAll" title="'._("Toggle All").'" onclick="'.$func_name.'();" />';
abafb676 1150// . <a href="javascript:void(0)" onClick="' . $func_name . '();">' . _("Toggle All")
1151// . "</a>\n";
e35045b7 1152 } else {
6a622b59 1153 if (strpos($PHP_SELF, "?")) {
1154 $result .= "<a href=\"$PHP_SELF&amp;mailbox=" . urlencode($mailbox)
1155 . "&amp;startMessage=$start_msg&amp;sort=$sort&amp;checkall=";
1156 } else {
1157 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
1158 . "&amp;startMessage=$start_msg&amp;sort=$sort&amp;checkall=";
1159 }
1160 if (isset($checkall) && $checkall == '1') {
1161 $result .= '0';
1162 } else {
1163 $result .= '1';
1164 }
1165
1166 if (isset($where) && isset($what)) {
1167 $result .= '&amp;where=' . urlencode($where)
1168 . '&amp;what=' . urlencode($what);
1169 }
1170 $result .= "\">";
98a9cc03 1171 $result .= _("All");
c7df3f1b 1172 $result .= "</a>\n";
e35045b7 1173 }
23d6bd09 1174
6a622b59 1175 /* Return our final result. */
1176 return ($result);
bdfb67f8 1177}
1a0e0983 1178
c7df3f1b 1179/**
e35045b7 1180 * This function computes the "Viewing Messages..." string.
c7df3f1b 1181 *
1182 * @param integer $start_msg first message number
1183 * @param integer $end_msg last message number
1184 * @param integer $num_msgs total number of message in folder
1185 * @return string
e35045b7 1186 */
bdfb67f8 1187function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
6a622b59 1188 /* Compute the $msg_cnt_str. */
1189 $result = '';
1190 if ($start_msg < $end_msg) {
c7df3f1b 1191 $result = sprintf(_("Viewing Messages: %s to %s (%s total)"),
1192 '<b>'.$start_msg.'</b>', '<b>'.$end_msg.'</b>', $num_msgs);
6a622b59 1193 } else if ($start_msg == $end_msg) {
c7df3f1b 1194 $result = sprintf(_("Viewing Message: %s (1 total)"), '<b>'.$start_msg.'</b>');
6a622b59 1195 } else {
c7df3f1b 1196 $result = '<br />';
6a622b59 1197 }
1198 /* Return our result string. */
1199 return ($result);
bdfb67f8 1200}
1201
c7df3f1b 1202/**
e35045b7 1203 * Generate a paginator link.
c7df3f1b 1204 *
1205 * @param mixed $box
1206 * @param mixed $start_msg
1207 * @param mixed $use
1208 * @param string $text text used for paginator link
1209 * @return string
e35045b7 1210 */
6c930ade 1211function get_paginator_link($box, $start_msg, $use, $text) {
e35045b7 1212
c7df3f1b 1213 $result = "<a href=\"right_main.php?use_mailbox_cache=$use"
6a622b59 1214 . "&amp;startMessage=$start_msg&amp;mailbox=$box\" "
c7df3f1b 1215 . ">$text</a>";
6a622b59 1216
6a622b59 1217 return ($result);
7b294953 1218}
1219
c7df3f1b 1220/**
e35045b7 1221 * This function computes the paginator string.
c7df3f1b 1222 *
1223 * @param mixed $box
1224 * @param mixed $start_msg
1225 * @param mixed $end_msg
1226 * @param integer $num_msgs
1227 * @param mixed $show_num
1228 * @param mixed $sort
e35045b7 1229 */
6a622b59 1230function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
1231 $show_num, $sort) {
dcc1cc82 1232 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
6a622b59 1233
1234 /* Initialize paginator string chunks. */
1235 $prv_str = '';
1236 $nxt_str = '';
eac26493 1237 $pg_str = '';
6a622b59 1238 $all_str = '';
6a622b59 1239
1240 $box = urlencode($box);
1241
1242 /* Create simple strings that will be creating the paginator. */
1243 $spc = '&nbsp;'; /* This will be used as a space. */
1244 $sep = '|'; /* This will be used as a seperator. */
1245
1246 /* Get some paginator preference values. */
1247 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON);
1248 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX);
1249
1250 /* Make sure that our start message number is not too big. */
1251 $start_msg = min($start_msg, $num_msgs);
1252
1253 /* Decide whether or not we will use the mailbox cache. */
1254 /* Not sure why $use_mailbox_cache is even passed in. */
1255 if ($sort == 6) {
1256 $use = 0;
1257 } else {
1258 $use = 1;
1259 }
1260
1261 /* Compute the starting message of the previous and next page group. */
1262 $next_grp = $start_msg + $show_num;
1263 $prev_grp = $start_msg - $show_num;
1264
1265 /* Compute the basic previous and next strings. */
1266 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
1267 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
1268 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1269 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
1270 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
abafb676 1271 $nxt_str = _("Next");
6a622b59 1272 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
abafb676 1273 $prv_str = _("Previous");
6a622b59 1274 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
1275 }
1276
1277 /* Page selector block. Following code computes page links. */
1278 if ($pg_sel && ($num_msgs > $show_num)) {
1279 /* Most importantly, what is the current page!!! */
1280 $cur_pg = intval($start_msg / $show_num) + 1;
1281
1282 /* Compute total # of pages and # of paginator page links. */
1283 $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
1284 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
1285
1286 /* Compute the size of the four quarters of the page links. */
1287
1288 /* If we can, just show all the pages. */
1289 if (($tot_pgs - 1) <= $pg_max) {
1290 $q1_pgs = $cur_pg - 1;
1291 $q2_pgs = $q3_pgs = 0;
1292 $q4_pgs = $tot_pgs - $cur_pg;
1293
e35045b7 1294 /* Otherwise, compute some magic to choose the four quarters. */
6a622b59 1295 } else {
1296 /*
1297 * Compute the magic base values. Added together,
1298 * these values will always equal to the $pag_pgs.
1299 * NOTE: These are DEFAULT values and do not take
1300 * the current page into account. That is below.
1301 */
1302 $q1_pgs = floor($vis_pgs/4);
1303 $q2_pgs = round($vis_pgs/4, 0);
1304 $q3_pgs = ceil($vis_pgs/4);
1305 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
1306
1307 /* Adjust if the first quarter contains the current page. */
1308 if (($cur_pg - $q1_pgs) < 1) {
1309 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) + $q2_pgs;
1310 $q1_pgs = $cur_pg - 1;
1311 $q2_pgs = 0;
1312 $q3_pgs += ceil($extra_pgs / 2);
1313 $q4_pgs += floor($extra_pgs / 2);
1314
1315 /* Adjust if the first and second quarters intersect. */
1316 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
1317 $extra_pgs = $q2_pgs;
176204a5 1318 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 3/4);
1319 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 3/4);
6a622b59 1320 $q3_pgs += ceil($extra_pgs / 2);
1321 $q4_pgs += floor($extra_pgs / 2);
1322
1323 /* Adjust if the fourth quarter contains the current page. */
1324 } else if (($cur_pg + $q4_pgs) >= $tot_pgs) {
1325 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) + $q3_pgs;
1326 $q3_pgs = 0;
1327 $q4_pgs = $tot_pgs - $cur_pg;
1328 $q1_pgs += floor($extra_pgs / 2);
1329 $q2_pgs += ceil($extra_pgs / 2);
1330
1331 /* Adjust if the third and fourth quarter intersect. */
1332 } else if (($cur_pg + $q3_pgs + 1) >= ($tot_pgs - $q4_pgs + 1)) {
1333 $extra_pgs = $q3_pgs;
176204a5 1334 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 3/4);
1335 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 3/4);
6a622b59 1336 $q1_pgs += floor($extra_pgs / 2);
1337 $q2_pgs += ceil($extra_pgs / 2);
1338 }
1339 }
e35045b7 1340
6a622b59 1341 /*
1342 * I am leaving this debug code here, commented out, because
1343 * it is a really nice way to see what the above code is doing.
1344 * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
74091b64 1345 * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br />';
6a622b59 1346 */
1347
1348 /* Print out the page links from the compute page quarters. */
1349
1350 /* Start with the first quarter. */
1351 if (($q1_pgs == 0) && ($cur_pg > 1)) {
1352 $pg_str .= "...$spc";
1353 } else {
1354 for ($pg = 1; $pg <= $q1_pgs; ++$pg) {
1355 $start = (($pg-1) * $show_num) + 1;
1356 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1357 }
1358 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
1359 $pg_str .= "...$spc";
1360 }
1361 }
1362
1363 /* Continue with the second quarter. */
1364 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++$pg) {
1365 $start = (($pg-1) * $show_num) + 1;
1366 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1367 }
1368
1369 /* Now print the current page. */
1370 $pg_str .= $cur_pg . $spc;
1371
1372 /* Next comes the third quarter. */
1373 for ($pg = $cur_pg + 1; $pg <= $cur_pg + $q3_pgs; ++$pg) {
1374 $start = (($pg-1) * $show_num) + 1;
1375 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1376 }
1377
1378 /* And last, print the forth quarter page links. */
1379 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
1380 $pg_str .= "...$spc";
1381 } else {
1382 if (($tot_pgs - $q4_pgs) > ($cur_pg + $q3_pgs)) {
1383 $pg_str .= "...$spc";
1384 }
1385 for ($pg = $tot_pgs - $q4_pgs + 1; $pg <= $tot_pgs; ++$pg) {
1386 $start = (($pg-1) * $show_num) + 1;
1387 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
1388 }
1389 }
1390 } else if ($PG_SHOWNUM == 999999) {
c7df3f1b 1391 $pg_str = "<a href=\"right_main.php?PG_SHOWALL=0"
6a622b59 1392 . "&amp;use_mailbox_cache=$use&amp;startMessage=1&amp;mailbox=$box\" "
c7df3f1b 1393 . ">" ._("Paginate") . '</a>';
6a622b59 1394 }
1395
6a622b59 1396 /* Put all the pieces of the paginator string together. */
1397 /**
1398 * Hairy code... But let's leave it like it is since I am not certain
1399 * a different approach would be any easier to read. ;)
1400 */
1401 $result = '';
abafb676 1402 if ( $prv_str != '' || $nxt_str != '' )
1403 {
1404 $result .= '[';
1405 $result .= ($prv_str != '' ? $prv_str . $spc . $sep . $spc : '');
1406 $result .= ($nxt_str != '' ? $nxt_str : '');
1407 $result .= ']' . $spc ;
eac26493 1408
1409 /* Compute the 'show all' string. */
c7df3f1b 1410 $all_str = "<a href=\"right_main.php?PG_SHOWALL=1"
eac26493 1411 . "&amp;use_mailbox_cache=$use&amp;startMessage=1&amp;mailbox=$box\" "
4669e892 1412 . ">" . _("Show All") . '</a>';
abafb676 1413 }
eac26493 1414
1415 $result .= ($pg_str != '' ? $spc . '['.$spc.$pg_str.']' . $spc : '');
abafb676 1416 $result .= ($all_str != '' ? $spc . '['.$all_str.']' . $spc . $spc : '');
6a622b59 1417
1418 /* If the resulting string is blank, return a non-breaking space. */
1419 if ($result == '') {
1420 $result = '&nbsp;';
1421 }
e35045b7 1422
6a622b59 1423 /* Return our final magical paginator string. */
1424 return ($result);
bdfb67f8 1425}
1426
c7df3f1b 1427/**
1428 * FIXME: Undocumented function
1429 */
eaa4f45f 1430function truncateWithEntities($subject, $trim_at)
1431{
341aa42f 1432 $ent_strlen = strlen($subject);
1433 if (($trim_at <= 0) || ($ent_strlen <= $trim_at))
6a622b59 1434 return $subject;
eaa4f45f 1435
1436 global $languages, $squirrelmail_language;
6a622b59 1437
6a622b59 1438 /*
1439 * see if this is entities-encoded string
1440 * If so, Iterate through the whole string, find out
1441 * the real number of characters, and if more
4669e892 1442 * than $trim_at, substr with an updated trim value.
6a622b59 1443 */
341aa42f 1444 $trim_val = $trim_at;
1445 $ent_offset = 0;
1446 $ent_loc = 0;
a1440f89 1447 while ( $ent_loc < $trim_val && (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
1448 (($ent_loc_end = strpos($subject, ';', $ent_loc+3)) !== false) ) {
1449 $trim_val += ($ent_loc_end-$ent_loc);
6a622b59 1450 $ent_offset = $ent_loc_end+1;
1451 }
341aa42f 1452 if (($trim_val > $trim_at) && ($ent_strlen > $trim_val) && (strpos($subject,';',$trim_val) < ($trim_val + 6))) {
a1440f89 1453 $i = strpos($subject,';',$trim_val);
1454 if ($i) {
1455 $trim_val = strpos($subject,';',$trim_val);
1456 }
46a49f65 1457 }
341aa42f 1458 // only print '...' when we're actually dropping part of the subject
1459 if ($ent_strlen <= $trim_val)
6a622b59 1460 return $subject;
6a622b59 1461
1462 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
1463 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
1464 return $languages[$squirrelmail_language]['XTRA_CODE']('strimwidth', $subject, $trim_val);
1465 }
ecaf6352 1466
341aa42f 1467 return substr_replace($subject, '...', $trim_val);
bdfb67f8 1468}
f93c93b9 1469
c7df3f1b 1470/**
1471 * FIXME: Undocumented function
1472 */
eaa4f45f 1473function processSubject($subject, $threadlevel = 0) {
1474 /* Shouldn't ever happen -- caught too many times in the IMAP functions */
1475 if ($subject == '') {
1476 return _("(no subject)");
1477 }
1478
3fc1a95f 1479 global $truncate_subject; /* number of characters for Subject field (<= 0 for unchanged) */
1480 $trim_at = $truncate_subject;
eaa4f45f 1481
1482 /* if this is threaded, subtract two chars per indentlevel */
1483 if (($threadlevel > 0) && ($threadlevel <= 10))
1484 $trim_at -= (2*$threadlevel);
1485
1486 return truncateWithEntities($subject, $trim_at);
1487}
1488
c7df3f1b 1489/**
1490 * FIXME: Undocumented function
1491 *
1492 * @param mixed $imapConnection
4669e892 1493 * @param mixed $boxes
c7df3f1b 1494 */
26454147 1495function getMbxList($imapConnection, $boxes = 0) {
6a622b59 1496 global $lastTargetMailbox;
1497 echo ' <small>&nbsp;<tt><select name="targetMailbox">';
4669e892 1498 echo sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)), 0, $boxes);
c7df3f1b 1499 echo ' </select></tt>&nbsp;';
e9e5f0fa 1500}
1501
c7df3f1b 1502/**
1503 * Creates button
1504 *
1505 * @deprecated see form functions available in 1.5.1 and 1.4.3.
1506 * @param string $type
1507 * @param string $name
1508 * @param string $value
1509 * @param string $js
1510 * @param bool $enabled
1511 */
1a531551 1512function getButton($type, $name, $value, $js = '', $enabled = TRUE) {
98a9cc03 1513 $disabled = ( $enabled ? '' : 'disabled ' );
1a531551 1514 $js = ( $js ? $js.' ' : '' );
c7df3f1b 1515 return '<input '.$disabled.$js.
1516 'type="'.$type.
1517 '" name="'.$name.
1518 '" value="'.$value .
1519 '" style="padding: 0px; margin: 0px" />';
e9e5f0fa 1520}
1521
c7df3f1b 1522/**
1523 * Puts string into cell, aligns it and adds <small> tag
1524 *
1525 * @param string $string string
1526 * @param string $align alignment
1527 */
e9e5f0fa 1528function getSmallStringCell($string, $align) {
6a622b59 1529 return html_tag('td',
1530 '<small>' . $string . ':&nbsp; </small>',
1531 $align,
1532 '',
1533 'nowrap' );
e9e5f0fa 1534}
1535
c7df3f1b 1536/**
1537 * FIXME: Undocumented function
1538 *
1539 * @param integer $start_msg
1540 * @param integer $show_num
1541 * @param integer $num_msgs
1542 */
e9e5f0fa 1543function getEndMessage($start_msg, $show_num, $num_msgs) {
6a622b59 1544 if ($start_msg + ($show_num - 1) < $num_msgs){
1545 $end_msg = $start_msg + ($show_num - 1);
1546 } else {
1547 $end_msg = $num_msgs;
1548 }
e9e5f0fa 1549
6a622b59 1550 if ($end_msg < $start_msg) {
1551 $start_msg = $start_msg - $show_num;
1552 if ($start_msg < 1) {
1553 $start_msg = 1;
1554 }
e9e5f0fa 1555 }
6a622b59 1556 return (array($start_msg,$end_msg));
e9e5f0fa 1557}
1558
c7df3f1b 1559/**
1560 * This should go in imap_mailbox.php
1561 * @param string $mailbox
1562 */
a3439b27 1563function handleAsSent($mailbox) {
6a8e7cae 1564 global $handleAsSent_result;
4669e892 1565
6a622b59 1566 /* First check if this is the sent or draft folder. */
6a8e7cae 1567 $handleAsSent_result = isSentMailbox($mailbox) || isDraftMailbox($mailbox);
a3439b27 1568
6a622b59 1569 /* Then check the result of the handleAsSent hook. */
1570 do_hook('check_handleAsSent_result', $mailbox);
a3439b27 1571
6a622b59 1572 /* And return the result. */
6a8e7cae 1573 return $handleAsSent_result;
6a622b59 1574}
e842b215 1575
b531f8ea 1576?>