mailbox_display.php 52 KB

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