mailbox_display.php 48 KB

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