mailbox_display.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. <?php
  2. /**
  3. ** mailbox_display.php
  4. **
  5. ** This contains functions that display mailbox information, such as the
  6. ** table row that has sender, date, subject, etc...
  7. **
  8. ** $Id$
  9. **/
  10. if (defined('mailbox_display_php'))
  11. return;
  12. define('mailbox_display_php', true);
  13. function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage, $where, $what) {
  14. global $checkall;
  15. global $color, $msgs, $msort;
  16. global $sent_folder;
  17. global $message_highlight_list;
  18. global $index_order;
  19. $color_string = $color[4];
  20. if ($GLOBALS['alt_index_colors']) {
  21. if (!isset($GLOBALS["row_count"])) {
  22. $GLOBALS["row_count"] = 0;
  23. }
  24. $GLOBALS["row_count"]++;
  25. if ($GLOBALS["row_count"] % 2) {
  26. if (!isset($color[12])) $color[12] = "#EAEAEA";
  27. $color_string = $color[12];
  28. }
  29. }
  30. $msg = $msgs[$key];
  31. $senderName = sqimap_find_displayable_name($msg['FROM']);
  32. $urlMailbox = urlencode($mailbox);
  33. $subject = processSubject($msg['SUBJECT']);
  34. echo "<TR>\n";
  35. if (isset($msg['FLAG_FLAGGED']) && $msg['FLAG_FLAGGED'] == true)
  36. {
  37. $flag = "<font color=$color[2]>";
  38. $flag_end = '</font>';
  39. }
  40. else
  41. {
  42. $flag = '';
  43. $flag_end = '';
  44. }
  45. if (!isset($msg['FLAG_SEEN']) || $msg['FLAG_SEEN'] == false)
  46. {
  47. $bold = '<b>';
  48. $bold_end = '</b>';
  49. }
  50. else
  51. {
  52. $bold = '';
  53. $bold_end = '';
  54. }
  55. if ($mailbox == $sent_folder)
  56. {
  57. $italic = '<i>';
  58. $italic_end = '</i>';
  59. }
  60. else
  61. {
  62. $italic = '';
  63. $italic_end = '';
  64. }
  65. if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'])
  66. {
  67. $fontstr = "<font color=\"$color[9]\">";
  68. $fontstr_end = '</font>';
  69. }
  70. else
  71. {
  72. $fontstr = '';
  73. $fontstr_end = '';
  74. }
  75. for ($i=0; $i < count($message_highlight_list); $i++) {
  76. if (trim($message_highlight_list[$i]['value']) != '') {
  77. if ($message_highlight_list[$i]['match_type'] == 'to_cc') {
  78. if (strpos('^^'.strtolower($msg['TO']), strtolower($message_highlight_list[$i]['value'])) || strpos('^^'.strtolower($msg['CC']), strtolower($message_highlight_list[$i]['value']))) {
  79. $hlt_color = $message_highlight_list[$i]['color'];
  80. continue;
  81. }
  82. } else if (strpos('^^'.strtolower($msg[strtoupper($message_highlight_list[$i]['match_type'])]),strtolower($message_highlight_list[$i]['value']))) {
  83. $hlt_color = $message_highlight_list[$i]['color'];
  84. continue;
  85. }
  86. }
  87. }
  88. if (!isset($hlt_color))
  89. $hlt_color = $color_string;
  90. if ($where && $what) {
  91. $search_stuff = '&where='.urlencode($where).'&what='.urlencode($what);
  92. }
  93. if ($checkall == 1)
  94. $checked = ' checked';
  95. else
  96. $checked = '';
  97. for ($i=1; $i <= count($index_order); $i++) {
  98. switch ($index_order[$i]) {
  99. case 1: # checkbox
  100. echo " <td bgcolor=$hlt_color align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n";
  101. break;
  102. case 2: # from
  103. echo " <td bgcolor=$hlt_color>$italic$bold$flag$fontstr$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n";
  104. break;
  105. case 3: # date
  106. echo " <td nowrap bgcolor=$hlt_color><center>$bold$flag$fontstr".$msg["DATE_STRING"]."$fontstr_end$flag_end$bold_end</center></td>\n";
  107. break;
  108. case 4: # subject
  109. echo " <td bgcolor=$hlt_color>$bold";
  110. if (! isset($search_stuff)) { $search_stuff = ''; }
  111. echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$startMessage&show_more=0$search_stuff\"";
  112. do_hook("subject_link");
  113. if ($subject != $msg['SUBJECT']) {
  114. $title = get_html_translation_table(HTML_SPECIALCHARS);
  115. $title = array_flip($title);
  116. $title = strtr($msg['SUBJECT'], $title);
  117. $title = str_replace('"', "''", $title);
  118. echo " title=\"$title\"";
  119. }
  120. echo ">$flag$subject$flag_end</a>$bold_end</td>\n";
  121. break;
  122. case 5: # flags
  123. $stuff = false;
  124. echo " <td bgcolor=$hlt_color align=center nowrap><b><small>\n";
  125. if (isset($msg['FLAG_ANSWERED']) &&
  126. $msg['FLAG_ANSWERED'] == true) {
  127. echo "A\n";
  128. $stuff = true;
  129. }
  130. if ($msg['TYPE0'] == 'multipart') {
  131. echo "+\n";
  132. $stuff = true;
  133. }
  134. if (ereg('(1|2)',substr($msg['PRIORITY'],0,1))) {
  135. echo "<font color=$color[1]>!</font>\n";
  136. $stuff = true;
  137. }
  138. if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
  139. echo "<font color=\"$color[1]\">D</font>\n";
  140. $stuff = true;
  141. }
  142. if (!$stuff) echo "&nbsp;\n";
  143. echo "</small></b></td>\n";
  144. break;
  145. case 6: # size
  146. echo " <td bgcolor=$hlt_color>$bold$fontstr".show_readable_size($msg['SIZE'])."$fontstr_end$bold_end</td>\n";
  147. break;
  148. }
  149. }
  150. echo "</tr>\n";
  151. }
  152. /**
  153. ** This function loops through a group of messages in the mailbox and shows them
  154. **/
  155. function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color,$show_num, $use_cache) {
  156. global $msgs, $msort;
  157. global $sent_folder;
  158. global $message_highlight_list;
  159. global $auto_expunge;
  160. if ($auto_expunge == true) sqimap_mailbox_expunge($imapConnection, $mailbox, false);
  161. sqimap_mailbox_select($imapConnection, $mailbox);
  162. $issent = ($mailbox == $sent_folder);
  163. if (!$use_cache) {
  164. // if it's sorted
  165. if ($numMessages >= 1) {
  166. if ($sort < 6) {
  167. $id = range(1, $numMessages);
  168. } else {
  169. // if it's not sorted
  170. if ($startMessage + ($show_num - 1) < $numMessages) {
  171. $endMessage = $startMessage + ($show_num-1);
  172. } else {
  173. $endMessage = $numMessages;
  174. }
  175. if ($endMessage < $startMessage) {
  176. $startMessage = $startMessage - $show_num;
  177. if ($startMessage < 1)
  178. $startMessage = 1;
  179. }
  180. $real_startMessage = $numMessages - $startMessage + 1;
  181. $real_endMessage = $numMessages - $startMessage - $show_num + 2;
  182. if ($real_endMessage <= 0)
  183. $real_endMessage = 1;
  184. $id = array_reverse(range($real_endMessage, $real_startMessage));
  185. }
  186. $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
  187. $flags = sqimap_get_flags_list($imapConnection, $id, $issent);
  188. foreach ($msgs_list as $hdr) {
  189. $from[] = $hdr->from;
  190. $date[] = $hdr->date;
  191. $subject[] = $hdr->subject;
  192. $to[] = $hdr->to;
  193. $priority[] = $hdr->priority;
  194. $cc[] = $hdr->cc;
  195. $size[] = $hdr->size;
  196. $type[] = $hdr->type0;
  197. }
  198. }
  199. $j = 0;
  200. if ($sort == 6) {
  201. $end = $startMessage + $show_num - 1;
  202. if ($numMessages < $show_num)
  203. $end_loop = $numMessages;
  204. elseif ($end > $numMessages)
  205. $end_loop = $numMessages - $startMessage + 1;
  206. else
  207. $end_loop = $show_num;
  208. } else {
  209. $end = $numMessages;
  210. $end_loop = $end;
  211. }
  212. while ($j < $end_loop) {
  213. if (isset($date[$j])) {
  214. $date[$j] = ereg_replace(' ', ' ', $date[$j]);
  215. $tmpdate = explode(' ', trim($date[$j]));
  216. } else {
  217. $tmpdate = $date = array("","","","","","");
  218. }
  219. $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
  220. $messages[$j]['DATE_STRING'] = getDateString($messages[$j]['TIME_STAMP']);
  221. $messages[$j]['ID'] = $id[$j];
  222. $messages[$j]['FROM'] = decodeHeader($from[$j]);
  223. $messages[$j]['FROM-SORT'] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
  224. $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
  225. $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
  226. $messages[$j]['TO'] = decodeHeader($to[$j]);
  227. $messages[$j]['PRIORITY'] = $priority[$j];
  228. $messages[$j]['CC'] = $cc[$j];
  229. $messages[$j]['SIZE'] = $size[$j];
  230. $messages[$j]['TYPE0'] = $type[$j];
  231. # fix SUBJECT-SORT to remove Re:
  232. $re_abbr = # Add more here!
  233. 'vedr|sv|' . # Danish
  234. 're|aw'; # English
  235. if (eregi("^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs))
  236. $messages[$j]['SUBJECT-SORT'] = $regs[2];
  237. $num = 0;
  238. while ($num < count($flags[$j])) {
  239. if ($flags[$j][$num] == 'Deleted') {
  240. $messages[$j]['FLAG_DELETED'] = true;
  241. }
  242. elseif ($flags[$j][$num] == 'Answered') {
  243. $messages[$j]['FLAG_ANSWERED'] = true;
  244. }
  245. elseif ($flags[$j][$num] == 'Seen') {
  246. $messages[$j]['FLAG_SEEN'] = true;
  247. }
  248. elseif ($flags[$j][$num] == 'Flagged') {
  249. $messages[$j]['FLAG_FLAGGED'] = true;
  250. }
  251. $num++;
  252. }
  253. $j++;
  254. }
  255. /* Only ignore messages flagged as deleted if we are using a
  256. * trash folder or auto_expunge */
  257. if (((isset($move_to_trash) && $move_to_trash)
  258. || (isset($auto_expunge) && $auto_expunge)) && $sort != 6)
  259. {
  260. /** Find and remove the ones that are deleted */
  261. $i = 0;
  262. $j = 0;
  263. while ($j < $numMessages) {
  264. if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) {
  265. $j++;
  266. continue;
  267. }
  268. $msgs[$i] = $messages[$j];
  269. $i++;
  270. $j++;
  271. }
  272. $numMessages = $i;
  273. } else {
  274. if (! isset($messages))
  275. $messages = array();
  276. $msgs = $messages;
  277. }
  278. }
  279. // There's gotta be messages in the array for it to sort them.
  280. if ($numMessages > 0 && ! $use_cache) {
  281. /** 0 = Date (up) 4 = Subject (up)
  282. ** 1 = Date (dn) 5 = Subject (dn)
  283. ** 2 = Name (up)
  284. ** 3 = Name (dn)
  285. **/
  286. session_unregister("msgs");
  287. if (($sort == 0) || ($sort == 1))
  288. $msort = array_cleave ($msgs, 'TIME_STAMP');
  289. elseif (($sort == 2) || ($sort == 3))
  290. $msort = array_cleave ($msgs, 'FROM-SORT');
  291. elseif (($sort == 4) || ($sort == 5))
  292. $msort = array_cleave ($msgs, 'SUBJECT-SORT');
  293. else // ($sort == 6)
  294. $msort = $msgs;
  295. if ($sort < 6) {
  296. if ($sort % 2) {
  297. asort($msort);
  298. } else {
  299. arsort($msort);
  300. }
  301. }
  302. session_register('msort');
  303. }
  304. displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $msort, $mailbox, $sort, $color,$show_num);
  305. session_register('msgs');
  306. }
  307. // generic function to convert the msgs array into an HTML table
  308. function displayMessageArray($imapConnection, $numMessages, $startMessage, &$msgs, $msort, $mailbox, $sort, $color,$show_num) {
  309. global $folder_prefix, $sent_folder;
  310. global $imapServerAddress;
  311. global $index_order, $real_endMessage, $real_startMessage, $checkall;
  312. // if cache isn't already set, do it now
  313. if (!session_is_registered('msgs'))
  314. session_register('msgs');
  315. if (!session_is_registered('msort'))
  316. session_register('msort');
  317. if ($startMessage + ($show_num - 1) < $numMessages) {
  318. $endMessage = $startMessage + ($show_num-1);
  319. } else {
  320. $endMessage = $numMessages;
  321. }
  322. if ($endMessage < $startMessage) {
  323. $startMessage = $startMessage - $show_num;
  324. if ($startMessage < 1)
  325. $startMessage = 1;
  326. }
  327. $nextGroup = $startMessage + $show_num;
  328. $prevGroup = $startMessage - $show_num;
  329. $urlMailbox = urlencode($mailbox);
  330. do_hook('mailbox_index_before');
  331. $Message = '';
  332. if ($startMessage < $endMessage) {
  333. $Message = _("Viewing messages") ." <B>$startMessage</B> ". _("to") ." <B>$endMessage</B> ($numMessages " . _("total") . ")\n";
  334. } elseif ($startMessage == $endMessage) {
  335. $Message = _("Viewing message") ." <B>$startMessage</B> ($numMessages " . _("total") . ")\n";
  336. }
  337. $More = '';
  338. if ($sort == 6) {
  339. $use = 0;
  340. } else {
  341. $use = 1;
  342. }
  343. if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
  344. $More = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
  345. $More .= "<A HREF=\"right_main.php?use_mailbox_cache=$use&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
  346. }
  347. elseif (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
  348. $More = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
  349. $More .= "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
  350. }
  351. elseif (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
  352. $More = "<FONT COLOR=\"$color[9]\">"._("Previous")."</FONT> | \n";
  353. $More .= "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
  354. }
  355. if (! isset($msg))
  356. $msg = "";
  357. mail_message_listing_beginning($imapConnection,
  358. "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$startMessage",
  359. $mailbox, $sort, $Message, $More, $startMessage);
  360. $groupNum = $startMessage % ($show_num - 1);
  361. $real_startMessage = $startMessage;
  362. if ($sort == 6) {
  363. if ($endMessage - $startMessage < $show_num - 1) {
  364. $endMessage = $endMessage - $startMessage + 1;
  365. $startMessage = 1;
  366. } else if ($startMessage > $show_num) {
  367. $endMessage = $show_num;
  368. $startMessage = 1;
  369. }
  370. }
  371. $endVar = $endMessage + 1;
  372. // loop through and display the info for each message.
  373. $t = 0; // $t is used for the checkbox number
  374. if ($numMessages == 0) { // if there's no messages in this folder
  375. echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order);
  376. echo "><CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR>&nbsp;</CENTER></TD></TR>";
  377. } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
  378. if ($sort != 6)
  379. $i = $startMessage;
  380. else
  381. $i = 1;
  382. reset($msort);
  383. $k = 0;
  384. do {
  385. $key = key($msort);
  386. next($msort);
  387. $k++;
  388. } while (isset ($key) && ($k < $i));
  389. printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
  390. } else {
  391. $i = $startMessage;
  392. reset($msort);
  393. $k = 0;
  394. do {
  395. $key = key($msort);
  396. next($msort);
  397. $k++;
  398. } while (isset ($key) && ($k < $i));
  399. do {
  400. printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
  401. $key = key($msort);
  402. $t++;
  403. $i++;
  404. next($msort);
  405. } while ($i && $i < $endVar);
  406. }
  407. echo '</TABLE></FORM>';
  408. echo "</td></tr>\n";
  409. echo "<TR BGCOLOR=\"$color[4]\"><TD>";
  410. echo '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>';
  411. echo "$More</td><td align=right>\n";
  412. if (!$startMessage) $startMessage=1;
  413. ShowSelectAllLink($startMessage, $sort);
  414. echo '</td></tr></table>';
  415. echo '</td></tr>';
  416. echo '</table>'; /** End of message-list table */
  417. do_hook('mailbox_index_after');
  418. }
  419. /* Displays the standard message list header.
  420. * To finish the table, you need to do a "</table></table>";
  421. * $moveURL is the URL to submit the delete/move form to
  422. * $mailbox is the current mailbox
  423. * $sort is the current sorting method (-1 for no sorting available [searches])
  424. * $Message is a message that is centered on top of the list
  425. * $More is a second line that is left aligned
  426. */
  427. function mail_message_listing_beginning($imapConnection, $moveURL,
  428. $mailbox = '', $sort = -1, $Message = '', $More = '', $startMessage = 1)
  429. {
  430. global $color, $index_order, $auto_expunge, $move_to_trash;
  431. global $checkall, $sent_folder;
  432. $urlMailbox = urlencode($mailbox);
  433. /** This is the beginning of the message list table. It wraps around all messages */
  434. echo '<TABLE WIDTH="100%" BORDER="0" CELLPADDING="2" CELLSPACING="0">';
  435. if ($Message)
  436. {
  437. echo "<TR BGCOLOR=\"$color[4]\"><TD align=center>$Message</td></tr>\n";
  438. }
  439. echo "<TR BGCOLOR=\"$color[4]\"><TD>";
  440. echo '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>';
  441. echo "$More</td><td align=right>\n";
  442. ShowSelectAllLink($startMessage, $sort);
  443. echo '</td></tr></table>';
  444. echo '</td></tr>';
  445. /** The delete and move options */
  446. echo "<TR><TD BGCOLOR=\"$color[0]\">";
  447. echo "\n\n\n<FORM name=messageList method=post action=\"$moveURL\">\n";
  448. echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=100%>\n";
  449. echo " <TR>\n";
  450. echo " <TD WIDTH=60% ALIGN=LEFT VALIGN=CENTER>\n";
  451. echo ' <NOBR><SMALL>'. _("Move selected to:") .'</SMALL>';
  452. echo ' <TT><SMALL><SELECT NAME="targetMailbox">';
  453. $boxes = sqimap_mailbox_list($imapConnection);
  454. for ($i = 0; $i < count($boxes); $i++) {
  455. if (!in_array("noselect", $boxes[$i]['flags'])) {
  456. $box = $boxes[$i]['unformatted'];
  457. $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
  458. echo " <OPTION VALUE=\"$box\">$box2</option>\n";
  459. }
  460. }
  461. echo ' </SELECT></SMALL></TT>';
  462. echo ' <SMALL><INPUT TYPE=SUBMIT NAME="moveButton" VALUE="'. _("Move") ."\"></SMALL></NOBR>\n";
  463. echo " </TD>\n";
  464. echo " <TD WIDTH=40% ALIGN=RIGHT>\n";
  465. if (! $auto_expunge) {
  466. echo ' <NOBR><SMALL><INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'">&nbsp;'. _("mailbox") ."</SMALL></NOBR>&nbsp;&nbsp;\n";
  467. }
  468. echo " <NOBR><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\">&nbsp;". _("checked messages") ."</SMALL></NOBR>\n";
  469. echo " </TD>\n";
  470. echo " </TR>\n";
  471. echo "</TABLE>\n";
  472. do_hook('mailbox_form_before');
  473. echo '</TD></TR>';
  474. echo "<TR><TD BGCOLOR=\"$color[0]\">";
  475. echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=";
  476. if ($GLOBALS['alt_index_colors']) {
  477. echo "0";
  478. } else {
  479. echo "1";
  480. }
  481. echo " BGCOLOR=\"$color[0]\">";
  482. echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
  483. // Print the headers
  484. for ($i=1; $i <= count($index_order); $i++) {
  485. switch ($index_order[$i]) {
  486. case 1: # checkbox
  487. case 5: # flags
  488. echo ' <TD WIDTH="1%"><B>&nbsp;</B></TD>';
  489. break;
  490. case 2: # from
  491. if ($mailbox == $sent_folder)
  492. echo ' <TD WIDTH="25%"><B>'. _("To") .'</B>';
  493. else
  494. echo ' <TD WIDTH="25%"><B>'. _("From") .'</B>';
  495. ShowSortButton($sort, $mailbox, 2, 3);
  496. echo "</TD>\n";
  497. break;
  498. case 3: # date
  499. echo ' <TD NOWRAP WIDTH="5%"><B>'. _("Date") .'</B>';
  500. ShowSortButton($sort, $mailbox, 0, 1);
  501. echo "</TD>\n";
  502. break;
  503. case 4: # subject
  504. echo ' <TD><B>'. _("Subject") .'</B> ';
  505. ShowSortButton($sort, $mailbox, 4, 5);
  506. echo "</TD>\n";
  507. break;
  508. case 6: # size
  509. echo ' <TD WIDTH="5%"><b>' . _("Size")."</b></TD>\n";
  510. break;
  511. }
  512. }
  513. echo "</TR>\n";
  514. }
  515. function ShowSortButton($sort, $mailbox, $Up, $Down) {
  516. if ($sort != $Up && $sort != $Down) {
  517. $img = 'sort_none.gif';
  518. $which = $Up;
  519. } elseif ($sort == $Up) {
  520. $img = 'up_pointer.gif';
  521. $which = $Down;
  522. } else {
  523. $img = 'down_pointer.gif';
  524. $which = 6;
  525. }
  526. echo ' <a href="right_main.php?newsort=' . $which .
  527. '&startMessage=1&mailbox=' . urlencode($mailbox) .
  528. '"><IMG SRC="../images/' . $img .
  529. '" BORDER=0 WIDTH=12 HEIGHT=10></a>';
  530. }
  531. function ShowSelectAllLink($startMessage, $sort)
  532. {
  533. global $checkall, $PHP_SELF, $what, $where, $mailbox;
  534. // This code is from Philippe Mingo <mingo@rotedic.com>
  535. ?>
  536. <script language="JavaScript">
  537. <!--
  538. function CheckAll() {
  539. for (var i = 0; i < document.messageList.elements.length; i++) {
  540. if( document.messageList.elements[i].name.substr( 0, 3 ) == 'msg') {
  541. document.messageList.elements[i].checked =
  542. !(document.messageList.elements[i].checked);
  543. }
  544. }
  545. }
  546. window.document.write('<a href="#" onClick="CheckAll();"><?php echo
  547. _("Toggle All") ?></A>');
  548. //-->
  549. </script><noscript>
  550. <?PHP
  551. echo "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox) .
  552. "&startMessage=$startMessage&sort=$sort&checkall=";
  553. if (isset($checkall) && $checkall == '1')
  554. echo '0';
  555. else
  556. echo '1';
  557. if (isset($where) && isset($what))
  558. echo '&where=' . urlencode($where) . '&what=' . urlencode($what);
  559. echo "\">";
  560. if (isset($checkall) && $checkall == '1')
  561. echo _("Unselect All");
  562. else
  563. echo _("Select All");
  564. echo "</A>\n</noscript>\n";
  565. }
  566. function processSubject($subject)
  567. {
  568. // Shouldn't ever happen -- caught too many times in the IMAP functions
  569. if ($subject == '')
  570. return _("(no subject)");
  571. if (strlen($subject) <= 55)
  572. return $subject;
  573. $ent_strlen=strlen($subject);
  574. $trim_val=50;
  575. $ent_offset=0;
  576. // see if this is entities-encoded string
  577. // If so, Iterate through the whole string, find out
  578. // the real number of characters, and if more
  579. // than 55, substr with an updated trim value.
  580. while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false &&
  581. ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false)
  582. {
  583. $trim_val += ($ent_loc_end-$ent_loc)+1;
  584. $ent_strlen -= $ent_loc_end-$ent_loc;
  585. $ent_offset = $ent_loc_end+1;
  586. }
  587. if ($ent_strlen <= 55)
  588. return $subject;
  589. return substr($subject, 0, $trim_val) . '...';
  590. }
  591. ?>