mailbox_display.php 34 KB

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