mailbox_display.php 55 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. $iRangeEnd = (($aMailbox['EXISTS'] - $aMailbox['OFFSET']) > $aMailbox['LIMIT']) ?
  596. $aMailbox['EXISTS'] - $aMailbox['OFFSET'] +1 - $aMailbox['LIMIT']:
  597. $aMailbox['EXISTS'] - $aMailbox['OFFSET'];
  598. $iRangeStart = (($aMailbox['EXISTS'] - $aMailbox['OFFSET']) > $aMailbox['LIMIT']) ?
  599. $aMailbox['EXISTS']-$aMailbox['OFFSET'] +1:1;
  600. $id_slice = range($iRangeStart, $iRangeEnd);
  601. $msgs = sqimap_get_small_header_list($imapConnection,$id_slice,$aMailbox['LIMIT'],
  602. $aHeaderFields,$aFetchItems);
  603. $msgs = array_reverse($msgs,true /* preserve key */);
  604. // generate id array
  605. $id = array_keys($msgs);
  606. $aMailbox['OFFSET'] = 0;
  607. }
  608. // FIX ME, use an id list bound to a mailbox
  609. if ($id !== false) {
  610. sqsession_register($id, 'server_sort_array');
  611. }
  612. sqsession_register($msgs, 'msgs');
  613. }
  614. $aMailbox['UIDSET'] =& $id;
  615. $aMailbox['MSG_HEADERS'] =& $msgs;
  616. if ($aMailbox['SORT_METHOD'] == 'THREAD') {
  617. // retrieve indent array for thread sort
  618. sqgetGlobalVar('indent_array',$indent_array,SQ_SESSION);
  619. $aMailbox['THREAD_INDENT'] =& $indent_array;
  620. }
  621. } /* if exists > 0 */
  622. $iEnd = ($aMailbox['PAGEOFFSET'] + ($aMailbox['LIMIT'] - 1) < $aMailbox['EXISTS']) ?
  623. $aMailbox['PAGEOFFSET'] + $aMailbox['LIMIT'] - 1 : $aMailbox['EXISTS'];
  624. $paginator_str = get_paginator_str($aMailbox['NAME'], $aMailbox['PAGEOFFSET'], $iEnd,
  625. $aMailbox['EXISTS'], $aMailbox['LIMIT'], $aMailbox['SORT']);
  626. $msg_cnt_str = get_msgcnt_str($aMailbox['PAGEOFFSET'], $iEnd,$aMailbox['EXISTS']);
  627. do_hook('mailbox_index_before');
  628. ?>
  629. <table border="0" width="100%" cellpadding="0" cellspacing="0">
  630. <tr>
  631. <td>
  632. <?php mail_message_listing_beginning($imapConnection, $aMailbox, $msg_cnt_str, $paginator_str); ?>
  633. </td>
  634. </tr>
  635. <tr><td height="5" bgcolor="<?php echo $color[4]; ?>"></td></tr>
  636. <tr>
  637. <td>
  638. <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="<?php echo $color[9]; ?>">
  639. <tr>
  640. <td>
  641. <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="<?php echo $color[5]; ?>">
  642. <tr>
  643. <td>
  644. <?php
  645. printHeader($aMailbox);
  646. displayMessageArray($imapConnection, $aMailbox);
  647. ?>
  648. </td>
  649. </tr>
  650. </table>
  651. </td>
  652. </tr>
  653. </table>
  654. <?php
  655. mail_message_listing_end($aMailbox['EXISTS'], $paginator_str, $msg_cnt_str);
  656. ?>
  657. </td>
  658. </tr>
  659. </table>
  660. <?php
  661. //$t = elapsed($start);
  662. //echo("elapsed time = $t seconds\n");
  663. }
  664. /**
  665. * Function to map an uid list with a msg header array by uid
  666. * The mapped headers are printed with printMessage
  667. * aMailbox parameters contains info about the page we are on, the
  668. * used search criteria, the number of messages to show
  669. *
  670. * @param resource $imapConnection socket handle to imap
  671. * @param array $aMailbox array with required elements MSG_HEADERS, UIDSET, OFFSET, LIMIT
  672. * @return void
  673. **/
  674. function displayMessageArray($imapConnection, $aMailbox) {
  675. $aId = $aMailbox['UIDSET'];
  676. $aHeaders = $aMailbox['MSG_HEADERS'];
  677. $iOffset = $aMailbox['OFFSET'];
  678. $sort = $aMailbox['SORT'];
  679. $iPageOffset = $aMailbox['PAGEOFFSET'];
  680. $sMailbox = $aMailbox['NAME'];
  681. $aSearch = (isset($aMailbox['SEARCH'])) ? $aMailbox['SEARCH'] : false;
  682. if ($aMailbox['SORT_METHOD'] == 'THREAD') {
  683. $aIndentArray =& $aMailbox['THREAD_INDENT'];
  684. $bThread = true;
  685. } else {
  686. $bThread = false;
  687. }
  688. /*
  689. * Loop through and display the info for each message.
  690. * ($t is used for the checkbox number)
  691. */
  692. $iEnd = ($aMailbox['LIMIT']) ? $iOffset + $aMailbox['LIMIT'] : 99999999 /* no limit */;
  693. for ($i=$iOffset,$t=0;$i<$iEnd;++$i) {
  694. if (isset($aId[$i])) {
  695. $bLast = ((isset($aId[$i+1]) && isset($aHeaders[$aId[$i+1]]))
  696. || ($i == $iEnd )) ? false : true;
  697. if ($bThread) {
  698. $indent = (isset($aIndentArray[$aId[$i]])) ? $aIndentArray[$aId[$i]] : 0;
  699. } else {
  700. $indent = 0;
  701. }
  702. $aMsg = array(
  703. 'HEADER' => $aHeaders[$aId[$i]],
  704. 'INDX' => $t,
  705. 'OFFSET' => $iOffset,
  706. 'PAGEOFFSET' => $iPageOffset,
  707. 'SORT' => $sort,
  708. 'SEARCH' => $aSearch,
  709. 'MAILBOX' => $sMailbox,
  710. 'INDENT' => $indent,
  711. 'LAST' => $bLast
  712. );
  713. printMessageInfo($aMsg);
  714. ++$t;
  715. } else {
  716. break;
  717. }
  718. }
  719. }
  720. /**
  721. * Displays the standard message list header.
  722. *
  723. * To finish the table, you need to do a "</table></table>";
  724. *
  725. * @param resource $imapConnection
  726. * @param array $aMailbox associative array with mailbox related information
  727. * @param string $msg_cnt_str
  728. * @param string $paginator Paginator string
  729. */
  730. function mail_message_listing_beginning ($imapConnection,
  731. $aMailbox,
  732. $msg_cnt_str = '',
  733. $paginator = '&nbsp;'
  734. ) {
  735. global $color, $base_uri, $show_flag_buttons, $PHP_SELF;
  736. $php_self = $PHP_SELF;
  737. /* fix for incorrect $PHP_SELF */
  738. if (strpos($php_self, 'move_messages.php')) {
  739. $php_self = str_replace('move_messages.php', 'right_main.php', $php_self);
  740. }
  741. $urlMailbox = urlencode($aMailbox['NAME']);
  742. if (preg_match('/^(.+)\?.+$/',$php_self,$regs)) {
  743. $source_url = $regs[1];
  744. } else {
  745. $source_url = $php_self;
  746. }
  747. if (!isset($msg)) {
  748. $msg = '';
  749. }
  750. if (!strpos($php_self,'?')) {
  751. $location = $php_self.'?mailbox=INBOX&amp;startMessage=1';
  752. } else {
  753. $location = $php_self;
  754. }
  755. $moveFields = addHidden('msg', $msg).
  756. addHidden('mailbox', $aMailbox['NAME']).
  757. addHidden('startMessage', $aMailbox['PAGEOFFSET']).
  758. addHidden('location', $location);
  759. /* build thread sorting links */
  760. if ($aMailbox['ALLOW_THREAD']) {
  761. if ($aMailbox['SORT_METHOD'] == 'THREAD') {
  762. $set_thread = 2;
  763. $thread_name = _("Unthread View");
  764. } else {
  765. $set_thread = 1;
  766. $thread_name = _("Thread View");
  767. }
  768. $thread_link_str = '<small>[<a href="' . $source_url . '?sort='
  769. . $aMailbox['SORT'] . '&start_messages=1&set_thread=' . $set_thread
  770. . '&mailbox=' . urlencode($aMailbox['NAME']) . '">' . $thread_name
  771. . '</a>]</small>';
  772. } else {
  773. $thread_link_str ='';
  774. }
  775. /*
  776. * This is the beginning of the message list table.
  777. * It wraps around all messages
  778. */
  779. $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $aMailbox['NAME']);
  780. $form_name = "FormMsgs" . $safe_name;
  781. echo '<form name="' . $form_name . '" method="post" action="move_messages.php">' ."\n"
  782. . $moveFields;
  783. ?>
  784. <table width="100%" cellpadding="1" cellspacing="0" style="border: 1px solid <?php echo $color[0]; ?>">
  785. <tr>
  786. <td>
  787. <table bgcolor="<?php echo $color[4]; ?>" border="0" width="100%" cellpadding="1" cellspacing="0">
  788. <tr>
  789. <td align="left"><small><?php echo $paginator . $thread_link_str; ?></small></td>
  790. <td align="center"></td>
  791. <td align="right"><small><?php echo $msg_cnt_str; ?></small></td>
  792. </tr>
  793. </table>
  794. </td>
  795. </tr>
  796. <tr width="100%" cellpadding="1" cellspacing="0" border="0" bgcolor="<?php echo $color[0]; ?>">
  797. <td>
  798. <table border="0" width="100%" cellpadding="1" cellspacing="0">
  799. <tr>
  800. <td align="left">
  801. <small><?php
  802. // display flag buttons only if supported
  803. if ($show_flag_buttons &&
  804. array_search('\\flagged',$aMailbox['PERMANENTFLAGS'], true) !== FALSE) {
  805. echo getButton('SUBMIT', 'markUnflagged',_("Unflag"));
  806. echo getButton('SUBMIT', 'markFlagged',_("Flag"));
  807. echo '&nbsp;';
  808. }
  809. if (array_search('\\seen',$aMailbox['PERMANENTFLAGS'], true) !== FALSE) {
  810. echo getButton('SUBMIT', 'markUnread',_("Unread"));
  811. echo getButton('SUBMIT', 'markRead',_("Read"));
  812. echo '&nbsp;';
  813. }
  814. echo getButton('SUBMIT', 'attache',_("Forward"));
  815. echo '&nbsp;';
  816. if (array_search('\\deleted',$aMailbox['PERMANENTFLAGS'], true) !== FALSE) {
  817. echo getButton('SUBMIT', 'delete',_("Delete"));
  818. echo '<input type="checkbox" name="bypass_trash" />' . _("Bypass Trash");
  819. echo '&nbsp;';
  820. }
  821. if (!$aMailbox['AUTO_EXPUNGE'] && $aMailbox['RIGHTS'] != 'READ-ONLY') {
  822. echo getButton('SUBMIT', 'expungeButton',_("Expunge")) .'&nbsp;' . _("mailbox") . "\n";
  823. echo '&nbsp;';
  824. }
  825. do_hook('mailbox_display_buttons');
  826. ?></small>
  827. </td>
  828. <?php
  829. if (array_search('\\deleted',$aMailbox['PERMANENTFLAGS'], true) !== FALSE) {
  830. echo '<td align="right">
  831. <small>';
  832. //echo $thread_link_str; //previous behaviour
  833. getMbxList($imapConnection);
  834. echo getButton('SUBMIT', 'moveButton',_("Move")) . "\n
  835. </small>";
  836. }
  837. ?>
  838. </td>
  839. </tr>
  840. </table>
  841. </td>
  842. </tr>
  843. </table>
  844. <?php
  845. do_hook('mailbox_form_before');
  846. }
  847. /**
  848. * Function to add the last row in a message list, it contains the paginator and info about
  849. * the number of messages.
  850. *
  851. * @param integer $num_msgs number of messages in a mailbox
  852. * @param string $paginator_str Paginator string [Prev | Next] [ 1 2 3 ... 91 92 94 ] [Show all]
  853. * @param string $msg_cnt_str Message count string Viewing Messages: 21 to 1861 (20 total)
  854. */
  855. function mail_message_listing_end($num_msgs, $paginator_str, $msg_cnt_str) {
  856. global $color;
  857. if ($num_msgs) {
  858. /* space between list and footer */
  859. ?>
  860. <tr><td height="5" bgcolor="<?php echo $color[4]; ?>" colspan="1"></td></tr>
  861. <tr>
  862. <td>
  863. <table width="100%" cellpadding="1" cellspacing="0" style="border: 1px solid <?php echo $color[0]; ?>">
  864. <tr>
  865. <td>
  866. <table bgcolor="<?php echo $color[4]; ?>" border="0" width="100%" cellpadding="1" cellspacing="0">
  867. <tr>
  868. <td align="left"><small><?php echo $paginator_str; ?></small></td>
  869. <td align="right"><small><?php echo $msg_cnt_str; ?></small></td>
  870. </tr>
  871. </table>
  872. </td>
  873. </tr>
  874. </table>
  875. </td>
  876. </tr>
  877. <?php
  878. }
  879. /* End of message-list table */
  880. do_hook('mailbox_index_after');
  881. echo "</form>\n";
  882. }
  883. /**
  884. * Prints the table header for the messages list view
  885. *
  886. * @param array $aMailbox
  887. */
  888. function printHeader($aMailbox) {
  889. global $index_order, $internal_date_sort, $color;
  890. if ($aMailbox['SORT_METHOD'] != 'THREAD') {
  891. $showsort = true;
  892. } else {
  893. $showsort = false;
  894. }
  895. echo html_tag( 'tr' ,'' , 'center', $color[5] );
  896. /* calculate the width of the subject column based on the
  897. * widths of the other columns */
  898. $widths = array(1=>1,2=>25,3=>5,4=>0,5=>1,6=>5);
  899. $subjectwidth = 100;
  900. foreach($index_order as $item) {
  901. $subjectwidth -= $widths[$item];
  902. }
  903. foreach ($index_order as $item) {
  904. switch ($item) {
  905. case 1: /* checkbox */
  906. echo html_tag( 'td',get_selectall_link($aMailbox) , '', '', 'width="1%"' );
  907. break;
  908. case 5: /* flags */
  909. echo html_tag( 'td','' , '', '', 'width="1%"' );
  910. break;
  911. case 2: /* from */
  912. if (handleAsSent($aMailbox['NAME'])) {
  913. echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
  914. . '<b>' . _("To") . '</b>';
  915. if ($showsort) {
  916. ShowSortButton($aMailbox, SQSORT_TO_ASC, SQSORT_TO_DEC);
  917. }
  918. } else {
  919. echo html_tag( 'td' ,'' , 'left', '', 'width="25%"' )
  920. . '<b>' . _("From") . '</b>';
  921. if ($showsort) {
  922. ShowSortButton($aMailbox, SQSORT_FROM_ASC, SQSORT_FROM_DEC);
  923. }
  924. }
  925. echo "</td>\n";
  926. break;
  927. case 3: /* date */
  928. echo html_tag( 'td' ,'' , 'left', '', 'width="5%" nowrap' )
  929. . '<b>' . _("Date") . '</b>';
  930. if ($showsort) {
  931. if ($internal_date_sort) {
  932. ShowSortButton($aMailbox, SQSORT_INT_DATE_ASC, SQSORT_INT_DATE_DEC);
  933. } else {
  934. ShowSortButton($aMailbox, SQSORT_DATE_ASC, SQSORT_DATE_DEC);
  935. }
  936. }
  937. echo "</td>\n";
  938. break;
  939. case 4: /* subject */
  940. echo html_tag( 'td' ,'' , 'left', '', 'width="'.$subjectwidth.'%"' )
  941. . '<b>' . _("Subject") . '</b>';
  942. if ($showsort) {
  943. ShowSortButton($aMailbox, SQSORT_SUBJ_ASC, SQSORT_SUBJ_DEC);
  944. }
  945. echo "</td>\n";
  946. break;
  947. case 6: /* size */
  948. echo html_tag( 'td', '', 'center','','width="5%" nowrap')
  949. . '<b>' . _("Size") . '</b>';
  950. if ($showsort) {
  951. ShowSortButton($aMailbox, SQSORT_SIZE_ASC, SQSORT_SIZE_DEC);
  952. }
  953. echo "</td>\n";
  954. break;
  955. }
  956. }
  957. echo "</tr>\n";
  958. }
  959. /**
  960. * This function shows the sort button. Isn't this a good comment?
  961. *
  962. * @param array $aMailbox
  963. * @param integer $Down
  964. * @param integer $Up
  965. */
  966. function ShowSortButton($aMailbox, $Down, $Up ) {
  967. global $PHP_SELF;
  968. /* Figure out which image we want to use. */
  969. if ($aMailbox['SORT'] != $Up && $aMailbox['SORT'] != $Down) {
  970. $img = 'sort_none.png';
  971. $which = $Up;
  972. } elseif ($aMailbox['SORT'] == $Up) {
  973. $img = 'up_pointer.png';
  974. $which = $Down;
  975. } else {
  976. $img = 'down_pointer.png';
  977. $which = 0;
  978. }
  979. if (preg_match('/^(.+)\?.+$/',$PHP_SELF,$regs)) {
  980. $source_url = $regs[1];
  981. } else {
  982. $source_url = $PHP_SELF;
  983. }
  984. /* Now that we have everything figured out, show the actual button. */
  985. echo ' <a href="' . $source_url .'?newsort=' . $which
  986. . '&amp;startMessage=1&amp;mailbox=' . urlencode($aMailbox['NAME'])
  987. . '"><img src="../images/' . $img
  988. . '" border="0" width="12" height="10" alt="sort" title="'
  989. . _("Click here to change the sorting of the message list") .' /"></a>';
  990. }
  991. /**
  992. * FIXME: Undocumented function
  993. *
  994. * @param array $aMailbox
  995. */
  996. function get_selectall_link($aMailbox) {
  997. global $checkall, $javascript_on;
  998. global $PHP_SELF, $PG_SHOWNUM;
  999. $result = '';
  1000. if ($javascript_on) {
  1001. $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $aMailbox['NAME']);
  1002. $func_name = "CheckAll" . $safe_name;
  1003. $form_name = "FormMsgs" . $safe_name;
  1004. $result = '<script language="JavaScript" type="text/javascript">'
  1005. . "\n<!-- \n"
  1006. . "function " . $func_name . "() {\n"
  1007. . " for (var i = 0; i < document." . $form_name . ".elements.length; i++) {\n"
  1008. . " if(document." . $form_name . ".elements[i].type == 'checkbox' && "
  1009. . " document." . $form_name . ".elements[i].name.substring(0,3) == 'msg'){\n"
  1010. . " document." . $form_name . ".elements[i].checked = "
  1011. . " !(document." . $form_name . ".elements[i].checked);\n"
  1012. . " }\n"
  1013. . " }\n"
  1014. . "}\n"
  1015. . "//-->\n"
  1016. . '</script>'
  1017. . '<input type="checkbox" name="toggleAll" title="'._("Toggle All").'" onclick="'.$func_name.'();" />';
  1018. // . <a href="javascript:void(0)" onClick="' . $func_name . '();">' . _("Toggle All")
  1019. // . "</a>\n";
  1020. } else {
  1021. if (strpos($PHP_SELF, "?")) {
  1022. $result .= "<a href=\"$PHP_SELF&amp;mailbox=" . urlencode($aMailbox['NAME'])
  1023. . "&amp;startMessage=$aMailbox[PAGEOFFSET]&amp;sort=$aMailbox[SORT]&amp;checkall=";
  1024. } else {
  1025. $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
  1026. . "&amp;startMessage=$aMailbox[PAGEOFFSET]&amp;sort=$aMailbox[SORT]&amp;checkall=";
  1027. }
  1028. if (isset($checkall) && $checkall == '1') {
  1029. $result .= '0';
  1030. } else {
  1031. $result .= '1';
  1032. }
  1033. if (isset($aMailbox['SEARCH']) && $aMailbox['SEARCH'][0]) {
  1034. $result .= '&amp;where=' . urlencode($aMailbox['SEARCH'][0])
  1035. . '&amp;what=' . urlencode($aMailbox['SEARCH'][1]);
  1036. }
  1037. $result .= "\">";
  1038. $result .= _("All");
  1039. $result .= "</a>\n";
  1040. }
  1041. /* Return our final result. */
  1042. return ($result);
  1043. }
  1044. /**
  1045. * This function computes the "Viewing Messages..." string.
  1046. *
  1047. * @param integer $start_msg first message number
  1048. * @param integer $end_msg last message number
  1049. * @param integer $num_msgs total number of message in folder
  1050. * @return string
  1051. */
  1052. function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
  1053. /* Compute the $msg_cnt_str. */
  1054. $result = '';
  1055. if ($start_msg < $end_msg) {
  1056. $result = sprintf(_("Viewing Messages: %s to %s (%s total)"),
  1057. '<b>'.$start_msg.'</b>', '<b>'.$end_msg.'</b>', $num_msgs);
  1058. } else if ($start_msg == $end_msg) {
  1059. $result = sprintf(_("Viewing Message: %s (1 total)"), '<b>'.$start_msg.'</b>');
  1060. } else {
  1061. $result = '<br />';
  1062. }
  1063. /* Return our result string. */
  1064. return ($result);
  1065. }
  1066. /**
  1067. * Generate a paginator link.
  1068. *
  1069. * @param mixed $box Mailbox name
  1070. * @param mixed $start_msg Message Offset
  1071. * @param mixed $use
  1072. * @param string $text text used for paginator link
  1073. * @return string
  1074. */
  1075. function get_paginator_link($box, $start_msg, $use, $text) {
  1076. $result = "<a href=\"right_main.php?use_mailbox_cache=$use"
  1077. . "&amp;startMessage=$start_msg&amp;mailbox=$box\" "
  1078. . ">$text</a>";
  1079. return ($result);
  1080. }
  1081. /**
  1082. * This function computes the paginator string.
  1083. *
  1084. * @param string $box
  1085. * @param integer $start_msg
  1086. * @param integer $end_msg
  1087. * @param integer $num_msgs
  1088. * @param integer $show_num
  1089. * @param integer $sort
  1090. */
  1091. function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
  1092. $show_num, $sort) {
  1093. global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
  1094. /* Initialize paginator string chunks. */
  1095. $prv_str = '';
  1096. $nxt_str = '';
  1097. $pg_str = '';
  1098. $all_str = '';
  1099. $box = urlencode($box);
  1100. $use = 0;
  1101. /* Create simple strings that will be creating the paginator. */
  1102. $spc = '&nbsp;'; /* This will be used as a space. */
  1103. $sep = '|'; /* This will be used as a seperator. */
  1104. /* Get some paginator preference values. */
  1105. $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON);
  1106. $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX);
  1107. /* Make sure that our start message number is not too big. */
  1108. $start_msg = min($start_msg, $num_msgs);
  1109. /* Compute the starting message of the previous and next page group. */
  1110. $next_grp = $start_msg + $show_num;
  1111. $prev_grp = $start_msg - $show_num;
  1112. /* Compute the basic previous and next strings. */
  1113. if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
  1114. $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
  1115. $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
  1116. } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
  1117. $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
  1118. $nxt_str = _("Next");
  1119. } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
  1120. $prv_str = _("Previous");
  1121. $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
  1122. }
  1123. /* Page selector block. Following code computes page links. */
  1124. if ($show_num != 0 && $pg_sel && ($num_msgs > $show_num)) {
  1125. /* Most importantly, what is the current page!!! */
  1126. $cur_pg = intval($start_msg / $show_num) + 1;
  1127. /* Compute total # of pages and # of paginator page links. */
  1128. $tot_pgs = ceil($num_msgs / $show_num); /* Total number of Pages */
  1129. $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
  1130. /* Compute the size of the four quarters of the page links. */
  1131. /* If we can, just show all the pages. */
  1132. if (($tot_pgs - 1) <= $pg_max) {
  1133. $q1_pgs = $cur_pg - 1;
  1134. $q2_pgs = $q3_pgs = 0;
  1135. $q4_pgs = $tot_pgs - $cur_pg;
  1136. /* Otherwise, compute some magic to choose the four quarters. */
  1137. } else {
  1138. /*
  1139. * Compute the magic base values. Added together,
  1140. * these values will always equal to the $pag_pgs.
  1141. * NOTE: These are DEFAULT values and do not take
  1142. * the current page into account. That is below.
  1143. */
  1144. $q1_pgs = floor($vis_pgs/4);
  1145. $q2_pgs = round($vis_pgs/4, 0);
  1146. $q3_pgs = ceil($vis_pgs/4);
  1147. $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
  1148. /* Adjust if the first quarter contains the current page. */
  1149. if (($cur_pg - $q1_pgs) < 1) {
  1150. $extra_pgs = ($q1_pgs - ($cur_pg - 1)) + $q2_pgs;
  1151. $q1_pgs = $cur_pg - 1;
  1152. $q2_pgs = 0;
  1153. $q3_pgs += ceil($extra_pgs / 2);
  1154. $q4_pgs += floor($extra_pgs / 2);
  1155. /* Adjust if the first and second quarters intersect. */
  1156. } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
  1157. $extra_pgs = $q2_pgs;
  1158. $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 3/4);
  1159. $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 3/4);
  1160. $q3_pgs += ceil($extra_pgs / 2);
  1161. $q4_pgs += floor($extra_pgs / 2);
  1162. /* Adjust if the fourth quarter contains the current page. */
  1163. } else if (($cur_pg + $q4_pgs) >= $tot_pgs) {
  1164. $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) + $q3_pgs;
  1165. $q3_pgs = 0;
  1166. $q4_pgs = $tot_pgs - $cur_pg;
  1167. $q1_pgs += floor($extra_pgs / 2);
  1168. $q2_pgs += ceil($extra_pgs / 2);
  1169. /* Adjust if the third and fourth quarter intersect. */
  1170. } else if (($cur_pg + $q3_pgs + 1) >= ($tot_pgs - $q4_pgs + 1)) {
  1171. $extra_pgs = $q3_pgs;
  1172. $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 3/4);
  1173. $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 3/4);
  1174. $q1_pgs += floor($extra_pgs / 2);
  1175. $q2_pgs += ceil($extra_pgs / 2);
  1176. }
  1177. }
  1178. /*
  1179. * I am leaving this debug code here, commented out, because
  1180. * it is a really nice way to see what the above code is doing.
  1181. * echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = "
  1182. * . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br />';
  1183. */
  1184. /* Print out the page links from the compute page quarters. */
  1185. /* Start with the first quarter. */
  1186. if (($q1_pgs == 0) && ($cur_pg > 1)) {
  1187. $pg_str .= "...$spc";
  1188. } else {
  1189. for ($pg = 1; $pg <= $q1_pgs; ++$pg) {
  1190. $start = (($pg-1) * $show_num) + 1;
  1191. $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  1192. }
  1193. if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
  1194. $pg_str .= "...$spc";
  1195. }
  1196. }
  1197. /* Continue with the second quarter. */
  1198. for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++$pg) {
  1199. $start = (($pg-1) * $show_num) + 1;
  1200. $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  1201. }
  1202. /* Now print the current page. */
  1203. $pg_str .= $cur_pg . $spc;
  1204. /* Next comes the third quarter. */
  1205. for ($pg = $cur_pg + 1; $pg <= $cur_pg + $q3_pgs; ++$pg) {
  1206. $start = (($pg-1) * $show_num) + 1;
  1207. $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  1208. }
  1209. /* And last, print the forth quarter page links. */
  1210. if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
  1211. $pg_str .= "...$spc";
  1212. } else {
  1213. if (($tot_pgs - $q4_pgs) > ($cur_pg + $q3_pgs)) {
  1214. $pg_str .= "...$spc";
  1215. }
  1216. for ($pg = $tot_pgs - $q4_pgs + 1; $pg <= $tot_pgs; ++$pg) {
  1217. $start = (($pg-1) * $show_num) + 1;
  1218. $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
  1219. }
  1220. }
  1221. } else if ($PG_SHOWNUM == 999999) {
  1222. $pg_str = "<a href=\"right_main.php?PG_SHOWALL=0"
  1223. . "&amp;use_mailbox_cache=$use&amp;startMessage=1&amp;mailbox=$box\" "
  1224. . ">" ._("Paginate") . '</a>';
  1225. }
  1226. /* Put all the pieces of the paginator string together. */
  1227. /**
  1228. * Hairy code... But let's leave it like it is since I am not certain
  1229. * a different approach would be any easier to read. ;)
  1230. */
  1231. $result = '';
  1232. if ( $prv_str != '' || $nxt_str != '' )
  1233. {
  1234. $result .= '[';
  1235. $result .= ($prv_str != '' ? $prv_str . $spc . $sep . $spc : '');
  1236. $result .= ($nxt_str != '' ? $nxt_str : '');
  1237. $result .= ']' . $spc ;
  1238. /* Compute the 'show all' string. */
  1239. $all_str = "<a href=\"right_main.php?PG_SHOWALL=1"
  1240. . "&amp;use_mailbox_cache=$use&amp;startMessage=1&amp;mailbox=$box\" "
  1241. . ">" . _("Show All") . '</a>';
  1242. }
  1243. $result .= ($pg_str != '' ? $spc . '['.$spc.$pg_str.']' . $spc : '');
  1244. $result .= ($all_str != '' ? $spc . '['.$all_str.']' . $spc . $spc : '');
  1245. /* If the resulting string is blank, return a non-breaking space. */
  1246. if ($result == '') {
  1247. $result = '&nbsp;';
  1248. }
  1249. /* Return our final magical paginator string. */
  1250. return ($result);
  1251. }
  1252. /**
  1253. * FIXME: Undocumented function
  1254. */
  1255. function truncateWithEntities($subject, $trim_at)
  1256. {
  1257. $ent_strlen = strlen($subject);
  1258. if (($trim_at <= 0) || ($ent_strlen <= $trim_at))
  1259. return $subject;
  1260. global $languages, $squirrelmail_language;
  1261. /*
  1262. * see if this is entities-encoded string
  1263. * If so, Iterate through the whole string, find out
  1264. * the real number of characters, and if more
  1265. * than $trim_at, substr with an updated trim value.
  1266. */
  1267. $trim_val = $trim_at;
  1268. $ent_offset = 0;
  1269. $ent_loc = 0;
  1270. while ( $ent_loc < $trim_val && (($ent_loc = strpos($subject, '&', $ent_offset)) !== false) &&
  1271. (($ent_loc_end = strpos($subject, ';', $ent_loc+3)) !== false) ) {
  1272. $trim_val += ($ent_loc_end-$ent_loc);
  1273. $ent_offset = $ent_loc_end+1;
  1274. }
  1275. if (($trim_val > $trim_at) && ($ent_strlen > $trim_val) && (strpos($subject,';',$trim_val) < ($trim_val + 6))) {
  1276. $i = strpos($subject,';',$trim_val);
  1277. if ($i) {
  1278. $trim_val = strpos($subject,';',$trim_val);
  1279. }
  1280. }
  1281. // only print '...' when we're actually dropping part of the subject
  1282. if ($ent_strlen <= $trim_val)
  1283. return $subject;
  1284. if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
  1285. function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
  1286. return $languages[$squirrelmail_language]['XTRA_CODE']('strimwidth', $subject, $trim_val);
  1287. }
  1288. return substr_replace($subject, '...', $trim_val);
  1289. }
  1290. /**
  1291. * FIXME: Undocumented function
  1292. */
  1293. function processSubject($subject, $threadlevel = 0) {
  1294. /* Shouldn't ever happen -- caught too many times in the IMAP functions */
  1295. if ($subject == '') {
  1296. return _("(no subject)");
  1297. }
  1298. global $truncate_subject; /* number of characters for Subject field (<= 0 for unchanged) */
  1299. $trim_at = $truncate_subject;
  1300. /* if this is threaded, subtract two chars per indentlevel */
  1301. if (($threadlevel > 0) && ($threadlevel <= 10))
  1302. $trim_at -= (2*$threadlevel);
  1303. return truncateWithEntities($subject, $trim_at);
  1304. }
  1305. /**
  1306. * FIXME: Undocumented function
  1307. *
  1308. * @param mixed $imapConnection
  1309. * @param mixed $boxes
  1310. */
  1311. function getMbxList($imapConnection, $boxes = 0) {
  1312. global $lastTargetMailbox;
  1313. echo ' <small>&nbsp;<tt><select name="targetMailbox">';
  1314. echo sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)), 0, $boxes);
  1315. echo ' </select></tt>&nbsp;';
  1316. }
  1317. /**
  1318. * Creates button
  1319. *
  1320. * @deprecated see form functions available in 1.5.1 and 1.4.3.
  1321. * @param string $type
  1322. * @param string $name
  1323. * @param string $value
  1324. * @param string $js
  1325. * @param bool $enabled
  1326. */
  1327. function getButton($type, $name, $value, $js = '', $enabled = TRUE) {
  1328. $disabled = ( $enabled ? '' : 'disabled ' );
  1329. $js = ( $js ? $js.' ' : '' );
  1330. return '<input '.$disabled.$js.
  1331. 'type="'.$type.
  1332. '" name="'.$name.
  1333. '" value="'.$value .
  1334. '" style="padding: 0px; margin: 0px" />';
  1335. }
  1336. /**
  1337. * Puts string into cell, aligns it and adds <small> tag
  1338. *
  1339. * @param string $string string
  1340. * @param string $align alignment
  1341. */
  1342. function getSmallStringCell($string, $align) {
  1343. return html_tag('td',
  1344. '<small>' . $string . ':&nbsp; </small>',
  1345. $align,
  1346. '',
  1347. 'nowrap' );
  1348. }
  1349. /**
  1350. * This should go in imap_mailbox.php
  1351. * @param string $mailbox
  1352. */
  1353. function handleAsSent($mailbox) {
  1354. global $handleAsSent_result;
  1355. /* First check if this is the sent or draft folder. */
  1356. $handleAsSent_result = isSentMailbox($mailbox) || isDraftMailbox($mailbox);
  1357. /* Then check the result of the handleAsSent hook. */
  1358. do_hook('check_handleAsSent_result', $mailbox);
  1359. /* And return the result. */
  1360. return $handleAsSent_result;
  1361. }
  1362. ?>