mailbox_display.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948
  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 = "&amp;pos=" . urlencode( $pos ) . "&amp;where=".urlencode($where).'&amp;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&amp;passed_id=".$msg["ID"]."&amp;startMessage=$start_msg&amp;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($imapConnection, $mailbox, $num_msgs, $start_msg, $sort,
  180. $color, $show_num, $use_cache) {
  181. global $msgs, $msort,
  182. $sent_folder, $draft_folder,
  183. $message_highlight_list,
  184. $auto_expunge;
  185. /* If autoexpunge is turned on, then do it now. */
  186. if ($auto_expunge == true) {
  187. sqimap_mailbox_expunge($imapConnection, $mailbox, false);
  188. }
  189. sqimap_mailbox_select($imapConnection, $mailbox);
  190. $issent = handleAsSent($mailbox);
  191. if (!$use_cache) {
  192. /* If it is sorted... */
  193. if ($num_msgs >= 1) {
  194. if ($sort < 6) {
  195. $id = range(1, $num_msgs);
  196. } else {
  197. // if it's not sorted
  198. if ($start_msg + ($show_num - 1) < $num_msgs) {
  199. $end_msg = $start_msg + ($show_num-1);
  200. } else {
  201. $end_msg = $num_msgs;
  202. }
  203. if ($end_msg < $start_msg) {
  204. $start_msg = $start_msg - $show_num;
  205. if ($start_msg < 1) {
  206. $start_msg = 1;
  207. }
  208. }
  209. $real_startMessage = $num_msgs - $start_msg + 1;
  210. $real_endMessage = $num_msgs - $start_msg - $show_num + 2;
  211. if ($real_endMessage <= 0) {
  212. $real_endMessage = 1;
  213. }
  214. $id = array_reverse(range($real_endMessage, $real_startMessage));
  215. }
  216. $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
  217. $flags = sqimap_get_flags_list($imapConnection, $id, $issent);
  218. foreach ($msgs_list as $hdr) {
  219. $from[] = $hdr->from;
  220. $date[] = $hdr->date;
  221. $subject[] = $hdr->subject;
  222. $to[] = $hdr->to;
  223. $priority[] = $hdr->priority;
  224. $cc[] = $hdr->cc;
  225. $size[] = $hdr->size;
  226. $type[] = $hdr->type0;
  227. }
  228. }
  229. $j = 0;
  230. if ($sort == 6) {
  231. $end = $start_msg + $show_num - 1;
  232. if ($num_msgs < $show_num) {
  233. $end_loop = $num_msgs;
  234. } else if ($end > $num_msgs) {
  235. $end_loop = $num_msgs - $start_msg + 1;
  236. } else {
  237. $end_loop = $show_num;
  238. }
  239. } else {
  240. $end = $num_msgs;
  241. $end_loop = $end;
  242. }
  243. while ($j < $end_loop) {
  244. if (isset($date[$j])) {
  245. $date[$j] = str_replace(' ', ' ', $date[$j]);
  246. $tmpdate = explode(' ', trim($date[$j]));
  247. } else {
  248. $tmpdate = $date = array('', '', '', '', '', '');
  249. }
  250. $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
  251. $messages[$j]['DATE_STRING'] = getDateString($messages[$j]['TIME_STAMP']);
  252. $messages[$j]['ID'] = $id[$j];
  253. $messages[$j]['FROM'] = decodeHeader($from[$j]);
  254. $messages[$j]['FROM-SORT'] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
  255. $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
  256. $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
  257. $messages[$j]['TO'] = decodeHeader($to[$j]);
  258. $messages[$j]['PRIORITY'] = $priority[$j];
  259. $messages[$j]['CC'] = $cc[$j];
  260. $messages[$j]['SIZE'] = $size[$j];
  261. $messages[$j]['TYPE0'] = $type[$j];
  262. # fix SUBJECT-SORT to remove Re:
  263. $re_abbr = /* Add more here! */
  264. 'vedr|sv|' . /* Danish */
  265. 're|aw'; /* English */
  266. if (eregi( "^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs)) {
  267. $messages[$j]['SUBJECT-SORT'] = $regs[2];
  268. }
  269. $num = 0;
  270. while ($num < count($flags[$j])) {
  271. if ($flags[$j][$num] == 'Deleted') {
  272. $messages[$j]['FLAG_DELETED'] = true;
  273. } else if ($flags[$j][$num] == 'Answered') {
  274. $messages[$j]['FLAG_ANSWERED'] = true;
  275. } else if ($flags[$j][$num] == 'Seen') {
  276. $messages[$j]['FLAG_SEEN'] = true;
  277. } else if ($flags[$j][$num] == 'Flagged') {
  278. $messages[$j]['FLAG_FLAGGED'] = true;
  279. }
  280. $num++;
  281. }
  282. $j++;
  283. }
  284. /* Only ignore messages flagged as deleted if we are using a
  285. * trash folder or auto_expunge */
  286. if (((isset($move_to_trash) && $move_to_trash)
  287. || (isset($auto_expunge) && $auto_expunge)) && $sort != 6) {
  288. /** Find and remove the ones that are deleted */
  289. $i = 0;
  290. $j = 0;
  291. while ($j < $num_msgs) {
  292. if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) {
  293. $j++;
  294. continue;
  295. }
  296. $msgs[$i] = $messages[$j];
  297. $i++;
  298. $j++;
  299. }
  300. $num_msgs = $i;
  301. } else {
  302. if (!isset($messages)) {
  303. $messages = array();
  304. }
  305. $msgs = $messages;
  306. }
  307. }
  308. // There's gotta be messages in the array for it to sort them.
  309. if ($num_msgs > 0 && ! $use_cache) {
  310. /** 0 = Date (up) 4 = Subject (up)
  311. ** 1 = Date (dn) 5 = Subject (dn)
  312. ** 2 = Name (up)
  313. ** 3 = Name (dn)
  314. **/
  315. session_unregister('msgs');
  316. if (($sort == 0) || ($sort == 1)) {
  317. $msort = array_cleave ($msgs, 'TIME_STAMP');
  318. } elseif (($sort == 2) || ($sort == 3)) {
  319. $msort = array_cleave ($msgs, 'FROM-SORT');
  320. } elseif (($sort == 4) || ($sort == 5)) {
  321. $msort = array_cleave ($msgs, 'SUBJECT-SORT');
  322. } else { // ($sort == 6)
  323. $msort = $msgs;
  324. }
  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&amp;mailbox=$urlMailbox&amp;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. if( $box2 == 'INBOX' ) {
  475. $box2 = _("INBOX");
  476. }
  477. echo " <OPTION VALUE=\"$box\">$box2</option>\n";
  478. }
  479. }
  480. echo ' </SELECT></TT>&nbsp;'.
  481. "<INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"" . _("Move") . '">&nbsp;'.
  482. "<INPUT TYPE=SUBMIT NAME=\"attache\" VALUE=\"". _("Forward") . "\">&nbsp;\n"."</SMALL>\n".
  483. " </TD>\n".
  484. " <TD ALIGN=RIGHT NOWRAP>\n";
  485. if (!$auto_expunge) {
  486. echo ' <INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'">&nbsp;'. _("mailbox") ."&nbsp;\n";
  487. }
  488. echo " <INPUT TYPE=SUBMIT NAME=\"markRead\" VALUE=\"". _("Read")."\">\n".
  489. " <INPUT TYPE=SUBMIT NAME=\"markUnread\" VALUE=\"". _("Unread")."\">\n".
  490. " <INPUT TYPE=SUBMIT VALUE=\"". _("Delete") . "\">&nbsp;\n".
  491. " </TD>\n".
  492. " </TR>\n".
  493. "</TABLE>\n";
  494. do_hook('mailbox_form_before');
  495. echo '</TD></TR>'.
  496. "<TR><TD BGCOLOR=\"$color[0]\">".
  497. '<TABLE WIDTH="100%" BORDER=0 CELLPADDING=2 CELLSPACING=';
  498. if ($GLOBALS['alt_index_colors']) {
  499. echo '0';
  500. } else {
  501. echo '1';
  502. }
  503. echo " BGCOLOR=\"$color[0]\">".
  504. "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
  505. /* Print the headers. */
  506. for ($i=1; $i <= count($index_order); $i++) {
  507. switch ($index_order[$i]) {
  508. case 1: /* checkbox */
  509. case 5: /* flags */
  510. echo ' <TD WIDTH="1%"><B>&nbsp;</B></TD>';
  511. break;
  512. case 2: /* from */
  513. if (handleAsSent($mailbox)) {
  514. echo ' <TD WIDTH="25%"><B>'. _("To") .'</B>';
  515. } else {
  516. echo ' <TD WIDTH="25%"><B>'. _("From") .'</B>';
  517. }
  518. ShowSortButton($sort, $mailbox, 2, 3);
  519. echo "</TD>\n";
  520. break;
  521. case 3: /* date */
  522. echo ' <TD NOWRAP WIDTH="5%"><B>'. _("Date") .'</B>';
  523. ShowSortButton($sort, $mailbox, 0, 1);
  524. echo "</TD>\n";
  525. break;
  526. case 4: /* subject */
  527. echo ' <TD><B>'. _("Subject") .'</B> ';
  528. ShowSortButton($sort, $mailbox, 4, 5);
  529. echo "</TD>\n";
  530. break;
  531. case 6: /* size */
  532. echo ' <TD WIDTH="5%"><b>' . _("Size")."</b></TD>\n";
  533. break;
  534. }
  535. }
  536. echo "</TR>\n";
  537. }
  538. /*
  539. * This function shows the sort button. Isn't this a good comment?
  540. */
  541. function ShowSortButton($sort, $mailbox, $Up, $Down) {
  542. /* Figure out which image we want to use. */
  543. if ($sort != $Up && $sort != $Down) {
  544. $img = 'sort_none.png';
  545. $which = $Up;
  546. } elseif ($sort == $Up) {
  547. $img = 'up_pointer.png';
  548. $which = $Down;
  549. } else {
  550. $img = 'down_pointer.png';
  551. $which = 6;
  552. }
  553. /* Now that we have everything figured out, show the actual button. */
  554. echo ' <a href="right_main.php?newsort=' . $which .
  555. '&amp;startMessage=1&amp;mailbox=' . urlencode($mailbox) .
  556. '"><IMG SRC="../images/' . $img .
  557. '" BORDER=0 WIDTH=12 HEIGHT=10></a>';
  558. }
  559. function get_selectall_link($start_msg, $sort) {
  560. global $checkall, $what, $where, $mailbox, $javascript_on;
  561. global $PHP_SELF, $PG_SHOWNUM;
  562. $result = '';
  563. if ($javascript_on) {
  564. $result =
  565. '<script language="JavaScript" type="text/javascript">' .
  566. "\n<!-- \n" .
  567. "function CheckAll() {\n" .
  568. " for (var i = 0; i < document.messageList.elements.length; i++) {\n" .
  569. " if( document.messageList.elements[i].type == 'checkbox' ) {\n" .
  570. " document.messageList.elements[i].checked = !(document.messageList.elements[i].checked);\n".
  571. " }\n" .
  572. " }\n" .
  573. "}\n" .
  574. "//-->\n" .
  575. '</script><a href="#" onClick="CheckAll();">' . _("Toggle All") . "</a>\n";
  576. } else {
  577. if (strpos($PHP_SELF, "?")) {
  578. $result .= "<a href=\"$PHP_SELF&amp;mailbox=" . urlencode($mailbox)
  579. . "&amp;startMessage=$start_msg&amp;sort=$sort&amp;checkall=";
  580. }
  581. else {
  582. $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
  583. . "&amp;startMessage=$start_msg&amp;sort=$sort&amp;checkall=";
  584. }
  585. if (isset($checkall) && $checkall == '1') {
  586. $result .= '0';
  587. } else {
  588. $result .= '1';
  589. }
  590. if (isset($where) && isset($what)) {
  591. $result .= '&amp;where=' . urlencode($where)
  592. . '&amp;what=' . urlencode($what);
  593. }
  594. if ($PG_SHOWNUM == 999999) {
  595. $result .= '&amp;PG_SHOWNUM=999999';
  596. }
  597. $result .= "\">";
  598. if (isset($checkall) && ($checkall == '1')) {
  599. $result .= _("Unselect All");
  600. } else {
  601. $result .= _("Select All");
  602. }
  603. $result .= "</A>\n";
  604. }
  605. /* Return our final result. */
  606. return ($result);
  607. }
  608. /**
  609. * This function computes the "Viewing Messages..." string.
  610. */
  611. function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
  612. /* Compute the $msg_cnt_str. */
  613. $result = '';
  614. if ($start_msg < $end_msg) {
  615. $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"), $start_msg, $end_msg, $num_msgs);
  616. } else if ($start_msg == $end_msg) {
  617. $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
  618. } else {
  619. $result = '<br>';
  620. }
  621. /* Return our result string. */
  622. return ($result);
  623. }
  624. /**
  625. * Generate a paginator link.
  626. */
  627. function get_paginator_link
  628. ($box, $start_msg, $use, $text) {
  629. $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
  630. . "&amp;startMessage=$start_msg&amp;mailbox=$box\" "
  631. . "TARGET=\"right\">$text</A>";
  632. return ($result);
  633. }
  634. /**
  635. * This function computes the paginator string.
  636. */
  637. function get_paginator_str
  638. ($box, $start_msg, $end_msg, $num_msgs, $show_num, $sort) {
  639. global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
  640. /* Initialize paginator string chunks. */
  641. $prv_str = '';
  642. $nxt_str = '';
  643. $pg_str = '';
  644. $all_str = '';
  645. $tgl_str = '';
  646. /* Create simple strings that will be creating the paginator. */
  647. $spc = '&nbsp;'; /* This will be used as a space. */
  648. $sep = '|'; /* This will be used as a seperator. */
  649. /* Get some paginator preference values. */
  650. $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON);
  651. $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX);
  652. /* Make sure that our start message number is not too big. */
  653. $start_msg = min($start_msg, $num_msgs);
  654. /* Decide whether or not we will use the mailbox cache. */
  655. /* Not sure why $use_mailbox_cache is even passed in. */
  656. if ($sort == 6) {
  657. $use = 0;
  658. } else {
  659. $use = 1;
  660. }
  661. /* Compute the starting message of the previous and next page group. */
  662. $next_grp = $start_msg + $show_num;
  663. $prev_grp = $start_msg - $show_num;
  664. /* Compute the basic previous and next strings. */
  665. if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
  666. $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
  667. $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
  668. } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
  669. $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
  670. $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
  671. } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
  672. $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
  673. $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
  674. }
  675. /* Page selector block. Following code computes page links. */
  676. if ($pg_sel && ($num_msgs > $show_num)) {
  677. /* Most importantly, what is the current page!!! */
  678. $cur_pg = intval($start_msg / $show_num) + 1;
  679. /* Compute total # of pages and # of paginator page links. */
  680. $tot_pgs = ceil($num_msgs / $show_num); /* Total # of Pages */
  681. $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
  682. /************************************************************/
  683. /* Compute the size of the four quarters of the page links. */
  684. /************************************************************/
  685. /* If we can, just show all the pages. */
  686. if (($tot_pgs - 1) <= $pg_max) {
  687. $q1_pgs = $cur_pg - 1;
  688. $q2_pgs = $q3_pgs = 0;
  689. $q4_pgs = $tot_pgs - $cur_pg;
  690. /* Otherwise, compute some magic to choose the four quarters. */
  691. } else {
  692. /* Compute the magic base values. Added together, */
  693. /* these values will always equal to the $pag_pgs. */
  694. /* NOTE: These are DEFAULT values and do not take */
  695. /* the current page into account. That is below. */
  696. $q1_pgs = floor($vis_pgs/4);
  697. $q2_pgs = round($vis_pgs/4, 0);
  698. $q3_pgs = ceil($vis_pgs/4);
  699. $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
  700. /* Adjust if the first quarter contains the current page. */
  701. if (($cur_pg - $q1_pgs) < 1) {
  702. $extra_pgs = ($q1_pgs - ($cur_pg - 1)) + $q2_pgs;
  703. $q1_pgs = $cur_pg - 1;
  704. $q2_pgs = 0;
  705. $q3_pgs += ceil($extra_pgs / 2);
  706. $q4_pgs += floor($extra_pgs / 2);
  707. /* Adjust if the first and second quarters intersect. */
  708. } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
  709. $extra_pgs = $q2_pgs;
  710. $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
  711. $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
  712. $q3_pgs += ceil($extra_pgs / 2);
  713. $q4_pgs += floor($extra_pgs / 2);
  714. /* Adjust if the fourth quarter contains the current page. */
  715. } else if (($cur_pg + $q4_pgs) >= $tot_pgs) {
  716. $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) + $q3_pgs;
  717. $q3_pgs = 0;
  718. $q4_pgs = $tot_pgs - $cur_pg;
  719. $q1_pgs += floor($extra_pgs / 2);
  720. $q2_pgs += ceil($extra_pgs / 2);
  721. /* Adjust if the third and fourth quarter intersect. */
  722. } else if (($cur_pg + $q3_pgs + 1) >= ($tot_pgs - $q4_pgs + 1)) {
  723. $extra_pgs = $q3_pgs;
  724. $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
  725. $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
  726. $q1_pgs += floor($extra_pgs / 2);
  727. $q2_pgs += ceil($extra_pgs / 2);
  728. }
  729. }
  730. /* I am leaving this debug code here, commented out, because */
  731. /* it is a really nice way to see what the above code is doing. */
  732. /* echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = " */
  733. /* . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>'; */
  734. /************************************************************/
  735. /* Print out the page links from the compute page quarters. */
  736. /************************************************************/
  737. /* Start with the first quarter. */
  738. if (($q1_pgs == 0) && ($cur_pg > 1)) {
  739. $pg_str .= "...$spc";
  740. } else {
  741. for ($pg = 1; $pg <= $q1_pgs; ++$pg) {
  742. $start = (($pg-1) * $show_num) + 1;
  743. $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  744. }
  745. if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
  746. $pg_str .= "...$spc";
  747. }
  748. }
  749. /* Continue with the second quarter. */
  750. for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++$pg) {
  751. $start = (($pg-1) * $show_num) + 1;
  752. $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  753. }
  754. /* Now print the current page. */
  755. $pg_str .= $cur_pg . $spc;
  756. /* Next comes the third quarter. */
  757. for ($pg = $cur_pg + 1; $pg <= $cur_pg + $q3_pgs; ++$pg) {
  758. $start = (($pg-1) * $show_num) + 1;
  759. $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  760. }
  761. /* And last, print the forth quarter page links. */
  762. if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
  763. $pg_str .= "...$spc";
  764. } else {
  765. if (($tot_pgs - $q4_pgs) > ($cur_pg + $q3_pgs)) {
  766. $pg_str .= "...$spc";
  767. }
  768. for ($pg = $tot_pgs - $q4_pgs + 1; $pg <= $tot_pgs; ++$pg) {
  769. $start = (($pg-1) * $show_num) + 1;
  770. $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  771. }
  772. }
  773. } else if ($PG_SHOWNUM == 999999) {
  774. $pg_str = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
  775. . "&amp;startMessage=1&amp;mailbox=$box\" TARGET=\"right\">"
  776. . _("Paginate") . '</A>' . $spc;
  777. }
  778. /* If necessary, compute the 'show all' string. */
  779. if (($prv_str != '') || ($nxt_str != '')) {
  780. $all_str = "<A HREF=\"right_main.php?PG_SHOWNUM=999999"
  781. . "&amp;use_mailbox_cache=$use&amp;startMessage=1&amp;mailbox=$box\" "
  782. . "TARGET=\"right\">" . _("Show All") . '</A>';
  783. }
  784. /* Last but not least, get the value for the toggle all link. */
  785. $tgl_str = get_selectall_link($start_msg, $sort);
  786. /* Put all the pieces of the paginator string together. */
  787. $result = '';
  788. $result .= ($prv_str != '' ? $prv_str . $spc . $sep . $spc : '');
  789. $result .= ($nxt_str != '' ? $nxt_str . $spc . $sep . $spc : '');
  790. $result .= ($pg_str != '' ? $pg_str : '');
  791. $result .= ($all_str != '' ? $sep . $spc . $all_str . $spc : '');
  792. $result .= ($result != '' ? $sep . $spc . $tgl_str: $tgl_str);
  793. /* If the resulting string is blank, return a non-breaking space. */
  794. if ($result == '') {
  795. $result = '&nbsp;';
  796. }
  797. /* Return our final magical paginator string. */
  798. return ($result);
  799. }
  800. function processSubject($subject) {
  801. // Shouldn't ever happen -- caught too many times in the IMAP functions
  802. if ($subject == '')
  803. return _("(no subject)");
  804. if (strlen($subject) <= 55)
  805. return $subject;
  806. $ent_strlen=strlen($subject);
  807. $trim_val=50;
  808. $ent_offset=0;
  809. // see if this is entities-encoded string
  810. // If so, Iterate through the whole string, find out
  811. // the real number of characters, and if more
  812. // than 55, substr with an updated trim value.
  813. while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false &&
  814. ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false)
  815. {
  816. $trim_val += ($ent_loc_end-$ent_loc)+1;
  817. $ent_strlen -= $ent_loc_end-$ent_loc;
  818. $ent_offset = $ent_loc_end+1;
  819. }
  820. if ($ent_strlen <= 55)
  821. return $subject;
  822. return substr($subject, 0, $trim_val) . '...';
  823. }
  824. function handleAsSent($mailbox) {
  825. global $sent_folder, $draft_folder;
  826. global $handleAsSent_result;
  827. /* First check if this is the sent or draft folder. */
  828. $handleAsSent_result = (($mailbox == $sent_folder)
  829. || ($mailbox == $draft_folder));
  830. /* Then check the result of the handleAsSent hook. */
  831. do_hook('check_handleAsSent_result', $mailbox);
  832. /* And return the result. */
  833. return ($handleAsSent_result);
  834. }
  835. ?>