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