mailbox_display.php 33 KB

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