mailbox_display.php 48 KB

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