mailbox_display.php 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447
  1. <?php
  2. /**
  3. * mailbox_display.php
  4. *
  5. * This contains functions that display mailbox information, such as the
  6. * table row that has sender, date, subject, etc...
  7. *
  8. * @copyright &copy; 1999-2006 The SquirrelMail Project Team
  9. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10. * @version $Id$
  11. * @package squirrelmail
  12. */
  13. /** The standard includes.. */
  14. require_once(SM_PATH . 'functions/strings.php');
  15. require_once(SM_PATH . 'functions/html.php');
  16. require_once(SM_PATH . 'functions/imap_mailbox.php');
  17. require_once(SM_PATH . 'functions/imap_messages.php');
  18. require_once(SM_PATH . 'functions/imap_asearch.php');
  19. require_once(SM_PATH . 'functions/mime.php');
  20. require_once(SM_PATH . 'functions/forms.php');
  21. /**
  22. * Selects a mailbox for header retrieval.
  23. * Cache control for message headers is embedded.
  24. *
  25. * @param resource $imapConnection imap socket handle
  26. * @param string $mailbox mailbox to select and retrieve message headers from
  27. * @param array $aConfig array with system config settings and incoming vars
  28. * @param array $aProps mailbox specific properties
  29. * @return array $aMailbox mailbox array with all relevant information
  30. * @since 1.5.1
  31. * @author Marc Groot Koerkamp
  32. */
  33. function sqm_api_mailbox_select($imapConnection,$account,$mailbox,$aConfig,$aProps) {
  34. /**
  35. * NB: retrieve this from the session before accessing this function
  36. * and make sure you write it back at the end of the script after
  37. * the aMailbox var is added so that the headers are added to the cache
  38. */
  39. global $mailbox_cache;
  40. $aDefaultConfigProps = array(
  41. // 'charset' => 'US-ASCII',
  42. 'user' => false, /* no pref storage if false */
  43. 'setindex' => 0,
  44. // 'search' => 'ALL',
  45. 'max_cache_size' => SQM_MAX_MBX_IN_CACHE
  46. );
  47. $aConfig = array_merge($aDefaultConfigProps,$aConfig);
  48. $iSetIndx = $aConfig['setindex'];
  49. $aMbxResponse = sqimap_mailbox_select($imapConnection, $mailbox);
  50. if ($mailbox_cache) {
  51. if (isset($mailbox_cache[$account.'_'.$mailbox])) {
  52. $aCachedMailbox = $mailbox_cache[$account.'_'.$mailbox];
  53. } else {
  54. $aCachedMailbox = false;
  55. }
  56. /* cleanup cache */
  57. if (count($mailbox_cache) > $aConfig['max_cache_size'] -1) {
  58. $aTime = array();
  59. foreach($mailbox_cache as $cachedmailbox => $aVal) {
  60. $aTime[$aVal['TIMESTAMP']] = $cachedmailbox;
  61. }
  62. if (ksort($aTime,SORT_NUMERIC)) {
  63. for ($i=0,$iCnt=count($mailbox_cache);$i<($iCnt-$aConfig['max_cache_size']);++$i) {
  64. $sOldestMbx = array_shift($aTime);
  65. /**
  66. * Remove only the UIDSET and MSG_HEADERS from cache because those can
  67. * contain large amounts of data.
  68. */
  69. if (isset($mailbox_cache[$sOldestMbx]['UIDSET'])) {
  70. $mailbox_cache[$sOldestMbx]['UIDSET']= false;
  71. }
  72. if (isset($mailbox_cache[$sOldestMbx]['MSG_HEADERS'])) {
  73. $mailbox_cache[$sOldestMbx]['MSG_HEADERS'] = false;
  74. }
  75. }
  76. }
  77. }
  78. } else {
  79. $aCachedMailbox = false;
  80. }
  81. /**
  82. * Deal with imap servers that do not return the required UIDNEXT or
  83. * UIDVALIDITY response
  84. * from a SELECT call (since rfc 3501 it's required).
  85. */
  86. if (!isset($aMbxResponse['UIDNEXT']) || !isset($aMbxResponse['UIDVALIDITY'])) {
  87. $aStatus = sqimap_status_messages($imapConnection,$mailbox,
  88. array('UIDNEXT','UIDVALIDITY'));
  89. $aMbxResponse['UIDNEXT'] = $aStatus['UIDNEXT'];
  90. $aMbxResponse['UIDVALIDTY'] = $aStatus['UIDVALIDITY'];
  91. }
  92. $aMailbox['ACCOUNT'] = $account;
  93. $aMailbox['UIDSET'][$iSetIndx] = false;
  94. $aMailbox['ID'] = false;
  95. $aMailbox['SETINDEX'] = $iSetIndx;
  96. $aMailbox['MSG_HEADERS'] = false;
  97. if ($aCachedMailbox) {
  98. /**
  99. * Validate integrity of cached data
  100. */
  101. if ($aCachedMailbox['EXISTS'] == $aMbxResponse['EXISTS'] &&
  102. $aMbxResponse['EXISTS'] &&
  103. $aCachedMailbox['UIDVALIDITY'] == $aMbxResponse['UIDVALIDITY'] &&
  104. $aCachedMailbox['UIDNEXT'] == $aMbxResponse['UIDNEXT'] &&
  105. isset($aCachedMailbox['SEARCH'][$iSetIndx]) &&
  106. (!isset($aConfig['search']) || /* always set search from the searchpage */
  107. $aCachedMailbox['SEARCH'][$iSetIndx] == $aConfig['search'])) {
  108. if (isset($aCachedMailbox['MSG_HEADERS'])) {
  109. $aMailbox['MSG_HEADERS'] = $aCachedMailbox['MSG_HEADERS'];
  110. }
  111. $aMailbox['ID'] = $aCachedMailbox['ID'];
  112. if (isset($aCachedMailbox['UIDSET'][$iSetIndx]) && $aCachedMailbox['UIDSET'][$iSetIndx]) {
  113. if (isset($aProps[MBX_PREF_SORT]) && $aProps[MBX_PREF_SORT] != $aCachedMailbox['SORT'] ) {
  114. $newsort = $aProps[MBX_PREF_SORT];
  115. $oldsort = $aCachedMailbox['SORT'];
  116. /**
  117. * If it concerns a reverse sort we do not need to invalidate
  118. * the cached sorted UIDSET, a reverse is sufficient.
  119. */
  120. if ((($newsort % 2) && ($newsort + 1 == $oldsort)) ||
  121. (!($newsort % 2) && ($newsort - 1 == $oldsort))) {
  122. $aMailbox['UIDSET'][$iSetIndx] = array_reverse($aCachedMailbox['UIDSET'][$iSetIndx]);
  123. } else {
  124. $server_sort_array = false;
  125. $aMailbox['MSG_HEADERS'] = false;
  126. $aMailbox['ID'] = false;
  127. }
  128. // store the new sort value in the mailbox pref
  129. if ($aConfig['user']) {
  130. // FIXME, in ideal situation, we write back the
  131. // prefs at the end of the script
  132. setUserPref($aConfig['user'],'pref_'.$account.'_'.$mailbox,serialize($aProps));
  133. }
  134. } else {
  135. $aMailbox['UIDSET'][$iSetIndx] = $aCachedMailbox['UIDSET'][$iSetIndx];
  136. }
  137. }
  138. }
  139. }
  140. /**
  141. * Restore the offset in the paginator if no new offset is provided.
  142. */
  143. if (isset($aMailbox['UIDSET'][$iSetIndx]) && !isset($aConfig['offset']) && $aCachedMailbox['OFFSET']) {
  144. $aMailbox['OFFSET'] = $aCachedMailbox['OFFSET'];
  145. $aMailbox['PAGEOFFSET'] = $aCachedMailbox['PAGEOFFSET'];
  146. } else {
  147. $aMailbox['OFFSET'] = (isset($aConfig['offset']) && $aConfig['offset']) ? $aConfig['offset'] -1 : 0;
  148. $aMailbox['PAGEOFFSET'] = (isset($aConfig['offset']) && $aConfig['offset']) ? $aConfig['offset'] : 1;
  149. }
  150. /**
  151. * Restore the number of messages in the result set
  152. */
  153. if (isset($aCachedMailbox['TOTAL'][$iSetIndx]) && $aCachedMailbox['TOTAL'][$iSetIndx]) {
  154. $aMailbox['TOTAL'][$iSetIndx] = $aCachedMailbox['TOTAL'][$iSetIndx];
  155. }
  156. /**
  157. * Restore the showall value no new showall value is provided.
  158. */
  159. if (isset($aMailbox['UIDSET'][$iSetIndx]) && !isset($aConfig['showall']) &&
  160. isset($aCachedMailbox['SHOWALL'][$iSetIndx]) && $aCachedMailbox['SHOWALL'][$iSetIndx]) {
  161. $aMailbox['SHOWALL'][$iSetIndx] = $aCachedMailbox['SHOWALL'][$iSetIndx];
  162. } else {
  163. $aMailbox['SHOWALL'][$iSetIndx] = (isset($aConfig['showall']) && $aConfig['showall']) ? 1 : 0;
  164. }
  165. /**
  166. * Restore the sort order if no new sort order is provided.
  167. */
  168. if (!isset($aProps[MBX_PREF_SORT]) && isset($aCachedMailbox['SORT'])) {
  169. $aMailbox['SORT'] = $aCachedMailbox['SORT'];
  170. } else {
  171. $aMailbox['SORT'] = (isset($aProps[MBX_PREF_SORT])) ? $aProps[MBX_PREF_SORT] : 0;
  172. }
  173. /**
  174. * Restore the number of message to show per page when no new limit is provided
  175. */
  176. if (!isset($aProps[MBX_PREF_LIMIT]) && isset($aCachedMailbox['LIMIT'])) {
  177. $aMailbox['LIMIT'] = $aCachedMailbox['LIMIT'];
  178. } else {
  179. $aMailbox['LIMIT'] = (isset($aProps[MBX_PREF_LIMIT])) ? $aProps[MBX_PREF_LIMIT] : 15;
  180. }
  181. /**
  182. * Restore the ordered columns to show when no new ordered columns are provided
  183. */
  184. if (!isset($aProps[MBX_PREF_COLUMNS]) && isset($aCachedMailbox['COLUMNS'])) {
  185. $aMailbox['COLUMNS'] = $aCachedMailbox['COLUMNS'];
  186. } else {
  187. $aMailbox['COLUMNS'] = (isset($aProps[MBX_PREF_COLUMNS])) ? $aProps[MBX_PREF_COLUMNS] :
  188. array(SQM_COL_FLAGS,SQM_COL_FROM, SQM_COL_SUBJ, SQM_COL_FLAGS);
  189. }
  190. /**
  191. * Restore the headers we fetch the last time. Saves intitialisation stuff in read_body.
  192. */
  193. $aMailbox['FETCHHEADERS'] = (isset($aCachedMailbox['FETCHHEADERS'])) ? $aCachedMailbox['FETCHHEADERS'] : null;
  194. if (!isset($aProps[MBX_PREF_AUTO_EXPUNGE]) && isset($aCachedMailbox['AUTO_EXPUNGE'])) {
  195. $aMailbox['AUTO_EXPUNGE'] = $aCachedMailbox['AUTO_EXPUNGE'];
  196. } else {
  197. $aMailbox['AUTO_EXPUNGE'] = (isset($aProps[MBX_PREF_AUTO_EXPUNGE])) ? $aProps[MBX_PREF_AUTO_EXPUNGE] : false;
  198. }
  199. if (!isset($aConfig['search']) && isset($aCachedMailbox['SEARCH'][$iSetIndx])) {
  200. $aMailbox['SEARCH'][$iSetIndx] = $aCachedMailbox['SEARCH'][$iSetIndx];
  201. } else if (isset($aConfig['search']) && isset($aCachedMailbox['SEARCH'][$iSetIndx]) &&
  202. $aConfig['search'] != $aCachedMailbox['SEARCH'][$iSetIndx]) {
  203. // reset the pageindex
  204. $aMailbox['SEARCH'][$iSetIndx] = $aConfig['search'];
  205. $aMailbox['OFFSET'] = 0;
  206. $aMailbox['PAGEOFFSET'] = 1;
  207. } else {
  208. $aMailbox['SEARCH'][$iSetIndx] = (isset($aConfig['search'])) ? $aConfig['search'] : 'ALL';
  209. }
  210. if (!isset($aConfig['charset']) && isset($aCachedMailbox['CHARSET'][$iSetIndx])) {
  211. $aMailbox['CHARSET'][$iSetIndx] = $aCachedMailbox['CHARSET'][$iSetIndx];
  212. } else {
  213. $aMailbox['CHARSET'][$iSetIndx] = (isset($aConfig['charset'])) ? $aConfig['charset'] : 'US-ASCII';
  214. }
  215. $aMailbox['NAME'] = $mailbox;
  216. $aMailbox['EXISTS'] = $aMbxResponse['EXISTS'];
  217. $aMailbox['SEEN'] = (isset($aMbxResponse['SEEN'])) ? $aMbxResponse['SEEN'] : $aMbxResponse['EXISTS'];
  218. $aMailbox['RECENT'] = (isset($aMbxResponse['RECENT'])) ? $aMbxResponse['RECENT'] : 0;
  219. $aMailbox['UIDVALIDITY'] = $aMbxResponse['UIDVALIDITY'];
  220. $aMailbox['UIDNEXT'] = $aMbxResponse['UIDNEXT'];
  221. $aMailbox['PERMANENTFLAGS'] = $aMbxResponse['PERMANENTFLAGS'];
  222. $aMailbox['RIGHTS'] = $aMbxResponse['RIGHTS'];
  223. /* decide if we are thread sorting or not */
  224. if ($aMailbox['SORT'] & SQSORT_THREAD) {
  225. if (!sqimap_capability($imapConnection,'THREAD')) {
  226. $aMailbox['SORT'] ^= SQSORT_THREAD;
  227. } else {
  228. $aMailbox['THREAD_INDENT'] = $aCachedMailbox['THREAD_INDENT'];
  229. }
  230. } else {
  231. $aMailbox['THREAD_INDENT'] = false;
  232. }
  233. /* set a timestamp for cachecontrol */
  234. $aMailbox['TIMESTAMP'] = time();
  235. return $aMailbox;
  236. }
  237. /**
  238. * Fetch the message headers for a mailbox. Settings are part of the aMailbox
  239. * array. Dependent of the mailbox settings it deals with sort, thread and search
  240. * If server sort is supported then SORT is also used for retrieving sorted search results
  241. *
  242. * @param resource $imapConnection imap socket handle
  243. * @param array $aMailbox (reference) mailbox retrieved from sqm_api_mailbox_select
  244. * @return error $error error number
  245. * @since 1.5.1
  246. * @author Marc Groot Koerkamp
  247. */
  248. function fetchMessageHeaders($imapConnection, &$aMailbox) {
  249. /* FIX ME, this function is kind of big, maybe we can split it up in
  250. a couple of functions. Make sure the functions are private and starts with _
  251. Also make sure that the error codes are propagated */
  252. /**
  253. * Retrieve the UIDSET.
  254. * Setindex is used to be able to store multiple uid sets. That will make it
  255. * possible to display the mailbox multiple times in different sort order
  256. * or to store serach results separate from normal mailbox view.
  257. */
  258. $iSetIndx = (isset($aMailbox['SETINDEX'])) ? $aMailbox['SETINDEX'] : 0;
  259. $iLimit = ($aMailbox['SHOWALL'][$iSetIndx]) ? $aMailbox['EXISTS'] : $aMailbox['LIMIT'];
  260. /**
  261. * Adjust the start_msg
  262. */
  263. $start_msg = $aMailbox['PAGEOFFSET'];
  264. if($aMailbox['PAGEOFFSET'] > $aMailbox['EXISTS']) {
  265. $start_msg -= $aMailbox['LIMIT'];
  266. if($start_msg < 1) {
  267. $start_msg = 1;
  268. }
  269. }
  270. if (is_array($aMailbox['UIDSET'])) {
  271. $aUid =& $aMailbox['UIDSET'][$iSetIndx];
  272. } else {
  273. $aUid = false;
  274. }
  275. $aFetchHeaders = $aMailbox['FETCHHEADERS'];
  276. $iError = 0;
  277. $aFetchItems = $aHeaderItems = array();
  278. // initialize the fields we want to retrieve:
  279. $aHeaderFields = array();
  280. foreach ($aFetchHeaders as $v) {
  281. switch ($v) {
  282. case SQM_COL_DATE: $aHeaderFields[] = 'Date'; break;
  283. case SQM_COL_TO: $aHeaderFields[] = 'To'; break;
  284. case SQM_COL_CC: $aHeaderFields[] = 'Cc'; break;
  285. case SQM_COL_FROM: $aHeaderFields[] = 'From'; break;
  286. case SQM_COL_SUBJ: $aHeaderFields[] = 'Subject'; break;
  287. case SQM_COL_PRIO: $aHeaderFields[] = 'X-Priority'; break;
  288. case SQM_COL_ATTACHMENT: $aHeaderFields[] = 'Content-Type'; break;
  289. case SQM_COL_INT_DATE: $aFetchItems[] = 'INTERNALDATE'; break;
  290. case SQM_COL_FLAGS: $aFetchItems[] = 'FLAGS'; break;
  291. case SQM_COL_SIZE: $aFetchItems[] = 'RFC822.SIZE'; break;
  292. default: break;
  293. }
  294. }
  295. /**
  296. * A uidset with sorted uid's is available. We can use the cache
  297. */
  298. if (isset($aUid) && $aUid ) {
  299. // limit the cache to SQM_MAX_PAGES_IN_CACHE
  300. if (!$aMailbox['SHOWALL'][$iSetIndx] && isset($aMailbox['MSG_HEADERS'])) {
  301. $iMaxMsgs = $iLimit * SQM_MAX_PAGES_IN_CACHE;
  302. $iCacheSize = count($aMailbox['MSG_HEADERS']);
  303. if ($iCacheSize > $iMaxMsgs) {
  304. $iReduce = $iCacheSize - $iMaxMsgs;
  305. foreach ($aMailbox['MSG_HEADERS'] as $iUid => $value) {
  306. if ($iReduce) {
  307. unset($aMailbox['MSG_HEADERS'][$iUid]);
  308. } else {
  309. break;
  310. }
  311. --$iReduce;
  312. }
  313. }
  314. }
  315. $id_slice = array_slice($aUid,$start_msg-1,$iLimit);
  316. /* do some funky cache checks */
  317. if (isset($aMailbox['MSG_HEADERS']) && is_array($aMailbox['MSG_HEADERS'])) {
  318. $aUidCached = array_keys($aMailbox['MSG_HEADERS']);
  319. } else {
  320. $aMailbox['MSG_HEADERS'] = array();
  321. $aUidCached = array();
  322. }
  323. $aUidNotCached = array_values(array_diff($id_slice,$aUidCached));
  324. /**
  325. * $aUidNotCached contains an array with UID's which need to be fetched to
  326. * complete the needed message headers.
  327. */
  328. if (count($aUidNotCached)) {
  329. $aMsgs = sqimap_get_small_header_list($imapConnection,$aUidNotCached,
  330. $aHeaderFields,$aFetchItems);
  331. // append the msgs to the existend headers
  332. $aMailbox['MSG_HEADERS'] += $aMsgs;
  333. }
  334. } else {
  335. /**
  336. * Initialize the sorted UID list or initiate a UID list with search
  337. * results and fetch the visible message headers
  338. */
  339. if ($aMailbox['SEARCH'][$iSetIndx] != 'ALL') { // in case of a search request
  340. if ($aMailbox['SEARCH'][$iSetIndx] && $aMailbox['SORT'] == 0) {
  341. $aUid = sqimap_run_search($imapConnection, $aMailbox['SEARCH'][$iSetIndx], $aMailbox['CHARSET'][$iSetIndx]);
  342. } else {
  343. $iError = 0;
  344. $iError = _get_sorted_msgs_list($imapConnection,$aMailbox,$iError);
  345. $aUid = $aMailbox['UIDSET'][$iSetIndx];
  346. }
  347. if (!$iError) {
  348. /**
  349. * Number of messages is the resultset
  350. */
  351. $aMailbox['TOTAL'][$iSetIndx] = count($aUid);
  352. $id_slice = array_slice($aUid,$aMailbox['OFFSET'], $iLimit);
  353. if (count($id_slice)) {
  354. $aMailbox['MSG_HEADERS'] = sqimap_get_small_header_list($imapConnection,$id_slice,
  355. $aHeaderFields,$aFetchItems);
  356. } else {
  357. $iError = 1; // FIX ME, define an error code
  358. }
  359. }
  360. } else { //
  361. $iError = 0;
  362. $iError = _get_sorted_msgs_list($imapConnection,$aMailbox,$iError);
  363. $aUid = $aMailbox['UIDSET'][$iSetIndx];
  364. if (!$iError) {
  365. /**
  366. * Number of messages is the resultset
  367. */
  368. $aMailbox['TOTAL'][$iSetIndx] = count($aUid);
  369. $id_slice = array_slice($aUid,$aMailbox['OFFSET'], $iLimit);
  370. if (count($id_slice)) {
  371. $aMailbox['MSG_HEADERS'] = sqimap_get_small_header_list($imapConnection,$id_slice,
  372. $aHeaderFields,$aFetchItems);
  373. } else {
  374. $iError = 1; // FIX ME, define an error code
  375. }
  376. }
  377. }
  378. }
  379. return $iError;
  380. }
  381. /**
  382. * Prepares the message headers for display inside a template. The links are calculated,
  383. * color for row highlighting is calculated and optionally the strings are truncated.
  384. *
  385. * @param array $aMailbox (reference) mailbox retrieved from sqm_api_mailbox_select
  386. * @param array $aProps properties
  387. * @return array $aFormattedMessages array with message headers and format info
  388. * @since 1.5.1
  389. * @author Marc Groot Koerkamp
  390. */
  391. function prepareMessageList(&$aMailbox, $aProps) {
  392. /* Globalize link attributes so plugins can share in modifying them */
  393. global $link, $title, $target, $onclick, $link_extra;
  394. /* retrieve the properties */
  395. $my_email_address = (isset($aProps['email'])) ? $aProps['email'] : false;
  396. $highlight_list = (isset($aProps['config']['highlight_list'])) ? $aProps['config']['highlight_list'] : false;
  397. $aColumnDesc = (isset($aProps['columns'])) ? $aProps['columns'] : false;
  398. $aExtraColumns = (isset($aProps['extra_columns'])) ? $aProps['extra_columns'] : array();
  399. $iAccount = (isset($aProps['account'])) ? (int) $aProps['account'] : 0;
  400. $sMailbox = (isset($aProps['mailbox'])) ? $aProps['mailbox'] : false;
  401. $sTargetModule = (isset($aProps['module'])) ? $aProps['module'] : 'read_body';
  402. /*
  403. * TODO 1, retrieve array with identity email addresses in order to match against to,cc and set a flag
  404. * $aFormattedMessages[$iUid]['match_identity'] = true
  405. * The template can show some image if there is a match.
  406. * TODO 2, makes sure the matching is done fast by doing a strpos call on the returned $value
  407. */
  408. /**
  409. * Only retrieve values for displayable columns
  410. */
  411. foreach ($aColumnDesc as $k => $v) {
  412. switch ($k) {
  413. case SQM_COL_FROM: $aCol[SQM_COL_FROM] = 'from'; break;
  414. case SQM_COL_DATE: $aCol[SQM_COL_DATE] = 'date'; break;
  415. case SQM_COL_SUBJ: $aCol[SQM_COL_SUBJ] = 'subject'; break;
  416. case SQM_COL_FLAGS: $aCol[SQM_COL_FLAGS] = 'FLAGS'; break;
  417. case SQM_COL_SIZE: $aCol[SQM_COL_SIZE] = 'SIZE'; break;
  418. case SQM_COL_PRIO: $aCol[SQM_COL_PRIO] = 'x-priority'; break;
  419. case SQM_COL_ATTACHMENT: $aCol[SQM_COL_ATTACHMENT] = 'content-type'; break;
  420. case SQM_COL_INT_DATE: $aCol[SQM_COL_INT_DATE] = 'INTERNALDATE'; break;
  421. case SQM_COL_TO: $aCol[SQM_COL_TO] = 'to'; break;
  422. case SQM_COL_CC: $aCol[SQM_COL_CC] = 'cc'; break;
  423. case SQM_COL_BCC: $aCol[SQM_COL_BCC] = 'bcc'; break;
  424. default: break;
  425. }
  426. }
  427. $aExtraHighLightColumns = array();
  428. foreach ($aExtraColumns as $v) {
  429. switch ($v) {
  430. case SQM_COL_FROM: $aExtraHighLightColumns[] = 'from'; break;
  431. case SQM_COL_SUBJ: $aExtraHighLightColumns[] = 'subject'; break;
  432. case SQM_COL_TO: $aExtraHighLightColumns[] = 'to'; break;
  433. case SQM_COL_CC: $aExtraHighLightColumns[] = 'cc'; break;
  434. case SQM_COL_BCC: $aExtraHighLightColumns[] = 'bcc'; break;
  435. default: break;
  436. }
  437. }
  438. $aFormattedMessages = array();
  439. $iSetIndx = $aMailbox['SETINDEX'];
  440. $aId = $aMailbox['UIDSET'][$iSetIndx];
  441. $aHeaders =& $aMailbox['MSG_HEADERS']; /* use a reference to avoid a copy.
  442. MSG_HEADERS can contain large amounts of data */
  443. $iOffset = $aMailbox['OFFSET'];
  444. $sort = $aMailbox['SORT'];
  445. $iPageOffset = $aMailbox['PAGEOFFSET'];
  446. $sMailbox = $aMailbox['NAME'];
  447. $sSearch = (isset($aMailbox['SEARCH'][$aMailbox['SETINDEX']]) &&
  448. $aMailbox['SEARCH'][$aMailbox['SETINDEX']] != 'ALL') ? $aMailbox['SEARCH'][$aMailbox['SETINDEX']] : false;
  449. $aSearch = ($sSearch) ? array('search.php',$aMailbox['SETINDEX']) : null;
  450. /* avoid improper usage */
  451. if ($sMailbox && isset($iAccount) && $sTargetModule) {
  452. $aInitQuery = array("account=$iAccount",'mailbox='.urlencode($sMailbox));
  453. } else {
  454. $aInitQuery = false;
  455. }
  456. if ($aMailbox['SORT'] & SQSORT_THREAD) {
  457. $aIndentArray =& $aMailbox['THREAD_INDENT'][$aMailbox['SETINDEX']];
  458. $bThread = true;
  459. } else {
  460. $bThread = false;
  461. }
  462. /*
  463. * Retrieve value for checkbox column
  464. */
  465. if (!sqgetGlobalVar('checkall',$checkall,SQ_GET)) {
  466. $checkall = false;
  467. }
  468. /*
  469. * Loop through and display the info for each message.
  470. */
  471. $iEnd = ($aMailbox['SHOWALL'][$iSetIndx]) ? $aMailbox['EXISTS'] : $iOffset + $aMailbox['LIMIT'];
  472. for ($i=$iOffset,$t=0;$i<$iEnd;++$i) {
  473. if (isset($aId[$i])) {
  474. $bHighLight = false;
  475. $value = $title = $link = $target = $onclick = $link_extra = '';
  476. $aQuery = ($aInitQuery !== false) ? $aInitQuery : false;
  477. $aMsg = $aHeaders[$aId[$i]];
  478. if (isset($aSearch) && count($aSearch) > 1 && $aQuery) {
  479. $aQuery[] = "where=". $aSearch[0];
  480. $aQuery[] = "what=" . $aSearch[1];
  481. }
  482. $iUid = (isset($aMsg['UID'])) ? $aMsg['UID'] : $aId[$i];
  483. if ($aQuery) {
  484. $aQuery[] = "passed_id=$aId[$i]";
  485. $aQuery[] = "startMessage=$iPageOffset";
  486. }
  487. foreach ($aCol as $k => $v) {
  488. $title = $link = $target = $onclick = $link_extra = '';
  489. $aColumns[$k] = array();
  490. $value = (isset($aMsg[$v])) ? $aMsg[$v] : '';
  491. $sUnknown = _("Unknown recipient");
  492. switch ($k) {
  493. case SQM_COL_FROM:
  494. $sUnknown = _("Unknown sender");
  495. case SQM_COL_TO:
  496. case SQM_COL_CC:
  497. case SQM_COL_BCC:
  498. $sTmp = false;
  499. if ($value) {
  500. if ($highlight_list && !$bHighLight) {
  501. $bHighLight = highlightMessage($aCol[$k], $value, $highlight_list,$aFormattedMessages[$iUid]);
  502. }
  503. $aAddressList = parseRFC822Address($value);
  504. $sTmp = getAddressString($aAddressList,array('best' => true));
  505. $title = $title_maybe = '';
  506. foreach ($aAddressList as $aAddr) {
  507. $sPersonal = (isset($aAddr[SQM_ADDR_PERSONAL])) ? $aAddr[SQM_ADDR_PERSONAL] : '';
  508. $sMailbox = (isset($aAddr[SQM_ADDR_MAILBOX])) ? $aAddr[SQM_ADDR_MAILBOX] : '';
  509. $sHost = (isset($aAddr[SQM_ADDR_HOST])) ? $aAddr[SQM_ADDR_HOST] : '';
  510. if ($sPersonal) {
  511. $title .= htmlspecialchars($sMailbox.'@'.$sHost).', ';
  512. } else {
  513. // if $value gets truncated we need to add the addresses with no
  514. // personal name as well
  515. $title_maybe .= htmlspecialchars($sMailbox.'@'.$sHost).', ';
  516. }
  517. }
  518. if ($title) {
  519. $title = substr($title,0,-2); // strip ', ';
  520. }
  521. $sTmp = decodeHeader($sTmp);
  522. if (isset($aColumnDesc[$k]['truncate']) && $aColumnDesc[$k]['truncate']) {
  523. $sTrunc = truncateWithEntities($sTmp, $aColumnDesc[$k]['truncate']);
  524. if ($sTrunc != $sTmp) {
  525. if (!$title) {
  526. $title = htmlspecialchars($sTmp);
  527. } else if ($title_maybe) {
  528. $title = $title .', '.$title_maybe;
  529. $title = substr($title,0,-2); // strip ', ';
  530. }
  531. }
  532. $sTmp = $sTrunc;
  533. }
  534. }
  535. $value = ($sTmp) ? $sTmp : $sUnknown;
  536. break;
  537. case SQM_COL_SUBJ:
  538. // subject is mime encoded, decode it.
  539. // value is sanitized in decoding function.
  540. // TODO, verify if it should be done before or after the highlighting
  541. $value=decodeHeader($value);
  542. if ($highlight_list && !$bHighLight) {
  543. $bHighLight = highlightMessage('SUBJECT', $value, $highlight_list, $aFormattedMessages[$iUid]);
  544. }
  545. $iIndent = (isset($aIndentArray[$aId[$i]])) ? $aIndentArray[$aId[$i]] : 0;
  546. // FIXME: don't break 8bit symbols and html entities during truncation
  547. if (isset($aColumnDesc[$k]['truncate']) && $aColumnDesc[$k]['truncate']) {
  548. $sTmp = truncateWithEntities($value, $aColumnDesc[$k]['truncate']-$iIndent);
  549. // drop any double spaces since these will be displayed in the title
  550. $title = ($sTmp != $value) ? preg_replace('/\s{2,}/', ' ', $value) : '';
  551. $value = $sTmp;
  552. }
  553. /* generate the link to the message */
  554. if ($aQuery) {
  555. // TODO, $sTargetModule should be a query parameter so that we can use a single entrypoint
  556. $link = $sTargetModule.'.php?' . implode('&amp;',$aQuery);
  557. // see top of this function for which attributes are available
  558. // in the global scope for plugin use (like $link, $target,
  559. // $onclick, $link_extra, $title, and so forth)
  560. // plugins are responsible for sharing nicely (such as for
  561. // setting the target, etc)
  562. do_hook('subject_link', array($iPageOffset, $sSearch, $aSearch));
  563. }
  564. $value = (trim($value)) ? $value : _("(no subject)");
  565. /* add thread indentation */
  566. $aColumns[$k]['indent'] = $iIndent;
  567. break;
  568. case SQM_COL_SIZE:
  569. $value = show_readable_size($value);
  570. break;
  571. case SQM_COL_DATE:
  572. case SQM_COL_INT_DATE:
  573. $value = getDateString(getTimeStamp(explode(' ',trim($value))));
  574. break;
  575. case SQM_COL_FLAGS:
  576. $aFlagColumn = array('seen' => false,
  577. 'deleted'=>false,
  578. 'answered'=>false,
  579. 'flagged' => false,
  580. 'draft' => false);
  581. if(!is_array($value)) $value = array();
  582. foreach ($value as $sFlag => $value) {
  583. switch ($sFlag) {
  584. case '\\seen' : $aFlagColumn['seen'] = true; break;
  585. case '\\deleted' : $aFlagColumn['deleted'] = true; break;
  586. case '\\answered': $aFlagColumn['answered'] = true; break;
  587. case '\\flagged' : $aFlagColumn['flagged'] = true; break;
  588. case '\\draft' : $aFlagColumn['draft'] = true; break;
  589. default: break;
  590. }
  591. }
  592. $value = $aFlagColumn;
  593. break;
  594. case SQM_COL_PRIO:
  595. $value = ($value) ? (int) $value : 3;
  596. break;
  597. case SQM_COL_ATTACHMENT:
  598. $value = (is_array($value) && $value[0] == 'multipart' && $value[1] == 'mixed') ? true : false;
  599. break;
  600. case SQM_COL_CHECK:
  601. $value = $checkall;
  602. break;
  603. default : break;
  604. }
  605. if ($title) { $aColumns[$k]['title'] = $title; }
  606. if ($link) { $aColumns[$k]['link'] = $link; }
  607. if ($link_extra) { $aColumns[$k]['link_extra'] = $link_extra; }
  608. if ($onclick) { $aColumns[$k]['onclick'] = $onclick; }
  609. if ($target) { $aColumns[$k]['target'] = $target; }
  610. $aColumns[$k]['value'] = $value;
  611. }
  612. /* columns which will not be displayed but should be inspected
  613. because the highlight list contains rules with those columns */
  614. foreach ($aExtraHighLightColumns as $v) {
  615. if ($highlight_list && !$bHighLight && isset($aMsg[$v])) {
  616. $bHighLight = highlightMessage($v, $aMsg[$v], $highlight_list,$aFormattedMessages[$iUid]);
  617. }
  618. }
  619. $aFormattedMessages[$iUid]['columns'] = $aColumns;
  620. } else {
  621. break;
  622. }
  623. }
  624. return $aFormattedMessages;
  625. }
  626. /**
  627. * Sets the row color if the provided column value pair matches a hightlight rule
  628. *
  629. * @param string $sCol column name
  630. * @param string $sVal column value
  631. * @param array $highlight_list highlight rules
  632. * @param array $aFormat (reference) array where row color info is stored
  633. * @return bool match found
  634. * @since 1.5.1
  635. * @author Marc Groot Koerkamp
  636. */
  637. function highlightMessage($sCol, $sVal, $highlight_list, &$aFormat) {
  638. if (!is_array($highlight_list) && count($highlight_list) == 0) {
  639. return false;
  640. }
  641. $hlt_color = false;
  642. $sCol = strtoupper($sCol);
  643. foreach ($highlight_list as $highlight_list_part) {
  644. if (trim($highlight_list_part['value'])) {
  645. $high_val = strtolower($highlight_list_part['value']);
  646. $match_type = strtoupper($highlight_list_part['match_type']);
  647. if($match_type == 'TO_CC') {
  648. if ($sCol == 'TO' || $sCol == 'CC') {
  649. $match_type = $sCol;
  650. } else {
  651. continue;
  652. }
  653. } else {
  654. if ($match_type != $sCol) {
  655. continue;
  656. }
  657. }
  658. if (strpos(strtolower($sVal),$high_val) !== false) {
  659. $hlt_color = $highlight_list_part['color'];
  660. break;
  661. }
  662. }
  663. }
  664. if ($hlt_color) {
  665. // Bug in highlight color???
  666. if ($hlt_color{0} != '#') {
  667. $hlt_color = '#'. $hlt_color;
  668. }
  669. $aFormat['row']['color'] = $hlt_color;
  670. return true;
  671. } else {
  672. return false;
  673. }
  674. }
  675. function setUserPref($username, $pref, $value) {
  676. global $data_dir;
  677. setPref($data_dir,$username,$pref,$value);
  678. }
  679. /**
  680. * Execute the sorting for a mailbox
  681. *
  682. * @param resource $imapConnection Imap connection
  683. * @param array $aMailbox (reference) Mailbox retrieved with sqm_api_mailbox_select
  684. * @return int $error (reference) Error number
  685. * @private
  686. * @since 1.5.1
  687. * @author Marc Groot Koerkamp
  688. */
  689. function _get_sorted_msgs_list($imapConnection,&$aMailbox) {
  690. $iSetIndx = (isset($aMailbox['SETINDEX'])) ? $aMailbox['SETINDEX'] : 0;
  691. $bDirection = !($aMailbox['SORT'] % 2);
  692. $error = 0;
  693. if (!$aMailbox['SEARCH'][$iSetIndx]) {
  694. $aMailbox['SEARCH'][$iSetIndx] = 'ALL';
  695. }
  696. if (($aMailbox['SORT'] & SQSORT_THREAD) && sqimap_capability($imapConnection,'THREAD')) {
  697. $aRes = get_thread_sort($imapConnection,$aMailbox['SEARCH'][$iSetIndx]);
  698. if ($aRes === false) {
  699. $aMailbox['SORT'] -= SQSORT_THREAD;
  700. $error = 1; // fix me, define an error code;
  701. } else {
  702. $aMailbox['UIDSET'][$iSetIndx] = $aRes[0];
  703. $aMailbox['THREAD_INDENT'][$iSetIndx] = $aRes[1];
  704. }
  705. } else if ($aMailbox['SORT'] === SQSORT_NONE) {
  706. $id = sqimap_run_search($imapConnection, 'ALL' , '');
  707. if ($id === false) {
  708. $error = 1; // fix me, define an error code
  709. } else {
  710. $aMailbox['UIDSET'][$iSetIndx] = array_reverse($id);
  711. $aMailbox['TOTAL'][$iSetIndx] = $aMailbox['EXISTS'];
  712. }
  713. } else {
  714. if (sqimap_capability($imapConnection,'SORT')) {
  715. $sSortField = _getSortField($aMailbox['SORT'],true);
  716. $id = sqimap_get_sort_order($imapConnection, $sSortField, $bDirection, $aMailbox['SEARCH'][$iSetIndx]);
  717. if ($id === false) {
  718. $error = 1; // fix me, define an error code
  719. } else {
  720. $aMailbox['UIDSET'][$iSetIndx] = $id;
  721. }
  722. } else {
  723. $id = NULL;
  724. if ($aMailbox['SEARCH'][$iSetIndx] != 'ALL') {
  725. $id = sqimap_run_search($imapConnection, $aMailbox['SEARCH'][$iSetIndx], $aMailbox['CHARSET'][$iSetIndx]);
  726. }
  727. $sSortField = _getSortField($aMailbox['SORT'],false);
  728. $aMailbox['UIDSET'][$iSetIndx] = get_squirrel_sort($imapConnection, $sSortField, $bDirection, $id);
  729. }
  730. }
  731. return $error;
  732. }
  733. /**
  734. * Does the $srt $_GET var to field mapping
  735. *
  736. * @param int $srt Field to sort on
  737. * @param bool $bServerSort Server sorting is true
  738. * @return string $sSortField Field to sort on
  739. * @since 1.5.1
  740. * @private
  741. */
  742. function _getSortField($sort,$bServerSort) {
  743. switch($sort) {
  744. case SQSORT_NONE:
  745. $sSortField = 'UID';
  746. break;
  747. case SQSORT_DATE_ASC:
  748. case SQSORT_DATE_DESC:
  749. $sSortField = 'DATE';
  750. break;
  751. case SQSORT_FROM_ASC:
  752. case SQSORT_FROM_DESC:
  753. $sSortField = 'FROM';
  754. break;
  755. case SQSORT_SUBJ_ASC:
  756. case SQSORT_SUBJ_DESC:
  757. $sSortField = 'SUBJECT';
  758. break;
  759. case SQSORT_SIZE_ASC:
  760. case SQSORT_SIZE_DESC:
  761. $sSortField = ($bServerSort) ? 'SIZE' : 'RFC822.SIZE';
  762. break;
  763. case SQSORT_TO_ASC:
  764. case SQSORT_TO_DESC:
  765. $sSortField = 'TO';
  766. break;
  767. case SQSORT_CC_ASC:
  768. case SQSORT_CC_DESC:
  769. $sSortField = 'CC';
  770. break;
  771. case SQSORT_INT_DATE_ASC:
  772. case SQSORT_INT_DATE_DESC:
  773. $sSortField = ($bServerSort) ? 'ARRIVAL' : 'INTERNALDATE';
  774. break;
  775. case SQSORT_THREAD:
  776. break;
  777. default: $sSortField = 'UID';
  778. break;
  779. }
  780. return $sSortField;
  781. }
  782. /**
  783. * This function is a utility function for setting which headers should be
  784. * fetched. It takes into account the highlight list which requires extra
  785. * headers to be fetch in order to make those rules work. It's called before
  786. * the headers are fetched which happens in showMessagesForMailbox and when
  787. * the next and prev links in read_body.php are used.
  788. *
  789. * @param array $aMailbox associative array with mailbox related vars
  790. * @param array $aProps
  791. * @return void
  792. * @since 1.5.1
  793. */
  794. function calcFetchColumns(&$aMailbox, &$aProps) {
  795. $highlight_list = (isset($aProps['config']['highlight_list'])) ? $aProps['config']['highlight_list'] : false;
  796. $aColumnsDesc = (isset($aProps['columns'])) ? $aProps['columns'] : false;
  797. $aFetchColumns = $aColumnsDesc;
  798. if (isset($aFetchColumns[SQM_COL_CHECK])) {
  799. unset($aFetchColumns[SQM_COL_CHECK]);
  800. }
  801. /*
  802. * Before we fetch the message headers, check if we need to fetch extra columns
  803. * to make the message highlighting work
  804. */
  805. if (is_array($highlight_list) && count($highlight_list)) {
  806. $aHighlightColumns = array();
  807. foreach ($highlight_list as $highlight_list_part) {
  808. if (trim($highlight_list_part['value'])) {
  809. $match_type = strtoupper($highlight_list_part['match_type']);
  810. switch ($match_type) {
  811. case 'TO_CC':
  812. $aHighlightColumns[SQM_COL_TO] = true;
  813. $aHighlightColumns[SQM_COL_CC] = true;
  814. break;
  815. case 'TO': $aHighlightColumns[SQM_COL_TO] = true; break;
  816. case 'CC': $aHighlightColumns[SQM_COL_CC] = true; break;
  817. case 'FROM': $aHighlightColumns[SQM_COL_FROM] = true; break;
  818. case 'SUBJECT':$aHighlightColumns[SQM_COL_SUBJ] = true; break;
  819. }
  820. }
  821. }
  822. $aExtraColumns = array();
  823. foreach ($aHighlightColumns as $k => $v) {
  824. if (!isset($aFetchColumns[$k])) {
  825. $aExtraColumns[] = $k;
  826. $aFetchColumns[$k] = true;
  827. }
  828. }
  829. if (count($aExtraColumns)) {
  830. $aProps['extra_columns'] = $aExtraColumns;
  831. }
  832. }
  833. $aMailbox['FETCHHEADERS'] = array_keys($aFetchColumns);
  834. }
  835. /**
  836. * This function loops through a group of messages in the mailbox
  837. * and shows them to the user.
  838. *
  839. * @param resource $imapConnection
  840. * @param array $aMailbox associative array with mailbox related vars
  841. * @param array $aProps
  842. * @param int $iError error code, 0 is no error
  843. */
  844. function showMessagesForMailbox($imapConnection, &$aMailbox,$aProps, &$iError) {
  845. global $PHP_SELF;
  846. global $boxes;
  847. $highlight_list = (isset($aProps['config']['highlight_list'])) ? $aProps['config']['highlight_list'] : false;
  848. $fancy_index_highlite = (isset($aProps['config']['fancy_index_highlite'])) ? $aProps['config']['fancy_index_highlite'] : true;
  849. $aColumnsDesc = (isset($aProps['columns'])) ? $aProps['columns'] : false;
  850. $iAccount = (isset($aProps['account'])) ? (int) $aProps['account'] : 0;
  851. $sMailbox = (isset($aProps['mailbox'])) ? $aProps['mailbox'] : false;
  852. $sTargetModule = (isset($aProps['module'])) ? $aProps['module'] : 'read_body';
  853. $show_flag_buttons = (isset($aProps['config']['show_flag_buttons'])) ? $aProps['config']['show_flag_buttons'] : true;
  854. $lastTargetMailbox = (isset($aProps['config']['lastTargetMailbox'])) ? $aProps['config']['lastTargetMailbox'] : '';
  855. $aOrder = array_keys($aProps['columns']);
  856. $trash_folder = (isset($aProps['config']['trash_folder']) && $aProps['config']['trash_folder'])
  857. ? $aProps['config']['trash_folder'] : false;
  858. $sent_folder = (isset($aProps['config']['sent_folder']) && $aProps['config']['sent_folder'])
  859. ? $aProps['config']['sent_folder'] : false;
  860. $draft_folder = (isset($aProps['config']['draft_folder']) && $aProps['config']['draft_folder'])
  861. ? $aProps['config']['draft_folder'] : false;
  862. $page_selector = (isset($aProps['config']['page_selector'])) ? $aProps['config']['page_selector'] : false;
  863. $page_selector_max = (isset($aProps['config']['page_selector_max'])) ? $aProps['config']['page_selector_max'] : 10;
  864. $color = $aProps['config']['color'];
  865. /*
  866. * Form ID
  867. */
  868. static $iFormId;
  869. if (!isset($iFormId)) {
  870. $iFormId=1;
  871. } else {
  872. ++$iFormId;
  873. }
  874. // store the columns to fetch so we can pick them up in read_body
  875. // where we validate the cache.
  876. calcFetchColumns($aMailbox ,$aProps);
  877. $iError = fetchMessageHeaders($imapConnection, $aMailbox);
  878. if ($iError) {
  879. return array();
  880. } else {
  881. $aMessages = prepareMessageList($aMailbox, $aProps);
  882. }
  883. $iSetIndx = $aMailbox['SETINDEX'];
  884. $iLimit = ($aMailbox['SHOWALL'][$iSetIndx]) ? $aMailbox['EXISTS'] : $aMailbox['LIMIT'];
  885. $iEnd = ($aMailbox['PAGEOFFSET'] + ($iLimit - 1) < $aMailbox['EXISTS']) ?
  886. $aMailbox['PAGEOFFSET'] + $iLimit - 1 : $aMailbox['EXISTS'];
  887. $iNumberOfMessages = $aMailbox['TOTAL'][$iSetIndx];
  888. $iEnd = min ( $iEnd, $iNumberOfMessages );
  889. $php_self = $PHP_SELF;
  890. $urlMailbox = urlencode($aMailbox['NAME']);
  891. if (preg_match('/^(.+)\?.+$/',$php_self,$regs)) {
  892. $source_url = $regs[1];
  893. } else {
  894. $source_url = $php_self;
  895. }
  896. $baseurl = $source_url.'?mailbox=' . urlencode($aMailbox['NAME']) .'&amp;account='.$aMailbox['ACCOUNT'];
  897. $where = urlencode($aMailbox['SEARCH'][$iSetIndx][0]);
  898. $what = urlencode($aMailbox['SEARCH'][$iSetIndx][1]);
  899. $baseurl .= '&amp;where=' . $where . '&amp;what=' . $what;
  900. /* build thread sorting links */
  901. $newsort = $aMailbox['SORT'];
  902. if (sqimap_capability($imapConnection,'THREAD')) {
  903. if ($aMailbox['SORT'] & SQSORT_THREAD) {
  904. $newsort -= SQSORT_THREAD;
  905. $thread_name = _("Unthread View");
  906. } else {
  907. $thread_name = _("Thread View");
  908. $newsort = $aMailbox['SORT'] + SQSORT_THREAD;
  909. }
  910. $thread_link_str = '<small>[<a href="' . $baseurl . '&amp;srt='
  911. . $newsort . '&amp;startMessage=1">' . $thread_name
  912. . '</a>]</small>';
  913. } else {
  914. $thread_link_str ='';
  915. }
  916. $sort = $aMailbox['SORT'];
  917. /* FIX ME ADD CHECKBOX CONTROL. No checkbox => no buttons */
  918. /* future admin control over displayable buttons */
  919. $aAdminControl = array(
  920. 'markUnflagged' => 1,
  921. 'markFlagged' => 1,
  922. 'markRead' => 1,
  923. 'markUnread' => 1,
  924. 'forward' => 1,
  925. 'delete' => 1,
  926. 'undeleteButton'=> 1,
  927. 'bypass_trash' => 1,
  928. 'expungeButton' => 1,
  929. 'moveButton' => 1
  930. );
  931. /* user prefs control */
  932. $aUserControl = array (
  933. 'markUnflagged' => $show_flag_buttons,
  934. 'markFlagged' => $show_flag_buttons,
  935. 'markRead' => 1,
  936. 'markUnread' => 1,
  937. 'forward' => 1,
  938. 'delete' => 1,
  939. 'undeleteButton'=> 1,
  940. 'bypass_trash' => 1,
  941. 'expungeButton' => 1,
  942. 'moveButton' => 1
  943. );
  944. $showDelete = ($aMailbox['RIGHTS'] != 'READ-ONLY' &&
  945. in_array('\\deleted',$aMailbox['PERMANENTFLAGS'], true)) ? true : false;
  946. $showByPassTrash = (($aMailbox['AUTO_EXPUNGE'] && $aMailbox['RIGHTS'] != 'READ-ONLY' &&
  947. in_array('\\deleted',$aMailbox['PERMANENTFLAGS'], true)) &&
  948. $trash_folder) ? true : false; //
  949. $showUndelete = (!$aMailbox['AUTO_EXPUNGE'] && $aMailbox['RIGHTS'] != 'READ-ONLY' &&
  950. in_array('\\deleted',$aMailbox['PERMANENTFLAGS'], true) && !$trash_folder) ? true : false;
  951. $showMove = ($aMailbox['RIGHTS'] != 'READ-ONLY') ? true : false;
  952. $showExpunge = (!$aMailbox['AUTO_EXPUNGE'] && $aMailbox['RIGHTS'] != 'READ-ONLY' &&
  953. in_array('\\deleted',$aMailbox['PERMANENTFLAGS'], true)) ? true : false;
  954. $aImapControl = array (
  955. 'markUnflagged' => in_array('\\flagged',$aMailbox['PERMANENTFLAGS'], true),
  956. 'markFlagged' => in_array('\\flagged',$aMailbox['PERMANENTFLAGS'], true),
  957. 'markRead' => in_array('\\seen',$aMailbox['PERMANENTFLAGS'], true),
  958. 'markUnread' => in_array('\\seen',$aMailbox['PERMANENTFLAGS'], true),
  959. 'forward' => 1,
  960. 'delete' => $showDelete,
  961. 'undeleteButton'=> $showUndelete,
  962. 'bypass_trash' => $showByPassTrash,
  963. 'expungeButton' => $showExpunge,
  964. 'moveButton' => $showMove
  965. );
  966. $aButtonStrings = array(
  967. 'markUnflagged' => _("Unflag"),
  968. 'markFlagged' => _("Flag"),
  969. 'markRead' => _("Read"),
  970. 'markUnread' => _("Unread"),
  971. 'forward' => _("Forward"),
  972. 'delete' => _("Delete"),
  973. 'undeleteButton' => _("Undelete"),
  974. 'bypass_trash' => _("Bypass Trash"),
  975. 'expungeButton' => _("Expunge"),
  976. 'moveButton' => _("Move")
  977. );
  978. /**
  979. * Register buttons in order to an array
  980. * The key is the "name", the first element of the value array is the "value", second argument is the type.
  981. */
  982. $aFormElements = array();
  983. foreach($aAdminControl as $k => $v) {
  984. if ($v & $aUserControl[$k] & $aImapControl[$k]) {
  985. switch ($k) {
  986. case 'markUnflagged':
  987. case 'markFlagged':
  988. case 'markRead':
  989. case 'markUnread':
  990. case 'delete':
  991. case 'undeleteButton':
  992. case 'expungeButton':
  993. case 'forward':
  994. $aFormElements[$k] = array($aButtonStrings[$k],'submit');
  995. break;
  996. case 'bypass_trash':
  997. $aFormElements[$k] = array($aButtonStrings[$k],'checkbox');
  998. break;
  999. case 'moveButton':
  1000. $aFormElements['targetMailbox'] =
  1001. array(sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)), 0, $boxes),'select');
  1002. $aFormElements['mailbox'] = array($aMailbox['NAME'],'hidden');
  1003. $aFormElements['startMessage'] = array($aMailbox['PAGEOFFSET'],'hidden');
  1004. $aFormElements[$k] = array($aButtonStrings[$k],'submit');
  1005. break;
  1006. }
  1007. }
  1008. $aFormElements['account'] = array($iAccount,'hidden');
  1009. }
  1010. /*
  1011. * This is the beginning of the message list table.
  1012. * It wraps around all messages
  1013. */
  1014. $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $aMailbox['NAME']);
  1015. $form_name = "FormMsgs" . $safe_name;
  1016. //if (!sqgetGlobalVar('align',$align,SQ_SESSION)) {
  1017. $align = array('left' => 'left', 'right' => 'right');
  1018. //}
  1019. //sm_print_r($align);
  1020. /* finally set the template vars */
  1021. // FIX ME, before we support multiple templates we must review the names of the vars
  1022. $aTemplate['color'] = $color;
  1023. $aTemplate['form_name'] = "FormMsgs" . $safe_name;
  1024. $aTemplate['form_id'] = 'mbx_'.$iFormId;
  1025. $aTemplate['page_selector'] = $page_selector;
  1026. $aTemplate['page_selector_max'] = $page_selector_max;
  1027. $aTemplate['messagesPerPage'] = $aMailbox['LIMIT'];
  1028. $aTemplate['showall'] = $aMailbox['SHOWALL'][$iSetIndx];
  1029. $aTemplate['end_msg'] = $iEnd;
  1030. $aTemplate['align'] = $align;
  1031. $aTemplate['iNumberOfMessages'] = $iNumberOfMessages;
  1032. $aTemplate['aOrder'] = $aOrder;
  1033. $aTemplate['aFormElements'] = $aFormElements;
  1034. $aTemplate['sort'] = $sort;
  1035. $aTemplate['pageOffset'] = $aMailbox['PAGEOFFSET'];
  1036. $aTemplate['baseurl'] = $baseurl;
  1037. $aTemplate['aMessages'] =& $aMessages;
  1038. $aTemplate['trash_folder'] = $trash_folder;
  1039. $aTemplate['sent_folder'] = $sent_folder;
  1040. $aTemplate['draft_folder'] = $draft_folder;
  1041. $aTemplate['thread_link_str'] = $thread_link_str;
  1042. $aTemplate['php_self'] = str_replace('&','&amp;',$php_self);
  1043. $aTemplate['mailbox'] = $sMailbox;
  1044. $aTemplate['javascript_on'] = (isset($aProps['config']['javascript_on'])) ? $aProps['config']['javascript_on'] : false;
  1045. $aTemplate['enablesort'] = (isset($aProps['config']['enablesort'])) ? $aProps['config']['enablesort'] : false;
  1046. $aTemplate['icon_theme'] = (isset($aProps['config']['icon_theme'])) ? $aProps['config']['icon_theme'] : false;
  1047. $aTemplate['use_icons'] = (isset($aProps['config']['use_icons'])) ? $aProps['config']['use_icons'] : false;
  1048. $aTemplate['alt_index_colors'] = (isset($aProps['config']['alt_index_colors'])) ? $aProps['config']['alt_index_colors'] : false;
  1049. $aTemplate['fancy_index_highlite'] = $fancy_index_highlite;
  1050. return $aTemplate;
  1051. }
  1052. /**
  1053. * Truncates a string and take care of html encoded characters
  1054. *
  1055. * @param string $s string to truncate
  1056. * @param int $iTrimAt Trim at nn characters
  1057. * @return string Trimmed string
  1058. */
  1059. function truncateWithEntities($s, $iTrimAt) {
  1060. global $languages, $squirrelmail_language;
  1061. $ent_strlen = strlen($s);
  1062. if (($iTrimAt <= 0) || ($ent_strlen <= $iTrimAt))
  1063. return $s;
  1064. if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
  1065. function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_strimwidth')) {
  1066. return call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_strimwidth', $s, $iTrimAt);
  1067. } else {
  1068. /*
  1069. * see if this is entities-encoded string
  1070. * If so, Iterate through the whole string, find out
  1071. * the real number of characters, and if more
  1072. * than $iTrimAt, substr with an updated trim value.
  1073. */
  1074. $trim_val = $iTrimAt;
  1075. $ent_offset = 0;
  1076. $ent_loc = 0;
  1077. while ( $ent_loc < $trim_val && (($ent_loc = strpos($s, '&', $ent_offset)) !== false) &&
  1078. (($ent_loc_end = strpos($s, ';', $ent_loc+3)) !== false) ) {
  1079. $trim_val += ($ent_loc_end-$ent_loc);
  1080. $ent_offset = $ent_loc_end+1;
  1081. }
  1082. if (($trim_val > $iTrimAt) && ($ent_strlen > $trim_val) && (strpos($s,';',$trim_val) < ($trim_val + 6))) {
  1083. $i = strpos($s,';',$trim_val);
  1084. if ($i !== false) {
  1085. $trim_val = strpos($s,';',$trim_val)+1;
  1086. }
  1087. }
  1088. // only print '...' when we're actually dropping part of the subject
  1089. if ($ent_strlen <= $trim_val)
  1090. return $s;
  1091. }
  1092. return substr_replace($s, '...', $trim_val);
  1093. }
  1094. /**
  1095. * This should go in imap_mailbox.php
  1096. * @param string $mailbox
  1097. */
  1098. function handleAsSent($mailbox) {
  1099. global $handleAsSent_result;
  1100. /* First check if this is the sent or draft folder. */
  1101. $handleAsSent_result = isSentMailbox($mailbox) || isDraftMailbox($mailbox);
  1102. /* Then check the result of the handleAsSent hook. */
  1103. do_hook('check_handleAsSent_result', $mailbox);
  1104. /* And return the result. */
  1105. return $handleAsSent_result;
  1106. }
  1107. /**
  1108. * Process messages list form and handle the cache gracefully. If $sButton and
  1109. * $aUid are provided as argument then you can fake a message list submit and
  1110. * use it i.e. in read_body.php for del move next and update the cache
  1111. *
  1112. * @param resource $imapConnection imap connection
  1113. * @param array $aMailbox (reference) cached mailbox
  1114. * @param string $sButton fake a submit button
  1115. * @param array $aUid fake the $msg array
  1116. * @return string $sError error string in case of an error
  1117. * @since 1.5.1
  1118. * @author Marc Groot Koerkamp
  1119. */
  1120. function handleMessageListForm($imapConnection,&$aMailbox,$sButton='',$aUid = array()) {
  1121. /* incoming formdata */
  1122. $sButton = (sqgetGlobalVar('moveButton', $sTmp, SQ_POST)) ? 'move' : $sButton;
  1123. $sButton = (sqgetGlobalVar('expungeButton', $sTmp, SQ_POST)) ? 'expunge' : $sButton;
  1124. $sButton = (sqgetGlobalVar('forward', $sTmp, SQ_POST)) ? 'forward' : $sButton;
  1125. $sButton = (sqgetGlobalVar('delete', $sTmp, SQ_POST)) ? 'setDeleted' : $sButton;
  1126. $sButton = (sqgetGlobalVar('undeleteButton', $sTmp, SQ_POST)) ? 'unsetDeleted' : $sButton;
  1127. $sButton = (sqgetGlobalVar('markRead', $sTmp, SQ_POST)) ? 'setSeen' : $sButton;
  1128. $sButton = (sqgetGlobalVar('markUnread', $sTmp, SQ_POST)) ? 'unsetSeen' : $sButton;
  1129. $sButton = (sqgetGlobalVar('markFlagged', $sTmp, SQ_POST)) ? 'setFlagged' : $sButton;
  1130. $sButton = (sqgetGlobalVar('markUnflagged', $sTmp, SQ_POST)) ? 'unsetFlagged' : $sButton;
  1131. sqgetGlobalVar('targetMailbox', $targetMailbox, SQ_POST);
  1132. sqgetGlobalVar('bypass_trash', $bypass_trash, SQ_POST);
  1133. sqgetGlobalVar('msg', $msg, SQ_POST);
  1134. if (sqgetGlobalVar('account', $iAccount, SQ_POST) === false) {
  1135. $iAccount = 0;
  1136. }
  1137. $sError = '';
  1138. $mailbox = $aMailbox['NAME'];
  1139. /* retrieve the check boxes */
  1140. $aUid = (isset($msg) && is_array($msg)) ? array_values($msg) : $aUid;
  1141. if (count($aUid) && $sButton != 'expunge') {
  1142. $aUpdatedMsgs = false;
  1143. $bExpunge = false;
  1144. switch ($sButton) {
  1145. case 'setDeleted':
  1146. // check if id exists in case we come from read_body
  1147. if (count($aUid) == 1 && is_array($aMailbox['UIDSET'][$aMailbox['SETINDEX']]) &&
  1148. !in_array($aUid[0],$aMailbox['UIDSET'][$aMailbox['SETINDEX']])) {
  1149. break;
  1150. }
  1151. $aUpdatedMsgs = sqimap_msgs_list_delete($imapConnection, $mailbox, $aUid,$bypass_trash);
  1152. $bExpunge = true;
  1153. //}
  1154. break;
  1155. case 'unsetDeleted':
  1156. case 'setSeen':
  1157. case 'unsetSeen':
  1158. case 'setFlagged':
  1159. case 'unsetFlagged':
  1160. // get flag
  1161. $sFlag = (substr($sButton,0,3) == 'set') ? '\\'.substr($sButton,3) : '\\'.substr($sButton,5);
  1162. $bSet = (substr($sButton,0,3) == 'set') ? true : false;
  1163. $aUpdatedMsgs = sqimap_toggle_flag($imapConnection, $aUid, $sFlag, $bSet, true);
  1164. break;
  1165. case 'move':
  1166. $aUpdatedMsgs = sqimap_msgs_list_move($imapConnection,$aUid,$targetMailbox,true,$mailbox);
  1167. sqsession_register($targetMailbox,'lastTargetMailbox');
  1168. $bExpunge = true;
  1169. break;
  1170. case 'forward':
  1171. $aMsgHeaders = array();
  1172. foreach ($aUid as $iUid) {
  1173. $aMsgHeaders[$iUid] = $aMailbox['MSG_HEADERS'][$iUid];
  1174. }
  1175. if (count($aMsgHeaders)) {
  1176. $composesession = attachSelectedMessages($imapConnection,$aMsgHeaders);
  1177. // dirty hack, add info to $aMailbox
  1178. $aMailbox['FORWARD_SESSION'] = $composesession;
  1179. }
  1180. break;
  1181. default:
  1182. // Hook for plugin buttons
  1183. do_hook_function('mailbox_display_button_action', $aUid);
  1184. break;
  1185. }
  1186. /**
  1187. * Updates messages is an array containing the result of the untagged
  1188. * fetch responses send by the imap server due to a flag change. That
  1189. * response is parsed in a array with msg arrays by the parseFetch function
  1190. */
  1191. if ($aUpdatedMsgs) {
  1192. // Update the message headers cache
  1193. $aDeleted = array();
  1194. foreach ($aUpdatedMsgs as $iUid => $aMsg) {
  1195. if (isset($aMsg['FLAGS'])) {
  1196. /**
  1197. * Only update the cached headers if the header is
  1198. * cached.
  1199. */
  1200. if (isset($aMailbox['MSG_HEADERS'][$iUid])) {
  1201. $aMailbox['MSG_HEADERS'][$iUid]['FLAGS'] = $aMsg['FLAGS'];
  1202. }
  1203. /**
  1204. * Count the messages with the \Delete flag set so we can determine
  1205. * if the number of expunged messages equals the number of flagged
  1206. * messages for deletion.
  1207. */
  1208. if (isset($aMsg['FLAGS']['\\deleted']) && $aMsg['FLAGS']['\\deleted']) {
  1209. $aDeleted[] = $iUid;
  1210. }
  1211. }
  1212. }
  1213. if ($bExpunge && $aMailbox['AUTO_EXPUNGE'] &&
  1214. $iExpungedMessages = sqimap_mailbox_expunge($imapConnection, $aMailbox['NAME'], true))
  1215. {
  1216. if (count($aDeleted) != $iExpungedMessages) {
  1217. // there are more messages deleted permanently then we expected
  1218. // invalidate the cache
  1219. $aMailbox['UIDSET'][$aMailbox['SETINDEX']] = false;
  1220. $aMailbox['MSG_HEADERS'] = false;
  1221. } else {
  1222. // remove expunged messages from cache
  1223. $aUidSet = $aMailbox['UIDSET'][$aMailbox['SETINDEX']];
  1224. if (is_array($aUidSet)) {
  1225. // create a UID => array index temp array
  1226. $aUidSetDummy = array_flip($aUidSet);
  1227. foreach ($aDeleted as $iUid) {
  1228. // get the id as well in case of SQM_SORT_NONE
  1229. if ($aMailbox['SORT'] == SQSORT_NONE) {
  1230. $aMailbox['ID'] = false;
  1231. //$iId = $aMailbox['MSG_HEADERS'][$iUid]['ID'];
  1232. //unset($aMailbox['ID'][$iId]);
  1233. }
  1234. // unset the UID and message header
  1235. unset($aUidSetDummy[$iUid]);
  1236. unset($aMailbox['MSG_HEADERS'][$iUid]);
  1237. }
  1238. $aMailbox['UIDSET'][$aMailbox['SETINDEX']] = array_keys($aUidSetDummy);
  1239. }
  1240. }
  1241. // update EXISTS info
  1242. if ($iExpungedMessages) {
  1243. $aMailbox['EXISTS'] -= (int) $iExpungedMessages;
  1244. $aMailbox['TOTAL'][$aMailbox['SETINDEX']] -= (int) $iExpungedMessages;
  1245. }
  1246. if (($aMailbox['PAGEOFFSET']-1) >= $aMailbox['EXISTS']) {
  1247. $aMailbox['PAGEOFFSET'] = ($aMailbox['PAGEOFFSET'] > $aMailbox['LIMIT']) ?
  1248. $aMailbox['PAGEOFFSET'] - $aMailbox['LIMIT'] : 1;
  1249. $aMailbox['OFFSET'] = $aMailbox['PAGEOFFSET'] - 1 ;
  1250. }
  1251. }
  1252. }
  1253. } else {
  1254. if ($sButton == 'expunge') {
  1255. /**
  1256. * on expunge we do not know which messages will be deleted
  1257. * so it's useless to try to sync the cache
  1258. *
  1259. * Close the mailbox so we do not need to parse the untagged expunge
  1260. * responses which do not contain uid info.
  1261. * NB: Closing a mailbox is faster then expunge because the imap
  1262. * server does not need to generate the untagged expunge responses
  1263. */
  1264. sqimap_run_command($imapConnection,'CLOSE',false,$result,$message);
  1265. $aMailbox = sqm_api_mailbox_select($imapConnection,$iAccount, $aMailbox['NAME'],array(),array());
  1266. } else {
  1267. if ($sButton) {
  1268. $sError = _("No messages were selected.");
  1269. }
  1270. }
  1271. }
  1272. return $sError;
  1273. }
  1274. /**
  1275. * Attach messages to a compose session
  1276. *
  1277. * @param resource $imapConnection imap connection
  1278. * @param array $aMsgHeaders
  1279. * @return int $composesession unique compose_session_id where the attached messages belong to
  1280. * @author Marc Groot Koerkamp
  1281. */
  1282. function attachSelectedMessages($imapConnection,$aMsgHeaders) {
  1283. global $username, $attachment_dir,
  1284. $data_dir;
  1285. sqgetGlobalVar('composesession', $composesession, SQ_SESSION);
  1286. sqgetGlobalVar('compose_messages', $compose_messages, SQ_SESSION);
  1287. if (!isset($compose_messages)|| is_null($compose_messages)) {
  1288. $compose_messages = array();
  1289. sqsession_register($compose_messages,'compose_messages');
  1290. }
  1291. if (!$composesession) {
  1292. $composesession = 1;
  1293. sqsession_register($composesession,'composesession');
  1294. } else {
  1295. $composesession++;
  1296. sqsession_register($composesession,'composesession');
  1297. }
  1298. $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
  1299. $composeMessage = new Message();
  1300. $rfc822_header = new Rfc822Header();
  1301. $composeMessage->rfc822_header = $rfc822_header;
  1302. $composeMessage->reply_rfc822_header = '';
  1303. foreach($aMsgHeaders as $iUid => $aMsgHeader) {
  1304. /**
  1305. * Retrieve the full message
  1306. */
  1307. $body_a = sqimap_run_command($imapConnection, "FETCH $iUid RFC822", true, $response, $readmessage, TRUE);
  1308. if ($response == 'OK') {
  1309. $subject = (isset($aMsgHeader['subject'])) ? $aMsgHeader['subject'] : $iUid;
  1310. array_shift($body_a);
  1311. array_pop($body_a);
  1312. $body = implode('', $body_a);
  1313. $body .= "\r\n";
  1314. $localfilename = GenerateRandomString(32, 'FILE', 7);
  1315. $full_localfilename = "$hashed_attachment_dir/$localfilename";
  1316. $fp = fopen( $full_localfilename, 'wb');
  1317. fwrite ($fp, $body);
  1318. fclose($fp);
  1319. $composeMessage->initAttachment('message/rfc822',$subject.'.msg',
  1320. $full_localfilename);
  1321. }
  1322. }
  1323. $compose_messages[$composesession] = $composeMessage;
  1324. sqsession_register($compose_messages,'compose_messages');
  1325. return $composesession;
  1326. }
  1327. ?>