mailbox_display.php 26 KB

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