mailbox_display.php 46 KB

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