mailbox_display.php 54 KB

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