' fix
[squirrelmail.git] / functions / mailbox_display.php
CommitLineData
59177427 1<?php
7c1b84d9 2
3302d0d4 3 /**
a09387f4 4 ** mailbox_display.php
3302d0d4 5 **
6 ** This contains functions that display mailbox information, such as the
7 ** table row that has sender, date, subject, etc...
8 **
245a6892 9 ** $Id$
3302d0d4 10 **/
a4c2cd49 11
f435778e 12 if (defined('mailbox_display_php'))
13 return;
14 define('mailbox_display_php', true);
d068c0ec 15
f7b1b3b1 16 define('PG_SEL_MAX', 10); /* Default value for page_selector_max. */
f1e6f580 17
1809bad8 18 function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage, $where, $what) {
66289791 19 global $checkall;
af9404d7 20 global $color, $msgs, $msort;
f7b1b3b1 21 global $sent_folder, $draft_folder;
9d157cec 22 global $message_highlight_list;
8e265988 23 global $index_order;
cbdc5621 24
ac53fb56 25 $color_string = $color[4];
26 if ($GLOBALS['alt_index_colors']) {
27 if (!isset($GLOBALS["row_count"])) {
28 $GLOBALS["row_count"] = 0;
29 }
30 $GLOBALS["row_count"]++;
31 if ($GLOBALS["row_count"] % 2) {
f136c965 32 if (!isset($color[12])) $color[12] = '#EAEAEA';
ac53fb56 33 $color_string = $color[12];
34 }
b3b103cb 35 }
0d455368 36 $msg = $msgs[$key];
d92b6f31 37
90bc0b93 38 $senderName = sqimap_find_displayable_name($msg['FROM']);
f136c965 39 if( $mailbox == _("None") ) {
40 // $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
41 $boxes = sqimap_mailbox_list($imapConnection);
42 // sqimap_logout($imapConnection);
43 $mailbox = $boxes[0]['unformatted'];
44 unset( $boxes );
d6def997 45 }
05207a68 46 $urlMailbox = urlencode($mailbox);
f93c93b9 47 $subject = processSubject($msg['SUBJECT']);
926da13e 48 echo "<TR>\n";
b60b58f9 49
f7b1b3b1 50 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
d6def997 51 $flag = "<font color=$color[2]>";
52 $flag_end = '</font>';
f7b1b3b1 53 } else {
90bc0b93 54 $flag = '';
6edca885 55 $flag_end = '';
245a6892 56 }
f7b1b3b1 57 if (!isset($msg['FLAG_SEEN']) || ($msg['FLAG_SEEN'] == false)) {
d6def997 58 $bold = '<b>';
59 $bold_end = '</b>';
f7b1b3b1 60 } else {
90bc0b93 61 $bold = '';
6edca885 62 $bold_end = '';
245a6892 63 }
f7b1b3b1 64
65 if (($mailbox == $sent_folder) || ($mailbox == $draft_folder)) {
d6def997 66 $italic = '<i>';
67 $italic_end = '</i>';
f7b1b3b1 68 } else {
90bc0b93 69 $italic = '';
6edca885 70 $italic_end = '';
245a6892 71 }
f7b1b3b1 72
73 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
d6def997 74 $fontstr = "<font color=\"$color[9]\">";
75 $fontstr_end = '</font>';
f7b1b3b1 76 } else {
90bc0b93 77 $fontstr = '';
6edca885 78 $fontstr_end = '';
245a6892 79 }
b60b58f9 80
9d157cec 81 for ($i=0; $i < count($message_highlight_list); $i++) {
90bc0b93 82 if (trim($message_highlight_list[$i]['value']) != '') {
83 if ($message_highlight_list[$i]['match_type'] == 'to_cc') {
84 if (strpos('^^'.strtolower($msg['TO']), strtolower($message_highlight_list[$i]['value'])) || strpos('^^'.strtolower($msg['CC']), strtolower($message_highlight_list[$i]['value']))) {
85 $hlt_color = $message_highlight_list[$i]['color'];
d059be8f 86 continue;
87 }
90bc0b93 88 } else if (strpos('^^'.strtolower($msg[strtoupper($message_highlight_list[$i]['match_type'])]),strtolower($message_highlight_list[$i]['value']))) {
89 $hlt_color = $message_highlight_list[$i]['color'];
1195c340 90 continue;
b60b58f9 91 }
d059be8f 92 }
b60b58f9 93 }
94
f7b1b3b1 95 if (!isset($hlt_color)) {
96 $hlt_color = $color_string;
97 }
1809bad8 98
99 if ($where && $what) {
90bc0b93 100 $search_stuff = '&where='.urlencode($where).'&what='.urlencode($what);
1809bad8 101 }
66289791 102
f7b1b3b1 103 $checked = ($checkall == 1 ?' checked' : '');
d6def997 104
8e265988 105 for ($i=1; $i <= count($index_order); $i++) {
106 switch ($index_order[$i]) {
f7b1b3b1 107 case 1: /* checkbox */
20cd8abb 108 echo " <td bgcolor=$hlt_color align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n";
8e265988 109 break;
f7b1b3b1 110 case 2: /* from */
20cd8abb 111 echo " <td bgcolor=$hlt_color>$italic$bold$flag$fontstr$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n";
8e265988 112 break;
f7b1b3b1 113 case 3: /* date */
20cd8abb 114 echo " <td nowrap bgcolor=$hlt_color><center>$bold$flag$fontstr".$msg["DATE_STRING"]."$fontstr_end$flag_end$bold_end</center></td>\n";
8e265988 115 break;
f7b1b3b1 116 case 4: /* subject */
7e73c6be 117 echo " <td bgcolor=$hlt_color>$bold";
6edca885 118 if (! isset($search_stuff)) { $search_stuff = ''; }
23fd3c8e 119 echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$startMessage&show_more=0$search_stuff\"";
120 do_hook("subject_link");
77f70304 121
8c16ad63 122 if ($subject != $msg['SUBJECT']) {
feb563a6 123 $title = get_html_translation_table(HTML_SPECIALCHARS);
124 $title = array_flip($title);
125 $title = strtr($msg['SUBJECT'], $title);
126 $title = str_replace('"', "''", $title);
8c16ad63 127 echo " title=\"$title\"";
feb563a6 128 }
129 echo ">$flag$subject$flag_end</a>$bold_end</td>\n";
8e265988 130 break;
f7b1b3b1 131 case 5: /* flags */
9db5f5fc 132 $stuff = false;
20cd8abb 133 echo " <td bgcolor=$hlt_color align=center nowrap><b><small>\n";
d6def997 134 if (isset($msg['FLAG_ANSWERED']) &&
6edca885 135 $msg['FLAG_ANSWERED'] == true) {
9db5f5fc 136 echo "A\n";
137 $stuff = true;
8ae331c2 138 }
5ae0173b 139 if (ereg('(5)',substr($msg['PRIORITY'],0,1))) {
140 echo "<font color=$color[8]>v</font>\n";
141 $stuff = true;
142 }
90bc0b93 143 if ($msg['TYPE0'] == 'multipart') {
9db5f5fc 144 echo "+\n";
145 $stuff = true;
8ae331c2 146 }
90bc0b93 147 if (ereg('(1|2)',substr($msg['PRIORITY'],0,1))) {
9db5f5fc 148 echo "<font color=$color[1]>!</font>\n";
149 $stuff = true;
150 }
90bc0b93 151 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
f9b3e5d9 152 echo "<font color=\"$color[1]\">D</font>\n";
153 $stuff = true;
154 }
8ae331c2 155
9db5f5fc 156 if (!$stuff) echo "&nbsp;\n";
157 echo "</small></b></td>\n";
8e265988 158 break;
f7b1b3b1 159 case 6: /* size */
20cd8abb 160 echo " <td bgcolor=$hlt_color>$bold$fontstr".show_readable_size($msg['SIZE'])."$fontstr_end$bold_end</td>\n";
8e265988 161 break;
162 }
163 }
7151188f 164 echo "</tr>\n";
926da13e 165 }
166
167 /**
f7b1b3b1 168 * This function loops through a group of messages in the mailbox
169 * and shows them to the user.
170 */
171 function showMessagesForMailbox
172 ($imapConnection, $mailbox, $numMessages, $startMessage,
173 $sort, $color,$show_num, $use_cache) {
5b6ae78a 174 global $msgs, $msort;
f7b1b3b1 175 global $sent_folder, $draft_folder;
9d157cec 176 global $message_highlight_list;
a3432f47 177 global $auto_expunge;
178
f7b1b3b1 179 /* If autoexpunge is turned on, then do it now. */
180 if ($auto_expunge == true) {
181 sqimap_mailbox_expunge($imapConnection, $mailbox, false);
182 }
0d455368 183 sqimap_mailbox_select($imapConnection, $mailbox);
61a4ac35 184
f7b1b3b1 185 $issent = (($mailbox == $sent_folder) || ($mailbox == $draft_folder));
5b6ae78a 186 if (!$use_cache) {
f7b1b3b1 187 /* If it is sorted... */
5b6ae78a 188 if ($numMessages >= 1) {
0d455368 189 if ($sort < 6) {
91f68e94 190 $id = range(1, $numMessages);
0d455368 191 } else {
192 // if it's not sorted
193 if ($startMessage + ($show_num - 1) < $numMessages) {
194 $endMessage = $startMessage + ($show_num-1);
195 } else {
196 $endMessage = $numMessages;
197 }
b60b58f9 198
0d455368 199 if ($endMessage < $startMessage) {
200 $startMessage = $startMessage - $show_num;
f7b1b3b1 201 if ($startMessage < 1) {
202 $startMessage = 1;
203 }
0d455368 204 }
205
a3d65705 206 $real_startMessage = $numMessages - $startMessage + 1;
91f68e94 207 $real_endMessage = $numMessages - $startMessage - $show_num + 2;
f7b1b3b1 208 if ($real_endMessage <= 0) {
209 $real_endMessage = 1;
210 }
91f68e94 211 $id = array_reverse(range($real_endMessage, $real_startMessage));
212 }
b60b58f9 213
91f68e94 214 $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
215 $flags = sqimap_get_flags_list($imapConnection, $id, $issent);
216 foreach ($msgs_list as $hdr) {
217 $from[] = $hdr->from;
218 $date[] = $hdr->date;
219 $subject[] = $hdr->subject;
220 $to[] = $hdr->to;
221 $priority[] = $hdr->priority;
222 $cc[] = $hdr->cc;
223 $size[] = $hdr->size;
224 $type[] = $hdr->type0;
b60b58f9 225 }
5b6ae78a 226 }
b60b58f9 227
5b6ae78a 228 $j = 0;
0d455368 229 if ($sort == 6) {
f7b1b3b1 230 $end = $startMessage + $show_num - 1;
231 if ($numMessages < $show_num) {
232 $end_loop = $numMessages;
233 } else if ($end > $numMessages) {
234 $end_loop = $numMessages - $startMessage + 1;
235 } else {
236 $end_loop = $show_num;
237 }
0d455368 238 } else {
239 $end = $numMessages;
cd928157 240 $end_loop = $end;
0d455368 241 }
f7b1b3b1 242
cd928157 243 while ($j < $end_loop) {
244 if (isset($date[$j])) {
245 $date[$j] = ereg_replace(' ', ' ', $date[$j]);
246 $tmpdate = explode(' ', trim($date[$j]));
247 } else {
248 $tmpdate = $date = array("","","","","","");
249 }
90bc0b93 250
251 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
252 $messages[$j]['DATE_STRING'] = getDateString($messages[$j]['TIME_STAMP']);
253 $messages[$j]['ID'] = $id[$j];
254 $messages[$j]['FROM'] = decodeHeader($from[$j]);
255 $messages[$j]['FROM-SORT'] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
256 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
257 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
258 $messages[$j]['TO'] = decodeHeader($to[$j]);
259 $messages[$j]['PRIORITY'] = $priority[$j];
260 $messages[$j]['CC'] = $cc[$j];
261 $messages[$j]['SIZE'] = $size[$j];
262 $messages[$j]['TYPE0'] = $type[$j];
e9f8ea4e 263
264 # fix SUBJECT-SORT to remove Re:
0d455368 265 $re_abbr = # Add more here!
90bc0b93 266 'vedr|sv|' . # Danish
267 're|aw'; # English
f1e6f580 268
269 if (eregi( "^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs))
0d455368 270 $messages[$j]['SUBJECT-SORT'] = $regs[2];
b60b58f9 271
5b6ae78a 272 $num = 0;
273 while ($num < count($flags[$j])) {
90bc0b93 274 if ($flags[$j][$num] == 'Deleted') {
f7b1b3b1 275 $messages[$j]['FLAG_DELETED'] = true;
276 } else if ($flags[$j][$num] == 'Answered') {
277 $messages[$j]['FLAG_ANSWERED'] = true;
278 } else if ($flags[$j][$num] == 'Seen') {
279 $messages[$j]['FLAG_SEEN'] = true;
280 } else if ($flags[$j][$num] == 'Flagged') {
281 $messages[$j]['FLAG_FLAGGED'] = true;
5b6ae78a 282 }
283 $num++;
7151188f 284 }
5b6ae78a 285 $j++;
3302d0d4 286 }
f9b3e5d9 287
288 /* Only ignore messages flagged as deleted if we are using a
289 * trash folder or auto_expunge */
d6def997 290 if (((isset($move_to_trash) && $move_to_trash)
f7b1b3b1 291 || (isset($auto_expunge) && $auto_expunge)) && $sort != 6) {
292
f9b3e5d9 293 /** Find and remove the ones that are deleted */
294 $i = 0;
295 $j = 0;
f7b1b3b1 296
f9b3e5d9 297 while ($j < $numMessages) {
cd928157 298 if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) {
f9b3e5d9 299 $j++;
300 continue;
301 }
302 $msgs[$i] = $messages[$j];
b60b58f9 303
f9b3e5d9 304 $i++;
5b6ae78a 305 $j++;
5b6ae78a 306 }
f9b3e5d9 307 $numMessages = $i;
0d455368 308 } else {
f7b1b3b1 309 if (!isset($messages)) {
310 $messages = array();
311 }
312 $msgs = $messages;
5b10f02a 313 }
d6def997 314 }
926da13e 315
4c2d69ac 316 // There's gotta be messages in the array for it to sort them.
f9b3e5d9 317 if ($numMessages > 0 && ! $use_cache) {
0e919368 318 /** 0 = Date (up) 4 = Subject (up)
319 ** 1 = Date (dn) 5 = Subject (dn)
320 ** 2 = Name (up)
321 ** 3 = Name (dn)
322 **/
09856735 323 session_unregister("msgs");
1c292c82 324 if (($sort == 0) || ($sort == 1))
90bc0b93 325 $msort = array_cleave ($msgs, 'TIME_STAMP');
9b0f85eb 326 elseif (($sort == 2) || ($sort == 3))
90bc0b93 327 $msort = array_cleave ($msgs, 'FROM-SORT');
9b0f85eb 328 elseif (($sort == 4) || ($sort == 5))
90bc0b93 329 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
9b0f85eb 330 else // ($sort == 6)
0d455368 331 $msort = $msgs;
332
333 if ($sort < 6) {
9b0f85eb 334 if ($sort % 2) {
0d455368 335 asort($msort);
336 } else {
337 arsort($msort);
338 }
0e919368 339 }
90bc0b93 340 session_register('msort');
4c2d69ac 341 }
5b6ae78a 342 displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $msort, $mailbox, $sort, $color,$show_num);
f7b1b3b1 343 session_register('msgs');
9f2215a1 344 }
345
f7b1b3b1 346 /******************************************************************/
347 /* Generic function to convert the msgs array into an HTML table. */
348 /******************************************************************/
5b6ae78a 349 function displayMessageArray($imapConnection, $numMessages, $startMessage, &$msgs, $msort, $mailbox, $sort, $color,$show_num) {
cbdc5621 350 global $folder_prefix, $sent_folder;
4aaea201 351 global $imapServerAddress, $data_dir, $username, $use_mailbox_cache;
21fafac8 352 global $index_order, $real_endMessage, $real_startMessage, $checkall;
feb563a6 353
f7b1b3b1 354 /* If cache isn't already set, do it now. */
355 if (!session_is_registered('msgs')) { session_register('msgs'); }
356 if (!session_is_registered('msort')) { session_register('msort'); }
90033b64 357
9c83f905 358 if ($startMessage + ($show_num - 1) < $numMessages) {
359 $endMessage = $startMessage + ($show_num-1);
926da13e 360 } else {
926da13e 361 $endMessage = $numMessages;
362 }
b60b58f9 363
8442ac08 364 if ($endMessage < $startMessage) {
365 $startMessage = $startMessage - $show_num;
f7b1b3b1 366 if ($startMessage < 1) { $startMessage = 1; }
8442ac08 367 }
b60b58f9 368
9c83f905 369 $nextGroup = $startMessage + $show_num;
370 $prevGroup = $startMessage - $show_num;
20db5033 371 $urlMailbox = urlencode($mailbox);
926da13e 372
90bc0b93 373 do_hook('mailbox_index_before');
926da13e 374
14eb705c 375 $Message = '';
0d1b4832 376 if ($startMessage < $endMessage) {
a2ae47f7 377 $Message = _("Viewing messages") .":<B>$startMessage</B> ". _("to") ." <B>$endMessage</B> ($numMessages " . _("total") . ")\n";
f9b3e5d9 378 } elseif ($startMessage == $endMessage) {
a2ae47f7 379 $Message = _("Viewing message") .":<B>$startMessage</B> ($numMessages " . _("total") . ")\n";
0d1b4832 380 }
26b6c99c 381
0d455368 382 if ($sort == 6) {
383 $use = 0;
384 } else {
385 $use = 1;
386 }
2c1872cb 387 $lMore = '';
388 $rMore = '';
5b10f02a 389 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
feb563a6 390 $lMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") . '</A>';
391 $rMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
f7b1b3b1 392 } else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
feb563a6 393 $lMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") . '</A>';
394 $rMore = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
f7b1b3b1 395 } else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
feb563a6 396 $lMore = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
397 $rMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
398 }
f7b1b3b1 399 if ($lMore <> '') {
400 $lMore .= ' | ';
401 }
feb563a6 402
f7b1b3b1 403 /* Page selector block. Following code computes page links. */
feb563a6 404 $mMore = '';
f7b1b3b1 405 if (!getPref($data_dir, $username, 'page_selector')
406 && ($numMessages > $show_num)) {
407 $j = intval( $numMessages / $show_num ); // Max pages
408 $k = max( 1, $j / getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX ) );
409 if ($numMessages % $show_num <> 0 ) {
410 $j++;
411 }
412 $startMessage = min( $startMessage, $numMessages );
413 $p = intval( $startMessage / $show_num ) + 1;
414 $i = 1;
415 while( $i < $p ) {
f1e6f580 416 $pg = intval( $i );
417 $start = ( ($pg-1) * $show_num ) + 1;
418 $mMore .= "<a href=\"right_main.php?use_mailbox_cache=$use_mailbox_cache&startMessage=$start" .
419 "&mailbox=$urlMailbox\" TARGET=\"right\">$pg</a> ";
f7b1b3b1 420 $i += $k;
421 }
422 $mMore .= "<b>$p</b> ";
423 $i += $k;
424 while( $i <= $j ) {
f1e6f580 425 $pg = intval( $i );
426 $start = ( ($pg-1) * $show_num ) + 1;
427 $mMore .= "<a href=\"right_main.php?use_mailbox_cache=$use_mailbox_cache&startMessage=$start" .
428 "&mailbox=$urlMailbox\" TARGET=\"right\">$pg</a> ";
429 $i+=$k;
f7b1b3b1 430 }
431 $mMore .= ' | ';
14eb705c 432 }
433
245a6892 434 if (! isset($msg))
feb563a6 435 $msg = '';
b60b58f9 436 mail_message_listing_beginning($imapConnection,
14eb705c 437 "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$startMessage",
feb563a6 438 $mailbox, $sort, $Message, $lMore . $mMore . $rMore, $startMessage);
14eb705c 439
8ae331c2 440 $groupNum = $startMessage % ($show_num - 1);
72b0f272 441 $real_startMessage = $startMessage;
b60b58f9 442 if ($sort == 6) {
443 if ($endMessage - $startMessage < $show_num - 1) {
444 $endMessage = $endMessage - $startMessage + 1;
445 $startMessage = 1;
446 } else if ($startMessage > $show_num) {
447 $endMessage = $show_num;
448 $startMessage = 1;
449 }
450 }
b60b58f9 451 $endVar = $endMessage + 1;
452
14eb705c 453 // loop through and display the info for each message.
454 $t = 0; // $t is used for the checkbox number
455 if ($numMessages == 0) { // if there's no messages in this folder
456 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order);
457 echo "><CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR>&nbsp;</CENTER></TD></TR>";
b60b58f9 458 } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
a3d65705 459 if ($sort != 6)
460 $i = $startMessage;
461 else
462 $i = 1;
14eb705c 463 reset($msort);
6edca885 464 $k = 0;
14eb705c 465 do {
466 $key = key($msort);
467 next($msort);
468 $k++;
469 } while (isset ($key) && ($k < $i));
72b0f272 470 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
14eb705c 471 } else {
b60b58f9 472 $i = $startMessage;
473
14eb705c 474 reset($msort);
6edca885 475 $k = 0;
14eb705c 476 do {
477 $key = key($msort);
478 next($msort);
479 $k++;
480 } while (isset ($key) && ($k < $i));
481
0d455368 482 do {
72b0f272 483 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
14eb705c 484 $key = key($msort);
485 $t++;
486 $i++;
487 next($msort);
b60b58f9 488 } while ($i && $i < $endVar);
14eb705c 489 }
14eb705c 490
1125b3de 491 echo '</table>';
820495bb 492 echo "<table width=100%><tr ><td>$lMore$mMore$rMore</td><td align=right>$Message</td></tr></table>";
a2ae47f7 493 /** End of message-list table */
14eb705c 494
90bc0b93 495 do_hook('mailbox_index_after');
a2ae47f7 496 echo "</TABLE></FORM>\n";
14eb705c 497 }
498
499 /* Displays the standard message list header.
500 * To finish the table, you need to do a "</table></table>";
501 * $moveURL is the URL to submit the delete/move form to
502 * $mailbox is the current mailbox
503 * $sort is the current sorting method (-1 for no sorting available [searches])
504 * $Message is a message that is centered on top of the list
505 * $More is a second line that is left aligned
506 */
f7b1b3b1 507 function mail_message_listing_beginning
508 ($imapConnection, $moveURL, $mailbox = '', $sort = -1,
509 $Message = '', $More = '', $startMessage = 1) {
f9b3e5d9 510 global $color, $index_order, $auto_expunge, $move_to_trash;
f7b1b3b1 511 global $checkall, $sent_folder, $draft_folder;
eca500d0 512 $urlMailbox = urlencode($mailbox);
8ae331c2 513
6332704d 514 /** This is the beginning of the message list table. It wraps around all messages */
515 echo '<TABLE WIDTH="100%" BORDER="0" CELLPADDING="2" CELLSPACING="0">';
8ae331c2 516
66289791 517 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
926da13e 518
81caa0f3 519 echo "<table bgcolor=\"$color[4]\" cellpadding=2".
520 ' width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>' .
521 "$More</td><td align=right>";
522 ShowSelectAllLink($startMessage, $sort);
523 echo "</td></tr></table>\n</td></tr>";
524
68347a84 525 /** The delete and move options */
f8f9bed9 526 echo "<TR><TD BGCOLOR=\"$color[0]\">";
ed4332d1 527
feb563a6 528 echo "\n<FORM name=messageList method=post action=\"$moveURL\">\n";
4f313fcf 529 echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=100%>\n";
66289791 530
f1e6f580 531 echo " <TR>\n" .
532 " <TD ALIGN=LEFT VALIGN=CENTER NOWRAP>\n" .
533 ' <SMALL>&nbsp;' . _("Move selected to:") . "</SMALL>\n" .
534 " </TD>\n" .
f1e6f580 535 " <TD ALIGN=RIGHT NOWRAP>\n" .
536 ' <SMALL>&nbsp;' . _("Transform Selected Messages") . ": &nbsp; </SMALL><BR>\n" .
537 " </TD>\n" .
538 " </TR>\n" .
539 " <TR>\n" .
540 " <TD ALIGN=LEFT VALIGN=CENTER NOWRAP>\n" .
541 ' <SMALL>&nbsp;<TT><SELECT NAME="targetMailbox">';
7ce342dc 542
9f2215a1 543 $boxes = sqimap_mailbox_list($imapConnection);
7ce342dc 544 for ($i = 0; $i < count($boxes); $i++) {
cbbdef2a 545 if (!in_array("noselect", $boxes[$i]['flags'])) {
90bc0b93 546 $box = $boxes[$i]['unformatted'];
0cd84d75 547 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
14eb705c 548 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
6edca885 549 }
dd88d31f 550 }
0c6d50f1 551 echo ' </SELECT></TT></SMALL>';
6332704d 552 echo " <SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"" . _("Move") . "\"></SMALL>\n";
ed4332d1 553 echo " </TD>\n";
6332704d 554 echo " <TD ALIGN=RIGHT NOWRAP>&nbsp;&nbsp;&nbsp;\n";
f7b1b3b1 555 if (!$auto_expunge) {
6332704d 556 echo ' <INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'">&nbsp;'. _("mailbox") ."&nbsp;\n";
f9b3e5d9 557 }
6332704d 558 echo " <INPUT TYPE=SUBMIT NAME=\"markRead\" VALUE=\"". _("Read")."\">\n";
559 echo " <INPUT TYPE=SUBMIT NAME=\"markUnread\" VALUE=\"". _("Unread")."\">\n";
560 echo " <INPUT TYPE=SUBMIT VALUE=\"". _("Delete") . "\">&nbsp;\n";
14eb705c 561 echo " </TD>\n";
ed4332d1 562 echo " </TR>\n";
70b455e0 563 echo "</TABLE>\n";
90bc0b93 564 do_hook('mailbox_form_before');
565 echo '</TD></TR>';
aa4c3749 566
f8f9bed9 567 echo "<TR><TD BGCOLOR=\"$color[0]\">";
ac53fb56 568 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=";
569 if ($GLOBALS['alt_index_colors']) {
570 echo "0";
571 } else {
572 echo "1";
573 }
574 echo " BGCOLOR=\"$color[0]\">";
f8f9bed9 575 echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
be8e07f8 576
f7b1b3b1 577 /* Print the headers. */
8e265988 578 for ($i=1; $i <= count($index_order); $i++) {
579 switch ($index_order[$i]) {
f7b1b3b1 580 case 1: /* checkbox */
581 case 5: /* flags */
90bc0b93 582 echo ' <TD WIDTH="1%"><B>&nbsp;</B></TD>';
8e265988 583 break;
d6def997 584
f7b1b3b1 585 case 2: /* from */
586 if (($mailbox == $sent_folder)
587 || ($mailbox == $draft_folder)) {
20cd8abb 588 echo ' <TD WIDTH="25%"><B>'. _("To") .'</B>';
f7b1b3b1 589 } else {
590 echo ' <TD WIDTH="25%"><B>'. _("From") .'</B>';
591 }
592
d6def997 593 ShowSortButton($sort, $mailbox, 2, 3);
9b0f85eb 594 echo "</TD>\n";
8e265988 595 break;
d6def997 596
f7b1b3b1 597 case 3: /* date */
20cd8abb 598 echo ' <TD NOWRAP WIDTH="5%"><B>'. _("Date") .'</B>';
d6def997 599 ShowSortButton($sort, $mailbox, 0, 1);
9b0f85eb 600 echo "</TD>\n";
8e265988 601 break;
d6def997 602
f7b1b3b1 603 case 4: /* subject */
9b0f85eb 604 echo ' <TD><B>'. _("Subject") .'</B> ';
d6def997 605 ShowSortButton($sort, $mailbox, 4, 5);
9b0f85eb 606 echo "</TD>\n";
8e265988 607 break;
d6def997 608
f7b1b3b1 609 case 6: /* size */
20cd8abb 610 echo ' <TD WIDTH="5%"><b>' . _("Size")."</b></TD>\n";
8e265988 611 break;
612 }
613 }
14eb705c 614 echo "</TR>\n";
3302d0d4 615 }
d6def997 616
f7b1b3b1 617 /*******************************************************************/
618 /* This function shows the sort button. Isn't this a good comment? */
619 /*******************************************************************/
9b0f85eb 620 function ShowSortButton($sort, $mailbox, $Up, $Down) {
f7b1b3b1 621 /* Figure out which image we want to use. */
9b0f85eb 622 if ($sort != $Up && $sort != $Down) {
623 $img = 'sort_none.gif';
624 $which = $Up;
625 } elseif ($sort == $Up) {
626 $img = 'up_pointer.gif';
d6def997 627 $which = $Down;
9b0f85eb 628 } else {
629 $img = 'down_pointer.gif';
d6def997 630 $which = 6;
9b0f85eb 631 }
f7b1b3b1 632
633 /* Now that we have everything figured out, show the actual button. */
d6def997 634 echo ' <a href="right_main.php?newsort=' . $which .
635 '&startMessage=1&mailbox=' . urlencode($mailbox) .
636 '"><IMG SRC="../images/' . $img .
637 '" BORDER=0 WIDTH=12 HEIGHT=10></a>';
9b0f85eb 638 }
d6def997 639
f7b1b3b1 640 function ShowSelectAllLink($startMessage, $sort) {
323218d7 641 global $checkall, $PHP_SELF, $what, $where, $mailbox;
5de4de79 642
2016e645 643 echo '&nbsp;<script language="JavaScript">' .
644 "\n<!-- \n" .
645 "function CheckAll() {\n" .
646 " for (var i = 0; i < document.messageList.elements.length; i++) {\n" .
647 " if( document.messageList.elements[i].type == 'checkbox' ) {\n" .
648 " document.messageList.elements[i].checked = !(document.messageList.elements[i].checked);\n".
649 " }\n" .
650 " }\n" .
651 "}\n" .
652 'window.document.write(\'<a href=# onClick="CheckAll();">' . _("Toggle All") . "</a>');\n" .
653 "//-->\n" .
654 "</script>\n<noscript>\n";
0700d853 655
656 echo "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox) .
657 "&startMessage=$startMessage&sort=$sort&checkall=";
7b0485a6 658 if (isset($checkall) && $checkall == '1')
659 echo '0';
323218d7 660 else
7b0485a6 661 echo '1';
323218d7 662 if (isset($where) && isset($what))
7b0485a6 663 echo '&where=' . urlencode($where) . '&what=' . urlencode($what);
323218d7 664 echo "\">";
665 if (isset($checkall) && $checkall == '1')
666 echo _("Unselect All");
667 else
668 echo _("Select All");
d6def997 669
5de4de79 670 echo "</A>\n</noscript>\n";
323218d7 671 }
f93c93b9 672
673 function processSubject($subject)
674 {
675 // Shouldn't ever happen -- caught too many times in the IMAP functions
676 if ($subject == '')
677 return _("(no subject)");
d6def997 678
f93c93b9 679 if (strlen($subject) <= 55)
680 return $subject;
d6def997 681
f93c93b9 682 $ent_strlen=strlen($subject);
683 $trim_val=50;
684 $ent_offset=0;
685 // see if this is entities-encoded string
686 // If so, Iterate through the whole string, find out
687 // the real number of characters, and if more
688 // than 55, substr with an updated trim value.
689 while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false &&
690 ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false)
691 {
d6def997 692 $trim_val += ($ent_loc_end-$ent_loc)+1;
693 $ent_strlen -= $ent_loc_end-$ent_loc;
694 $ent_offset = $ent_loc_end+1;
f93c93b9 695 }
d6def997 696
f93c93b9 697 if ($ent_strlen <= 55)
698 return $subject;
699
700 return substr($subject, 0, $trim_val) . '...';
701 }
702
2016e645 703?>