mailbox_display.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937
  1. <?php
  2. /**
  3. * mailbox_display.php
  4. *
  5. * Copyright (c) 1999-2002 The SquirrelMail Project Team
  6. * Licensed under the GNU GPL. For full terms see the file COPYING.
  7. *
  8. * This contains functions that display mailbox information, such as the
  9. * table row that has sender, date, subject, etc...
  10. *
  11. * $Id$
  12. */
  13. require_once('../functions/strings.php');
  14. define('PG_SEL_MAX', 10); /* Default value for page_selector_max. */
  15. function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $start_msg, $where, $what) {
  16. global $checkall,
  17. $color, $msgs, $msort,
  18. $sent_folder, $draft_folder,
  19. $default_use_priority,
  20. $message_highlight_list,
  21. $index_order,
  22. $pos; /* Search postion (if any) */
  23. $color_string = $color[4];
  24. if ($GLOBALS['alt_index_colors']) {
  25. if (!isset($GLOBALS['row_count'])) {
  26. $GLOBALS['row_count'] = 0;
  27. }
  28. $GLOBALS['row_count']++;
  29. if ($GLOBALS['row_count'] % 2) {
  30. if (!isset($color[12])) {
  31. $color[12] = '#EAEAEA';
  32. }
  33. $color_string = $color[12];
  34. }
  35. }
  36. $msg = $msgs[$key];
  37. /**
  38. * This is done in case you're looking into Sent folders,
  39. * because you can have multi receiver.
  40. */
  41. $sendersName = split(',', $msg['FROM']);
  42. $senderName = '';
  43. for ($index = 0 ; $index < count($sendersName) ; $index++) {
  44. if ($senderName != '') {
  45. $senderName .= ', ';
  46. }
  47. $senderName .= sqimap_find_displayable_name($sendersName[$index]);
  48. }
  49. if( $mailbox == 'None' ) {
  50. // $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
  51. $boxes = sqimap_mailbox_list($imapConnection);
  52. // sqimap_logout($imapConnection);
  53. $mailbox = $boxes[0]['unformatted'];
  54. unset( $boxes );
  55. }
  56. $urlMailbox = urlencode($mailbox);
  57. $subject = processSubject($msg['SUBJECT']);
  58. echo "<TR>\n";
  59. if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
  60. $flag = "<font color=\"$color[2]\">";
  61. $flag_end = '</font>';
  62. } else {
  63. $flag = '';
  64. $flag_end = '';
  65. }
  66. if (!isset($msg['FLAG_SEEN']) || ($msg['FLAG_SEEN'] == false)) {
  67. $bold = '<b>';
  68. $bold_end = '</b>';
  69. } else {
  70. $bold = '';
  71. $bold_end = '';
  72. }
  73. if (handleAsSent($mailbox)) {
  74. $italic = '<i>';
  75. $italic_end = '</i>';
  76. } else {
  77. $italic = '';
  78. $italic_end = '';
  79. }
  80. if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
  81. $fontstr = "<font color=\"$color[9]\">";
  82. $fontstr_end = '</font>';
  83. } else {
  84. $fontstr = '';
  85. $fontstr_end = '';
  86. }
  87. for ($i=0; $i < count($message_highlight_list); $i++) {
  88. if (trim($message_highlight_list[$i]['value']) != '') {
  89. if ($message_highlight_list[$i]['match_type'] == 'to_cc') {
  90. if (strpos('^^'.strtolower($msg['TO']), strtolower($message_highlight_list[$i]['value'])) || strpos('^^'.strtolower($msg['CC']), strtolower($message_highlight_list[$i]['value']))) {
  91. $hlt_color = $message_highlight_list[$i]['color'];
  92. continue;
  93. }
  94. } else if (strpos('^^'.strtolower($msg[strtoupper($message_highlight_list[$i]['match_type'])]),strtolower($message_highlight_list[$i]['value']))) {
  95. $hlt_color = $message_highlight_list[$i]['color'];
  96. continue;
  97. }
  98. }
  99. }
  100. if (!isset($hlt_color)) {
  101. $hlt_color = $color_string;
  102. }
  103. if ($where && $what) {
  104. if( !isset( $pos ) || $pos == '' ) {
  105. $pos = '0';
  106. }
  107. $search_stuff = "&pos=" . urlencode( $pos ) . "&where=".urlencode($where).'&what='.urlencode($what);
  108. }
  109. $checked = ($checkall == 1 ?' checked' : '');
  110. for ($i=1; $i <= count($index_order); $i++) {
  111. switch ($index_order[$i]) {
  112. case 1: /* checkbox */
  113. echo " <td bgcolor=\"$hlt_color\" align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n";
  114. break;
  115. case 2: /* from */
  116. echo " <td bgcolor=\"$hlt_color\">$italic$bold$flag$fontstr$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n";
  117. break;
  118. case 3: /* date */
  119. echo " <td nowrap bgcolor=\"$hlt_color\"><center>$bold$flag$fontstr".$msg["DATE_STRING"]."$fontstr_end$flag_end$bold_end</center></td>\n";
  120. break;
  121. case 4: /* subject */
  122. echo " <td bgcolor=\"$hlt_color\">$bold";
  123. if (! isset($search_stuff)) { $search_stuff = ''; }
  124. echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$start_msg&show_more=0$search_stuff\"";
  125. do_hook("subject_link");
  126. if ($subject != $msg['SUBJECT']) {
  127. $title = get_html_translation_table(HTML_SPECIALCHARS);
  128. $title = array_flip($title);
  129. $title = strtr($msg['SUBJECT'], $title);
  130. $title = str_replace('"', "''", $title);
  131. echo " title=\"$title\"";
  132. }
  133. echo ">$flag$subject$flag_end</a>$bold_end</td>\n";
  134. break;
  135. case 5: /* flags */
  136. $stuff = false;
  137. echo " <td bgcolor=\"$hlt_color\" align=center nowrap><b><small>\n";
  138. if (isset($msg['FLAG_ANSWERED']) &&
  139. $msg['FLAG_ANSWERED'] == true) {
  140. echo "A\n";
  141. $stuff = true;
  142. }
  143. if ($msg['TYPE0'] == 'multipart') {
  144. echo "+\n";
  145. $stuff = true;
  146. }
  147. if ($default_use_priority) {
  148. if (ereg('(1|2)',substr($msg['PRIORITY'],0,1))) {
  149. echo "<font color=\"$color[1]\">!</font>\n";
  150. $stuff = true;
  151. }
  152. if (ereg('(5)',substr($msg['PRIORITY'],0,1))) {
  153. echo "<font color=\"$color[8]\">?</font>\n";
  154. $stuff = true;
  155. }
  156. }
  157. if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
  158. echo "<font color=\"$color[1]\">D</font>\n";
  159. $stuff = true;
  160. }
  161. if (!$stuff) {
  162. echo "&nbsp;\n";
  163. }
  164. echo "</small></b></td>\n";
  165. break;
  166. case 6: /* size */
  167. echo " <td bgcolor=\"$hlt_color\">$bold$fontstr" .
  168. show_readable_size($msg['SIZE']) .
  169. "$fontstr_end$bold_end</td>\n";
  170. break;
  171. }
  172. }
  173. echo "</tr>\n";
  174. }
  175. /**
  176. * This function loops through a group of messages in the mailbox
  177. * and shows them to the user.
  178. */
  179. function showMessagesForMailbox
  180. ($imapConnection, $mailbox, $num_msgs, $start_msg, $sort,
  181. $color, $show_num, $use_cache) {
  182. global $msgs, $msort;
  183. global $sent_folder, $draft_folder;
  184. global $message_highlight_list;
  185. global $auto_expunge;
  186. /* If autoexpunge is turned on, then do it now. */
  187. if ($auto_expunge == true) {
  188. sqimap_mailbox_expunge($imapConnection, $mailbox, false);
  189. }
  190. sqimap_mailbox_select($imapConnection, $mailbox);
  191. $issent = handleAsSent($mailbox);
  192. if (!$use_cache) {
  193. /* If it is sorted... */
  194. if ($num_msgs >= 1) {
  195. if ($sort < 6) {
  196. $id = range(1, $num_msgs);
  197. } else {
  198. // if it's not sorted
  199. if ($start_msg + ($show_num - 1) < $num_msgs) {
  200. $end_msg = $start_msg + ($show_num-1);
  201. } else {
  202. $end_msg = $num_msgs;
  203. }
  204. if ($end_msg < $start_msg) {
  205. $start_msg = $start_msg - $show_num;
  206. if ($start_msg < 1) {
  207. $start_msg = 1;
  208. }
  209. }
  210. $real_startMessage = $num_msgs - $start_msg + 1;
  211. $real_endMessage = $num_msgs - $start_msg - $show_num + 2;
  212. if ($real_endMessage <= 0) {
  213. $real_endMessage = 1;
  214. }
  215. $id = array_reverse(range($real_endMessage, $real_startMessage));
  216. }
  217. $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
  218. $flags = sqimap_get_flags_list($imapConnection, $id, $issent);
  219. foreach ($msgs_list as $hdr) {
  220. $from[] = $hdr->from;
  221. $date[] = $hdr->date;
  222. $subject[] = $hdr->subject;
  223. $to[] = $hdr->to;
  224. $priority[] = $hdr->priority;
  225. $cc[] = $hdr->cc;
  226. $size[] = $hdr->size;
  227. $type[] = $hdr->type0;
  228. }
  229. }
  230. $j = 0;
  231. if ($sort == 6) {
  232. $end = $start_msg + $show_num - 1;
  233. if ($num_msgs < $show_num) {
  234. $end_loop = $num_msgs;
  235. } else if ($end > $num_msgs) {
  236. $end_loop = $num_msgs - $start_msg + 1;
  237. } else {
  238. $end_loop = $show_num;
  239. }
  240. } else {
  241. $end = $num_msgs;
  242. $end_loop = $end;
  243. }
  244. while ($j < $end_loop) {
  245. if (isset($date[$j])) {
  246. $date[$j] = str_replace(' ', ' ', $date[$j]);
  247. $tmpdate = explode(' ', trim($date[$j]));
  248. } else {
  249. $tmpdate = $date = array('', '', '', '', '', '');
  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];
  263. # fix SUBJECT-SORT to remove Re:
  264. $re_abbr = /* Add more here! */
  265. 'vedr|sv|' . /* Danish */
  266. 're|aw'; /* English */
  267. if (eregi( "^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs)) {
  268. $messages[$j]['SUBJECT-SORT'] = $regs[2];
  269. }
  270. $num = 0;
  271. while ($num < count($flags[$j])) {
  272. if ($flags[$j][$num] == 'Deleted') {
  273. $messages[$j]['FLAG_DELETED'] = true;
  274. } else if ($flags[$j][$num] == 'Answered') {
  275. $messages[$j]['FLAG_ANSWERED'] = true;
  276. } else if ($flags[$j][$num] == 'Seen') {
  277. $messages[$j]['FLAG_SEEN'] = true;
  278. } else if ($flags[$j][$num] == 'Flagged') {
  279. $messages[$j]['FLAG_FLAGGED'] = true;
  280. }
  281. $num++;
  282. }
  283. $j++;
  284. }
  285. /* Only ignore messages flagged as deleted if we are using a
  286. * trash folder or auto_expunge */
  287. if (((isset($move_to_trash) && $move_to_trash)
  288. || (isset($auto_expunge) && $auto_expunge)) && $sort != 6) {
  289. /** Find and remove the ones that are deleted */
  290. $i = 0;
  291. $j = 0;
  292. while ($j < $num_msgs) {
  293. if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) {
  294. $j++;
  295. continue;
  296. }
  297. $msgs[$i] = $messages[$j];
  298. $i++;
  299. $j++;
  300. }
  301. $num_msgs = $i;
  302. } else {
  303. if (!isset($messages)) {
  304. $messages = array();
  305. }
  306. $msgs = $messages;
  307. }
  308. }
  309. // There's gotta be messages in the array for it to sort them.
  310. if ($num_msgs > 0 && ! $use_cache) {
  311. /** 0 = Date (up) 4 = Subject (up)
  312. ** 1 = Date (dn) 5 = Subject (dn)
  313. ** 2 = Name (up)
  314. ** 3 = Name (dn)
  315. **/
  316. session_unregister("msgs");
  317. if (($sort == 0) || ($sort == 1))
  318. $msort = array_cleave ($msgs, 'TIME_STAMP');
  319. elseif (($sort == 2) || ($sort == 3))
  320. $msort = array_cleave ($msgs, 'FROM-SORT');
  321. elseif (($sort == 4) || ($sort == 5))
  322. $msort = array_cleave ($msgs, 'SUBJECT-SORT');
  323. else // ($sort == 6)
  324. $msort = $msgs;
  325. if ($sort < 6) {
  326. if ($sort % 2) {
  327. asort($msort);
  328. } else {
  329. arsort($msort);
  330. }
  331. }
  332. session_register('msort');
  333. }
  334. displayMessageArray($imapConnection, $num_msgs, $start_msg, $msgs, $msort, $mailbox, $sort, $color,$show_num);
  335. session_register('msgs');
  336. }
  337. /**
  338. * Generic function to convert the msgs array into an HTML table.
  339. */
  340. function displayMessageArray($imapConnection, $num_msgs, $start_msg, &$msgs, $msort, $mailbox, $sort, $color, $show_num) {
  341. global $folder_prefix, $sent_folder;
  342. global $imapServerAddress, $data_dir, $username, $use_mailbox_cache;
  343. global $index_order, $real_endMessage, $real_startMessage, $checkall;
  344. /* If cache isn't already set, do it now. */
  345. if (!session_is_registered('msgs')) { session_register('msgs'); }
  346. if (!session_is_registered('msort')) { session_register('msort'); }
  347. if ($start_msg + ($show_num - 1) < $num_msgs) {
  348. $end_msg = $start_msg + ($show_num-1);
  349. } else {
  350. $end_msg = $num_msgs;
  351. }
  352. if ($end_msg < $start_msg) {
  353. $start_msg = $start_msg - $show_num;
  354. if ($start_msg < 1) { $start_msg = 1; }
  355. }
  356. $urlMailbox = urlencode($mailbox);
  357. do_hook('mailbox_index_before');
  358. $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
  359. $paginator_str = get_paginator_str
  360. ($urlMailbox, $start_msg, $end_msg, $num_msgs, $show_num, $sort);
  361. if (! isset($msg)) {
  362. $msg = '';
  363. }
  364. mail_message_listing_beginning( $imapConnection,
  365. "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$start_msg",
  366. $mailbox, $sort, $msg_cnt_str, $paginator_str, $start_msg);
  367. $groupNum = $start_msg % ($show_num - 1);
  368. $real_startMessage = $start_msg;
  369. if ($sort == 6) {
  370. if ($end_msg - $start_msg < $show_num - 1) {
  371. $end_msg = $end_msg - $start_msg + 1;
  372. $start_msg = 1;
  373. } else if ($start_msg > $show_num) {
  374. $end_msg = $show_num;
  375. $start_msg = 1;
  376. }
  377. }
  378. $endVar = $end_msg + 1;
  379. /* Loop through and display the info for each message. */
  380. $t = 0; // $t is used for the checkbox number
  381. if ($num_msgs == 0) { // if there's no messages in this folder
  382. echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order) . ">\n".
  383. " <CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR>&nbsp;</CENTER>\n".
  384. "</TD></TR>";
  385. } elseif ($start_msg == $end_msg) {
  386. /* If there's only one message in the box, handle it differently. */
  387. if ($sort != 6) {
  388. $i = $start_msg;
  389. } else {
  390. $i = 1;
  391. }
  392. reset($msort);
  393. $k = 0;
  394. do {
  395. $key = key($msort);
  396. next($msort);
  397. $k++;
  398. } while (isset ($key) && ($k < $i));
  399. printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
  400. } else {
  401. $i = $start_msg;
  402. reset($msort);
  403. $k = 0;
  404. do {
  405. $key = key($msort);
  406. next($msort);
  407. $k++;
  408. } while (isset ($key) && ($k < $i));
  409. do {
  410. printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
  411. $key = key($msort);
  412. $t++;
  413. $i++;
  414. next($msort);
  415. } while ($i && $i < $endVar);
  416. }
  417. echo '</table>'.
  418. "<table bgcolor=\"$color[9]\" width=\"100%\" border=0 cellpadding=1 cellspacing=1>" .
  419. "<tr BGCOLOR=\"$color[4]\"><td>" .
  420. "<table width=\"100%\" BGCOLOR=\"$color[4]\" border=0 cellpadding=1 cellspacing=0><tr><td>$paginator_str</td>".
  421. "<td align=right>$msg_cnt_str</td></tr></table>".
  422. "</td></tr>".
  423. "</table>";
  424. /** End of message-list table */
  425. do_hook('mailbox_index_after');
  426. echo "</TABLE></FORM>\n";
  427. }
  428. /**
  429. * Displays the standard message list header. To finish the table,
  430. * you need to do a "</table></table>";
  431. *
  432. * $moveURL is the URL to submit the delete/move form to
  433. * $mailbox is the current mailbox
  434. * $sort is the current sorting method (-1 for no sorting available [searches])
  435. * $Message is a message that is centered on top of the list
  436. * $More is a second line that is left aligned
  437. */
  438. function mail_message_listing_beginning
  439. ($imapConnection, $moveURL, $mailbox = '', $sort = -1,
  440. $msg_cnt_str = '', $paginator = '&nbsp;', $start_msg = 1) {
  441. global $color, $index_order, $auto_expunge, $move_to_trash;
  442. global $checkall, $sent_folder, $draft_folder;
  443. $urlMailbox = urlencode($mailbox);
  444. /*
  445. * This is the beginning of the message list table.
  446. * It wraps around all messages
  447. */
  448. echo "<FORM name=messageList method=post action=\"$moveURL\">\n"
  449. . "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"0\">\n"
  450. . "<TR BGCOLOR=\"$color[0]\"><TD>"
  451. . " <TABLE BGCOLOR=\"$color[4]\" width=\"100%\" CELLPADDING=\"2\" CELLSPACING=\"0\" BORDER=\"0\"><TR>\n"
  452. . " <TD ALIGN=LEFT>$paginator</TD>\n"
  453. . " <TD ALIGN=RIGHT>$msg_cnt_str</TD>\n"
  454. . " </TR></TABLE>\n"
  455. . '</TD></TR>'
  456. . "<TR><TD BGCOLOR=\"$color[0]\">\n"
  457. . "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=\"100%\">\n"
  458. . " <TR>\n"
  459. . " <TD ALIGN=LEFT VALIGN=MIDDLE NOWRAP>\n"
  460. . ' <SMALL>&nbsp;' . _("Move Selected To:") . "</SMALL>\n"
  461. . " </TD>\n"
  462. . " <TD ALIGN=RIGHT NOWRAP>\n"
  463. . ' <SMALL>&nbsp;' . _("Transform Selected Messages") . ": &nbsp; </SMALL><BR>\n"
  464. . " </TD>\n"
  465. . " </TR>\n"
  466. . " <TR>\n"
  467. . " <TD ALIGN=LEFT VALIGN=MIDDLE NOWRAP>\n"
  468. . ' <SMALL>&nbsp;<TT><SELECT NAME="targetMailbox">';
  469. $boxes = sqimap_mailbox_list($imapConnection);
  470. for ($i = 0; $i < count($boxes); $i++) {
  471. if (!in_array("noselect", $boxes[$i]['flags'])) {
  472. $box = $boxes[$i]['unformatted'];
  473. $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
  474. echo " <OPTION VALUE=\"$box\">$box2</option>\n";
  475. }
  476. }
  477. echo ' </SELECT></TT>&nbsp;'.
  478. "<INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"" . _("Move") . "\"></SMALL>\n".
  479. " </TD>\n".
  480. " <TD ALIGN=RIGHT NOWRAP>&nbsp;&nbsp;&nbsp;\n";
  481. if (!$auto_expunge) {
  482. echo ' <INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'">&nbsp;'. _("mailbox") ."&nbsp;\n";
  483. }
  484. echo " <INPUT TYPE=SUBMIT NAME=\"markRead\" VALUE=\"". _("Read")."\">\n".
  485. " <INPUT TYPE=SUBMIT NAME=\"markUnread\" VALUE=\"". _("Unread")."\">\n".
  486. " <INPUT TYPE=SUBMIT VALUE=\"". _("Delete") . "\">&nbsp;\n".
  487. " </TD>\n".
  488. " </TR>\n".
  489. "</TABLE>\n";
  490. do_hook('mailbox_form_before');
  491. echo '</TD></TR>'.
  492. "<TR><TD BGCOLOR=\"$color[0]\">".
  493. "<TABLE WIDTH=\"100%\" BORDER=0 CELLPADDING=2 CELLSPACING=";
  494. if ($GLOBALS['alt_index_colors']) {
  495. echo "0";
  496. } else {
  497. echo "1";
  498. }
  499. echo " BGCOLOR=\"$color[0]\">".
  500. "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
  501. /* Print the headers. */
  502. for ($i=1; $i <= count($index_order); $i++) {
  503. switch ($index_order[$i]) {
  504. case 1: /* checkbox */
  505. case 5: /* flags */
  506. echo ' <TD WIDTH="1%"><B>&nbsp;</B></TD>';
  507. break;
  508. case 2: /* from */
  509. if (handleAsSent($mailbox)) {
  510. echo ' <TD WIDTH="25%"><B>'. _("To") .'</B>';
  511. } else {
  512. echo ' <TD WIDTH="25%"><B>'. _("From") .'</B>';
  513. }
  514. ShowSortButton($sort, $mailbox, 2, 3);
  515. echo "</TD>\n";
  516. break;
  517. case 3: /* date */
  518. echo ' <TD NOWRAP WIDTH="5%"><B>'. _("Date") .'</B>';
  519. ShowSortButton($sort, $mailbox, 0, 1);
  520. echo "</TD>\n";
  521. break;
  522. case 4: /* subject */
  523. echo ' <TD><B>'. _("Subject") .'</B> ';
  524. ShowSortButton($sort, $mailbox, 4, 5);
  525. echo "</TD>\n";
  526. break;
  527. case 6: /* size */
  528. echo ' <TD WIDTH="5%"><b>' . _("Size")."</b></TD>\n";
  529. break;
  530. }
  531. }
  532. echo "</TR>\n";
  533. }
  534. /*
  535. * This function shows the sort button. Isn't this a good comment?
  536. */
  537. function ShowSortButton($sort, $mailbox, $Up, $Down) {
  538. /* Figure out which image we want to use. */
  539. if ($sort != $Up && $sort != $Down) {
  540. $img = 'sort_none.png';
  541. $which = $Up;
  542. } elseif ($sort == $Up) {
  543. $img = 'up_pointer.png';
  544. $which = $Down;
  545. } else {
  546. $img = 'down_pointer.png';
  547. $which = 6;
  548. }
  549. /* Now that we have everything figured out, show the actual button. */
  550. echo ' <a href="right_main.php?newsort=' . $which .
  551. '&startMessage=1&mailbox=' . urlencode($mailbox) .
  552. '"><IMG SRC="../images/' . $img .
  553. '" BORDER=0 WIDTH=12 HEIGHT=10></a>';
  554. }
  555. function get_selectall_link($start_msg, $sort) {
  556. global $checkall, $what, $where, $mailbox, $javascript_on;
  557. global $PHP_SELF, $PG_SHOWNUM;
  558. if ($javascript_on) {
  559. $result =
  560. '<script language="JavaScript">' .
  561. "\n<!-- \n" .
  562. "function CheckAll() {\n" .
  563. " for (var i = 0; i < document.messageList.elements.length; i++) {\n" .
  564. " if( document.messageList.elements[i].type == 'checkbox' ) {\n" .
  565. " document.messageList.elements[i].checked = !(document.messageList.elements[i].checked);\n".
  566. " }\n" .
  567. " }\n" .
  568. "}\n" .
  569. "//-->\n" .
  570. '</script><a href="#" onClick="CheckAll();">' . _("Toggle All") . "</a>\n";
  571. } else {
  572. $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
  573. . "&startMessage=$start_msg&sort=$sort&checkall=";
  574. if (isset($checkall) && $checkall == '1') {
  575. $result .= '0';
  576. } else {
  577. $result .= '1';
  578. }
  579. if (isset($where) && isset($what)) {
  580. $result .= '&where=' . urlencode($where)
  581. . '&what=' . urlencode($what);
  582. }
  583. if ($PG_SHOWNUM == 999999) {
  584. $result .= '&PG_SHOWNUM=999999';
  585. }
  586. $result .= "\">";
  587. if (isset($checkall) && ($checkall == '1')) {
  588. $result .= _("Unselect All");
  589. } else {
  590. $result .= _("Select All");
  591. }
  592. $result .= "</A>\n";
  593. }
  594. /* Return our final result. */
  595. return ($result);
  596. }
  597. /**
  598. * This function computes the "Viewing Messages..." string.
  599. */
  600. function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
  601. /* Compute the $msg_cnt_str. */
  602. $result = '';
  603. if ($start_msg < $end_msg) {
  604. $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"), $start_msg, $end_msg, $num_msgs);
  605. } else if ($start_msg == $end_msg) {
  606. $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
  607. } else {
  608. $result = '<br>';
  609. }
  610. /* Return our result string. */
  611. return ($result);
  612. }
  613. /**
  614. * Generate a paginator link.
  615. */
  616. function get_paginator_link
  617. ($box, $start_msg, $use, $text) {
  618. $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
  619. . "&startMessage=$start_msg&mailbox=$box\" "
  620. . "TARGET=\"right\">$text</A>";
  621. return ($result);
  622. }
  623. /**
  624. * This function computes the paginator string.
  625. */
  626. function get_paginator_str
  627. ($box, $start_msg, $end_msg, $num_msgs, $show_num, $sort) {
  628. global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
  629. /* Initialize paginator string chunks. */
  630. $prv_str = '';
  631. $nxt_str = '';
  632. $pg_str = '';
  633. $all_str = '';
  634. $tgl_str = '';
  635. /* Create simple strings that will be creating the paginator. */
  636. $spc = '&nbsp;'; /* This will be used as a space. */
  637. $sep = '|'; /* This will be used as a seperator. */
  638. /* Get some paginator preference values. */
  639. $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON);
  640. $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX);
  641. /* Make sure that our start message number is not too big. */
  642. $start_msg = min($start_msg, $num_msgs);
  643. /* Decide whether or not we will use the mailbox cache. */
  644. /* Not sure why $use_mailbox_cache is even passed in. */
  645. if ($sort == 6) {
  646. $use = 0;
  647. } else {
  648. $use = 1;
  649. }
  650. /* Compute the starting message of the previous and next page group. */
  651. $next_grp = $start_msg + $show_num;
  652. $prev_grp = $start_msg - $show_num;
  653. /* Compute the basic previous and next strings. */
  654. if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
  655. $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
  656. $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
  657. } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
  658. $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
  659. $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
  660. } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
  661. $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
  662. $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
  663. }
  664. /* Page selector block. Following code computes page links. */
  665. if ($pg_sel && ($num_msgs > $show_num)) {
  666. /* Most importantly, what is the current page!!! */
  667. $cur_pg = intval($start_msg / $show_num) + 1;
  668. /* Compute total # of pages and # of paginator page links. */
  669. $tot_pgs = ceil($num_msgs / $show_num); /* Total # of Pages */
  670. $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
  671. /************************************************************/
  672. /* Compute the size of the four quarters of the page links. */
  673. /************************************************************/
  674. /* If we can, just show all the pages. */
  675. if (($tot_pgs - 1) <= $pg_max) {
  676. $q1_pgs = $cur_pg - 1;
  677. $q2_pgs = $q3_pgs = 0;
  678. $q4_pgs = $tot_pgs - $cur_pg;
  679. /* Otherwise, compute some magic to choose the four quarters. */
  680. } else {
  681. /* Compute the magic base values. Added together, */
  682. /* these values will always equal to the $pag_pgs. */
  683. /* NOTE: These are DEFAULT values and do not take */
  684. /* the current page into account. That is below. */
  685. $q1_pgs = floor($vis_pgs/4);
  686. $q2_pgs = round($vis_pgs/4, 0);
  687. $q3_pgs = ceil($vis_pgs/4);
  688. $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
  689. /* Adjust if the first quarter contains the current page. */
  690. if (($cur_pg - $q1_pgs) < 1) {
  691. $extra_pgs = ($q1_pgs - ($cur_pg - 1)) + $q2_pgs;
  692. $q1_pgs = $cur_pg - 1;
  693. $q2_pgs = 0;
  694. $q3_pgs += ceil($extra_pgs / 2);
  695. $q4_pgs += floor($extra_pgs / 2);
  696. /* Adjust if the first and second quarters intersect. */
  697. } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
  698. $extra_pgs = $q2_pgs;
  699. $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
  700. $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
  701. $q3_pgs += ceil($extra_pgs / 2);
  702. $q4_pgs += floor($extra_pgs / 2);
  703. /* Adjust if the fourth quarter contains the current page. */
  704. } else if (($cur_pg + $q4_pgs) >= $tot_pgs) {
  705. $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) + $q3_pgs;
  706. $q3_pgs = 0;
  707. $q4_pgs = $tot_pgs - $cur_pg;
  708. $q1_pgs += floor($extra_pgs / 2);
  709. $q2_pgs += ceil($extra_pgs / 2);
  710. /* Adjust if the third and fourth quarter intersect. */
  711. } else if (($cur_pg + $q3_pgs + 1) >= ($tot_pgs - $q4_pgs + 1)) {
  712. $extra_pgs = $q3_pgs;
  713. $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
  714. $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
  715. $q1_pgs += floor($extra_pgs / 2);
  716. $q2_pgs += ceil($extra_pgs / 2);
  717. }
  718. }
  719. /* I am leaving this debug code here, commented out, because */
  720. /* it is a really nice way to see what the above code is doing. */
  721. /* echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = " */
  722. /* . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>'; */
  723. /************************************************************/
  724. /* Print out the page links from the compute page quarters. */
  725. /************************************************************/
  726. /* Start with the first quarter. */
  727. if (($q1_pgs == 0) && ($cur_pg > 1)) {
  728. $pg_str .= "...$spc";
  729. } else {
  730. for ($pg = 1; $pg <= $q1_pgs; ++$pg) {
  731. $start = (($pg-1) * $show_num) + 1;
  732. $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  733. }
  734. if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
  735. $pg_str .= "...$spc";
  736. }
  737. }
  738. /* Continue with the second quarter. */
  739. for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++$pg) {
  740. $start = (($pg-1) * $show_num) + 1;
  741. $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  742. }
  743. /* Now print the current page. */
  744. $pg_str .= $cur_pg . $spc;
  745. /* Next comes the third quarter. */
  746. for ($pg = $cur_pg + 1; $pg <= $cur_pg + $q3_pgs; ++$pg) {
  747. $start = (($pg-1) * $show_num) + 1;
  748. $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  749. }
  750. /* And last, print the forth quarter page links. */
  751. if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
  752. $pg_str .= "...$spc";
  753. } else {
  754. if (($tot_pgs - $q4_pgs) > ($cur_pg + $q3_pgs)) {
  755. $pg_str .= "...$spc";
  756. }
  757. for ($pg = $tot_pgs - $q4_pgs + 1; $pg <= $tot_pgs; ++$pg) {
  758. $start = (($pg-1) * $show_num) + 1;
  759. $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  760. }
  761. }
  762. } else if ($PG_SHOWNUM == 999999) {
  763. $pg_str = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
  764. . "&startMessage=1&mailbox=$box\" TARGET=\"right\">"
  765. . _("Paginate") . '</A>' . $spc;
  766. }
  767. /* If necessary, compute the 'show all' string. */
  768. if (($prv_str != '') || ($nxt_str != '')) {
  769. $all_str = "<A HREF=\"right_main.php?PG_SHOWNUM=999999"
  770. . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
  771. . "TARGET=\"right\">" . _("Show All") . '</A>';
  772. }
  773. /* Last but not least, get the value for the toggle all link. */
  774. $tgl_str = get_selectall_link($start_msg, $sort);
  775. /* Put all the pieces of the paginator string together. */
  776. $result = '';
  777. $result .= ($prv_str != '' ? $prv_str . $spc . $sep . $spc : '');
  778. $result .= ($nxt_str != '' ? $nxt_str . $spc . $sep . $spc : '');
  779. $result .= ($pg_str != '' ? $pg_str : '');
  780. $result .= ($all_str != '' ? $sep . $spc . $all_str . $spc : '');
  781. $result .= ($result != '' ? $sep . $spc . $tgl_str: $tgl_str);
  782. /* If the resulting string is blank, return a non-breaking space. */
  783. if ($result == '') {
  784. $result = '&nbsp;';
  785. }
  786. /* Return our final magical paginator string. */
  787. return ($result);
  788. }
  789. function processSubject($subject) {
  790. // Shouldn't ever happen -- caught too many times in the IMAP functions
  791. if ($subject == '')
  792. return _("(no subject)");
  793. if (strlen($subject) <= 55)
  794. return $subject;
  795. $ent_strlen=strlen($subject);
  796. $trim_val=50;
  797. $ent_offset=0;
  798. // see if this is entities-encoded string
  799. // If so, Iterate through the whole string, find out
  800. // the real number of characters, and if more
  801. // than 55, substr with an updated trim value.
  802. while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false &&
  803. ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false)
  804. {
  805. $trim_val += ($ent_loc_end-$ent_loc)+1;
  806. $ent_strlen -= $ent_loc_end-$ent_loc;
  807. $ent_offset = $ent_loc_end+1;
  808. }
  809. if ($ent_strlen <= 55)
  810. return $subject;
  811. return substr($subject, 0, $trim_val) . '...';
  812. }
  813. function handleAsSent($mailbox) {
  814. global $sent_folder, $draft_folder;
  815. global $handleAsSent_result;
  816. /* First check if this is the sent or draft folder. */
  817. $handleAsSent_result = (($mailbox == $sent_folder)
  818. || ($mailbox == $draft_folder));
  819. /* Then check the result of the handleAsSent hook. */
  820. do_hook('check_handleAsSent_result', $mailbox);
  821. /* And return the result. */
  822. return ($handleAsSent_result);
  823. }
  824. ?>