imap_mailbox.php 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081
  1. <?php
  2. /**
  3. * imap_mailbox.php
  4. *
  5. * Copyright (c) 1999-2005 The SquirrelMail Project Team
  6. * Licensed under the GNU GPL. For full terms see the file COPYING.
  7. *
  8. * This impliments all functions that manipulate mailboxes
  9. *
  10. * @version $Id$
  11. * @package squirrelmail
  12. * @subpackage imap
  13. */
  14. /** UTF7 support */
  15. require_once(SM_PATH . 'functions/imap_utf7_local.php');
  16. global $boxesnew;
  17. /**
  18. * Mailboxes class
  19. *
  20. * FIXME. This class should be extracted and placed in a separate file that
  21. * can be included before we start the session. That makes caching of the tree
  22. * possible. On a refresh mailboxes from left_main.php the only function that
  23. * should be called is the sqimap_get_status_mbx_tree. In case of subscribe
  24. * / rename / delete / new we have to create methods for adding/changing the
  25. * mailbox in the mbx_tree without the need for a refresh.
  26. * @package squirrelmail
  27. */
  28. class mailboxes {
  29. var $mailboxname_full = '', $mailboxname_sub= '', $is_noselect = false, $is_noinferiors = false,
  30. $is_special = false, $is_root = false, $is_inbox = false, $is_sent = false,
  31. $is_trash = false, $is_draft = false, $mbxs = array(),
  32. $unseen = false, $total = false;
  33. function addMbx($mbx, $delimiter, $start, $specialfirst) {
  34. $ary = explode($delimiter, $mbx->mailboxname_full);
  35. $mbx_parent =& $this;
  36. for ($i = $start, $c = count($ary)-1; $i < $c; $i++) {
  37. $mbx_childs =& $mbx_parent->mbxs;
  38. $found = false;
  39. if ($mbx_childs) {
  40. foreach ($mbx_childs as $key => $parent) {
  41. if ($parent->mailboxname_sub == $ary[$i]) {
  42. $mbx_parent =& $mbx_parent->mbxs[$key];
  43. $found = true;
  44. break;
  45. }
  46. }
  47. }
  48. if (!$found) {
  49. $no_select_mbx = new mailboxes();
  50. if (isset($mbx_parent->mailboxname_full) && $mbx_parent->mailboxname_full != '') {
  51. $no_select_mbx->mailboxname_full = $mbx_parent->mailboxname_full.$delimiter.$ary[$i];
  52. } else {
  53. $no_select_mbx->mailboxname_full = $ary[$i];
  54. }
  55. $no_select_mbx->mailboxname_sub = $ary[$i];
  56. $no_select_mbx->is_noselect = true;
  57. $mbx_parent->mbxs[] = $no_select_mbx;
  58. $i--;
  59. }
  60. }
  61. $mbx_parent->mbxs[] = $mbx;
  62. if ($mbx->is_special && $specialfirst) {
  63. usort($mbx_parent->mbxs, 'sortSpecialMbx');
  64. }
  65. }
  66. }
  67. function sortSpecialMbx($a, $b) {
  68. if ($a->is_inbox) {
  69. $acmp = '0'. $a->mailboxname_full;
  70. } else if ($a->is_special) {
  71. $acmp = '1'. $a->mailboxname_full;
  72. } else {
  73. $acmp = '2' . $a->mailboxname_full;
  74. }
  75. if ($b->is_inbox) {
  76. $bcmp = '0'. $b->mailboxname_full;
  77. }else if ($b->is_special) {
  78. $bcmp = '1' . $b->mailboxname_full;
  79. } else {
  80. $bcmp = '2' . $b->mailboxname_full;
  81. }
  82. return strnatcasecmp($acmp, $bcmp);
  83. }
  84. function compact_mailboxes_response($ary)
  85. {
  86. /*
  87. * Workaround for mailboxes returned as literal
  88. * FIXME : Doesn't work if the mailbox name is multiple lines
  89. * (larger then fgets buffer)
  90. */
  91. for ($i = 0, $iCnt=count($ary); $i < $iCnt; $i++) {
  92. if (isset($ary[$i + 1]) && substr($ary[$i], -3) == "}\r\n") {
  93. if (ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$",
  94. $ary[$i], $regs)) {
  95. $ary[$i] = $regs[1] . '"' . addslashes(trim($ary[$i+1])) . '"' . $regs[2];
  96. array_splice($ary, $i+1, 2);
  97. }
  98. }
  99. }
  100. /* remove duplicates and ensure array is contiguous */
  101. return array_values(array_unique($ary));
  102. }
  103. /**
  104. * Extract the mailbox name from an untagged LIST (7.2.2) or LSUB (7.2.3) answer
  105. * (LIST|LSUB) (<Flags list>) (NIL|"<separator atom>") <mailbox name string>\r\n
  106. * mailbox name in quoted string MUST be unquoted and stripslashed (sm API)
  107. */
  108. function find_mailbox_name($line)
  109. {
  110. if (preg_match('/^\* (?:LIST|LSUB) \([^\)]*\) (?:NIL|\"[^\"]*\") ([^\r\n]*)[\r\n]*$/i', $line, $regs)) {
  111. if (substr($regs[1], 0, 1) == '"')
  112. return stripslashes(substr($regs[1], 1, -1));
  113. return $regs[1];
  114. }
  115. return '';
  116. }
  117. /**
  118. * @return bool whether this is a Noselect mailbox.
  119. */
  120. function check_is_noselect ($lsub_line) {
  121. return preg_match("/^\* (LSUB|LIST) \([^\)]*\\\\Noselect[^\)]*\)/i", $lsub_line);
  122. }
  123. /**
  124. * @return bool whether this is a Noinferiors mailbox.
  125. */
  126. function check_is_noinferiors ($lsub_line) {
  127. return preg_match("/^\* (LSUB|LIST) \([^\)]*\\\\Noinferiors[^\)]*\)/i", $lsub_line);
  128. }
  129. /**
  130. * If $haystack is a full mailbox name, and $needle is the mailbox
  131. * separator character, returns the second last part of the full
  132. * mailbox name (i.e. the mailbox's parent mailbox)
  133. */
  134. function readMailboxParent($haystack, $needle) {
  135. if ($needle == '') {
  136. $ret = '';
  137. } else {
  138. $parts = explode($needle, $haystack);
  139. $elem = array_pop($parts);
  140. while ($elem == '' && count($parts)) {
  141. $elem = array_pop($parts);
  142. }
  143. $ret = join($needle, $parts);
  144. }
  145. return( $ret );
  146. }
  147. /**
  148. * Check if $subbox is below the specified $parentbox
  149. */
  150. function isBoxBelow( $subbox, $parentbox ) {
  151. global $delimiter;
  152. /*
  153. * Eliminate the obvious mismatch, where the
  154. * subfolder path is shorter than that of the potential parent
  155. */
  156. if ( strlen($subbox) < strlen($parentbox) ) {
  157. return false;
  158. }
  159. /* check for delimiter */
  160. if (substr($parentbox,-1) != $delimiter) {
  161. $parentbox .= $delimiter;
  162. }
  163. return (substr($subbox,0,strlen($parentbox)) == $parentbox);
  164. }
  165. /**
  166. * Defines special mailboxes: given a mailbox name, it checks if this is a
  167. * "special" one: INBOX, Trash, Sent or Draft.
  168. */
  169. function isSpecialMailbox( $box ) {
  170. $ret = ( (strtolower($box) == 'inbox') ||
  171. isTrashMailbox($box) || isSentMailbox($box) || isDraftMailbox($box) );
  172. if ( !$ret ) {
  173. $ret = boolean_hook_function('special_mailbox',$box,1);
  174. }
  175. return $ret;
  176. }
  177. /**
  178. * @return bool whether this is a Trash folder
  179. */
  180. function isTrashMailbox ($box) {
  181. global $trash_folder, $move_to_trash;
  182. return $move_to_trash && $trash_folder &&
  183. ( $box == $trash_folder || isBoxBelow($box, $trash_folder) );
  184. }
  185. /**
  186. * @return bool whether this is a Sent folder
  187. */
  188. function isSentMailbox($box) {
  189. global $sent_folder, $move_to_sent;
  190. return $move_to_sent && $sent_folder &&
  191. ( $box == $sent_folder || isBoxBelow($box, $sent_folder) );
  192. }
  193. /**
  194. * @return bool whether this is a Draft folder
  195. */
  196. function isDraftMailbox($box) {
  197. global $draft_folder, $save_as_draft;
  198. return $save_as_draft &&
  199. ( $box == $draft_folder || isBoxBelow($box, $draft_folder) );
  200. }
  201. /**
  202. * Expunges a mailbox, ie. delete all contents.
  203. */
  204. function sqimap_mailbox_expunge ($imap_stream, $mailbox, $handle_errors = true, $id='') {
  205. if ($id) {
  206. if (is_array($id)) {
  207. $id = sqimap_message_list_squisher($id);
  208. }
  209. $id = ' '.$id;
  210. $uid = TRUE;
  211. } else {
  212. $uid = false;
  213. }
  214. $read = sqimap_run_command($imap_stream, 'EXPUNGE'.$id, $handle_errors,
  215. $response, $message, $uid);
  216. $cnt = 0;
  217. if (is_array($read)) {
  218. foreach ($read as $r) {
  219. if (preg_match('/^\*\s[0-9]+\sEXPUNGE/AUi',$r,$regs)) {
  220. $cnt++;
  221. }
  222. }
  223. }
  224. return $cnt;
  225. }
  226. /**
  227. * Checks whether or not the specified mailbox exists
  228. */
  229. function sqimap_mailbox_exists ($imap_stream, $mailbox) {
  230. if (!isset($mailbox) || empty($mailbox)) {
  231. return false;
  232. }
  233. $mbx = sqimap_run_command($imap_stream, 'LIST "" ' . sqimap_encode_mailbox_name($mailbox),
  234. true, $response, $message);
  235. return isset($mbx[0]);
  236. }
  237. /**
  238. * Selects a mailbox
  239. */
  240. function sqimap_mailbox_select ($imap_stream, $mailbox) {
  241. if ($mailbox == 'None') {
  242. return;
  243. }
  244. $read = sqimap_run_command($imap_stream, 'SELECT ' . sqimap_encode_mailbox_name($mailbox),
  245. true, $response, $message);
  246. $result = array();
  247. for ($i = 0, $cnt = count($read); $i < $cnt; $i++) {
  248. if (preg_match('/^\*\s+OK\s\[(\w+)\s(\w+)\]/',$read[$i], $regs)) {
  249. $result[strtoupper($regs[1])] = $regs[2];
  250. } else if (preg_match('/^\*\s([0-9]+)\s(\w+)/',$read[$i], $regs)) {
  251. $result[strtoupper($regs[2])] = $regs[1];
  252. } else {
  253. if (preg_match("/PERMANENTFLAGS(.*)/i",$read[$i], $regs)) {
  254. $regs[1]=trim(preg_replace ( array ("/\(/","/\)/","/\]/") ,'', $regs[1])) ;
  255. $result['PERMANENTFLAGS'] = explode(' ',strtolower($regs[1]));
  256. } else if (preg_match("/FLAGS(.*)/i",$read[$i], $regs)) {
  257. $regs[1]=trim(preg_replace ( array ("/\(/","/\)/") ,'', $regs[1])) ;
  258. $result['FLAGS'] = explode(' ',strtolower($regs[1]));
  259. }
  260. }
  261. }
  262. if (!isset($result['PERMANENTFLAGS'])) {
  263. $result['PERMANENTFLAGS'] = $result['FLAGS'];
  264. }
  265. if (preg_match('/^\[(.+)\]/',$message, $regs)) {
  266. $result['RIGHTS']=strtoupper($regs[1]);
  267. }
  268. return $result;
  269. }
  270. /**
  271. * Creates a folder.
  272. */
  273. function sqimap_mailbox_create ($imap_stream, $mailbox, $type) {
  274. global $delimiter;
  275. if (strtolower($type) == 'noselect') {
  276. $mailbox .= $delimiter;
  277. }
  278. $read_ary = sqimap_run_command($imap_stream, 'CREATE ' .
  279. sqimap_encode_mailbox_name($mailbox),
  280. true, $response, $message);
  281. sqimap_subscribe ($imap_stream, $mailbox);
  282. }
  283. /**
  284. * Subscribes to an existing folder.
  285. */
  286. function sqimap_subscribe ($imap_stream, $mailbox,$debug=true) {
  287. $read_ary = sqimap_run_command($imap_stream, 'SUBSCRIBE ' .
  288. sqimap_encode_mailbox_name($mailbox),
  289. $debug, $response, $message);
  290. }
  291. /**
  292. * Unsubscribes from an existing folder
  293. */
  294. function sqimap_unsubscribe ($imap_stream, $mailbox) {
  295. $read_ary = sqimap_run_command($imap_stream, 'UNSUBSCRIBE ' .
  296. sqimap_encode_mailbox_name($mailbox),
  297. false, $response, $message);
  298. }
  299. /**
  300. * Deletes the given folder
  301. */
  302. function sqimap_mailbox_delete ($imap_stream, $mailbox) {
  303. global $data_dir, $username;
  304. sqimap_unsubscribe ($imap_stream, $mailbox);
  305. $read_ary = sqimap_run_command($imap_stream, 'DELETE ' .
  306. sqimap_encode_mailbox_name($mailbox),
  307. true, $response, $message);
  308. if ($response !== 'OK') {
  309. // subscribe again
  310. sqimap_subscribe ($imap_stream, $mailbox);
  311. } else {
  312. do_hook_function('rename_or_delete_folder', $args = array($mailbox, 'delete', ''));
  313. removePref($data_dir, $username, "thread_$mailbox");
  314. removePref($data_dir, $username, "collapse_folder_$mailbox");
  315. }
  316. }
  317. /**
  318. * Determines if the user is subscribed to the folder or not
  319. */
  320. function sqimap_mailbox_is_subscribed($imap_stream, $folder) {
  321. $boxesall = sqimap_mailbox_list ($imap_stream);
  322. foreach ($boxesall as $ref) {
  323. if ($ref['unformatted'] == $folder) {
  324. return true;
  325. }
  326. }
  327. return false;
  328. }
  329. /**
  330. * Renames a mailbox.
  331. */
  332. function sqimap_mailbox_rename( $imap_stream, $old_name, $new_name ) {
  333. if ( $old_name != $new_name ) {
  334. global $delimiter, $imap_server_type, $data_dir, $username;
  335. if ( substr( $old_name, -1 ) == $delimiter ) {
  336. $old_name = substr( $old_name, 0, strlen( $old_name ) - 1 );
  337. $new_name = substr( $new_name, 0, strlen( $new_name ) - 1 );
  338. $postfix = $delimiter;
  339. } else {
  340. $postfix = '';
  341. }
  342. $boxesall = sqimap_mailbox_list_all($imap_stream);
  343. $cmd = 'RENAME ' . sqimap_encode_mailbox_name($old_name) .
  344. ' ' . sqimap_encode_mailbox_name($new_name);
  345. $data = sqimap_run_command($imap_stream, $cmd, true, $response, $message);
  346. sqimap_unsubscribe($imap_stream, $old_name.$postfix);
  347. $oldpref_thread = getPref($data_dir, $username, 'thread_'.$old_name.$postfix);
  348. $oldpref_collapse = getPref($data_dir, $username, 'collapse_folder_'.$old_name.$postfix);
  349. removePref($data_dir, $username, 'thread_'.$old_name.$postfix);
  350. removePref($data_dir, $username, 'collapse_folder_'.$old_name.$postfix);
  351. sqimap_subscribe($imap_stream, $new_name.$postfix);
  352. setPref($data_dir, $username, 'thread_'.$new_name.$postfix, $oldpref_thread);
  353. setPref($data_dir, $username, 'collapse_folder_'.$new_name.$postfix, $oldpref_collapse);
  354. do_hook_function('rename_or_delete_folder',$args = array($old_name, 'rename', $new_name));
  355. $l = strlen( $old_name ) + 1;
  356. $p = 'unformatted';
  357. foreach ($boxesall as $box) {
  358. if (substr($box[$p], 0, $l) == $old_name . $delimiter) {
  359. $new_sub = $new_name . $delimiter . substr($box[$p], $l);
  360. /* With Cyrus IMAPd >= 2.0 rename is recursive, so don't check for errors here */
  361. if ($imap_server_type == 'cyrus') {
  362. $cmd = 'RENAME "' . $box[$p] . '" "' . $new_sub . '"';
  363. $data = sqimap_run_command($imap_stream, $cmd, false,
  364. $response, $message);
  365. }
  366. $was_subscribed = sqimap_mailbox_is_subscribed($imap_stream, $box[$p]);
  367. if ( $was_subscribed ) {
  368. sqimap_unsubscribe($imap_stream, $box[$p]);
  369. }
  370. $oldpref_thread = getPref($data_dir, $username, 'thread_'.$box[$p]);
  371. $oldpref_collapse = getPref($data_dir, $username, 'collapse_folder_'.$box[$p]);
  372. removePref($data_dir, $username, 'thread_'.$box[$p]);
  373. removePref($data_dir, $username, 'collapse_folder_'.$box[$p]);
  374. if ( $was_subscribed ) {
  375. sqimap_subscribe($imap_stream, $new_sub);
  376. }
  377. setPref($data_dir, $username, 'thread_'.$new_sub, $oldpref_thread);
  378. setPref($data_dir, $username, 'collapse_folder_'.$new_sub, $oldpref_collapse);
  379. do_hook_function('rename_or_delete_folder',
  380. $args = array($box[$p], 'rename', $new_sub));
  381. }
  382. }
  383. }
  384. }
  385. /**
  386. * Formats a mailbox into parts for the $boxesall array
  387. *
  388. * The parts are:
  389. *
  390. * raw - Raw LIST/LSUB response from the IMAP server
  391. * formatted - nicely formatted folder name
  392. * unformatted - unformatted, but with delimiter at end removed
  393. * unformatted-dm - folder name as it appears in raw response
  394. * unformatted-disp - unformatted without $folder_prefix
  395. */
  396. function sqimap_mailbox_parse ($line, $line_lsub) {
  397. global $folder_prefix, $delimiter;
  398. /* Process each folder line */
  399. for ($g = 0, $cnt = count($line); $g < $cnt; ++$g) {
  400. /* Store the raw IMAP reply */
  401. if (isset($line[$g])) {
  402. $boxesall[$g]['raw'] = $line[$g];
  403. } else {
  404. $boxesall[$g]['raw'] = '';
  405. }
  406. /* Count number of delimiters ($delimiter) in folder name */
  407. $mailbox = /*trim(*/$line_lsub[$g]/*)*/;
  408. $dm_count = substr_count($mailbox, $delimiter);
  409. if (substr($mailbox, -1) == $delimiter) {
  410. /* If name ends in delimiter, decrement count by one */
  411. $dm_count--;
  412. }
  413. /* Format folder name, but only if it's a INBOX.* or has a parent. */
  414. $boxesallbyname[$mailbox] = $g;
  415. $parentfolder = readMailboxParent($mailbox, $delimiter);
  416. if ( (strtolower(substr($mailbox, 0, 5)) == "inbox") ||
  417. (substr($mailbox, 0, strlen($folder_prefix)) == $folder_prefix) ||
  418. (isset($boxesallbyname[$parentfolder]) &&
  419. (strlen($parentfolder) > 0) ) ) {
  420. $indent = $dm_count - (substr_count($folder_prefix, $delimiter));
  421. if ($indent > 0) {
  422. $boxesall[$g]['formatted'] = str_repeat('&nbsp;&nbsp;', $indent);
  423. } else {
  424. $boxesall[$g]['formatted'] = '';
  425. }
  426. $boxesall[$g]['formatted'] .= imap_utf7_decode_local(readShortMailboxName($mailbox, $delimiter));
  427. } else {
  428. $boxesall[$g]['formatted'] = imap_utf7_decode_local($mailbox);
  429. }
  430. $boxesall[$g]['unformatted-dm'] = $mailbox;
  431. if (substr($mailbox, -1) == $delimiter) {
  432. $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
  433. }
  434. $boxesall[$g]['unformatted'] = $mailbox;
  435. if (substr($mailbox,0,strlen($folder_prefix))==$folder_prefix) {
  436. $mailbox = substr($mailbox, strlen($folder_prefix));
  437. }
  438. $boxesall[$g]['unformatted-disp'] = $mailbox;
  439. $boxesall[$g]['id'] = $g;
  440. $boxesall[$g]['flags'] = array();
  441. if (isset($line[$g])) {
  442. ereg("\(([^)]*)\)",$line[$g],$regs);
  443. // FIXME Flags do contain the \ character. \NoSelect \NoInferiors
  444. // and $MDNSent <= last one doesn't have the \
  445. // It's better to follow RFC3501 instead of using our own naming.
  446. $flags = trim(strtolower(str_replace('\\', '',$regs[1])));
  447. if ($flags) {
  448. $boxesall[$g]['flags'] = explode(' ', $flags);
  449. }
  450. }
  451. }
  452. return $boxesall;
  453. }
  454. /**
  455. * Returns list of options (to be echoed into select statement
  456. * based on available mailboxes and separators
  457. * Caller should surround options with <select ...> </select> and
  458. * any formatting.
  459. * $imap_stream - $imapConnection to query for mailboxes
  460. * $show_selected - array containing list of mailboxes to pre-select (0 if none)
  461. * $folder_skip - array of folders to keep out of option list (compared in lower)
  462. * $boxes - list of already fetched boxes (for places like folder panel, where
  463. * you know these options will be shown 3 times in a row.. (most often unset).
  464. * $flag - flag to check for in mailbox flags, used to filter out mailboxes.
  465. * 'noselect' by default to remove unselectable mailboxes.
  466. * 'noinferiors' used to filter out folders that can not contain subfolders.
  467. * NULL to avoid flag check entirely.
  468. * NOTE: noselect and noiferiors are used internally. The IMAP representation is
  469. * \NoSelect and \NoInferiors
  470. * $use_long_format - override folder display preference and always show full folder name.
  471. */
  472. function sqimap_mailbox_option_list($imap_stream, $show_selected = 0, $folder_skip = 0, $boxes = 0,
  473. $flag = 'noselect', $use_long_format = false ) {
  474. global $username, $data_dir;
  475. $mbox_options = '';
  476. if ( $use_long_format ) {
  477. $shorten_box_names = 0;
  478. } else {
  479. $shorten_box_names = getPref($data_dir, $username, 'mailbox_select_style', SMPREF_OFF);
  480. }
  481. if ($boxes == 0) {
  482. $boxes = sqimap_mailbox_list($imap_stream);
  483. }
  484. foreach ($boxes as $boxes_part) {
  485. if ($flag == NULL || (is_array($boxes_part['flags'])
  486. && !in_array($flag, $boxes_part['flags']))) {
  487. $box = $boxes_part['unformatted'];
  488. if ($folder_skip != 0 && in_array($box, $folder_skip) ) {
  489. continue;
  490. }
  491. $lowerbox = strtolower($box);
  492. // mailboxes are casesensitive => inbox.sent != inbox.Sent
  493. // nevermind, to many dependencies this should be fixed!
  494. if (strtolower($box) == 'inbox') { // inbox is special and not casesensitive
  495. $box2 = _("INBOX");
  496. } else {
  497. switch ($shorten_box_names)
  498. {
  499. case 2: /* delimited, style = 2 */
  500. $box2 = str_replace('&amp;nbsp;&amp;nbsp;', '.&nbsp;', htmlspecialchars($boxes_part['formatted']));
  501. break;
  502. case 1: /* indent, style = 1 */
  503. $box2 = str_replace('&amp;nbsp;&amp;nbsp;', '&nbsp;&nbsp;', htmlspecialchars($boxes_part['formatted']));
  504. break;
  505. default: /* default, long names, style = 0 */
  506. $box2 = str_replace(' ', '&nbsp;', htmlspecialchars(imap_utf7_decode_local($boxes_part['unformatted-disp'])));
  507. break;
  508. }
  509. }
  510. if ($show_selected != 0 && in_array($lowerbox, $show_selected) ) {
  511. $mbox_options .= '<option value="' . htmlspecialchars($box) .'" selected="selected">'.$box2.'</option>' . "\n";
  512. } else {
  513. $mbox_options .= '<option value="' . htmlspecialchars($box) .'">'.$box2.'</option>' . "\n";
  514. }
  515. }
  516. }
  517. return $mbox_options;
  518. }
  519. /**
  520. * Returns sorted mailbox lists in several different ways.
  521. * See comment on sqimap_mailbox_parse() for info about the returned array.
  522. * @param resource $imap_stream imap connection resource
  523. * @param boolean $force force update of mailbox listing. available since 1.4.2 and 1.5.0
  524. * @return array list of mailboxes
  525. */
  526. function sqimap_mailbox_list($imap_stream, $force=false) {
  527. if (!sqgetGlobalVar('boxesnew',$boxesnew,SQ_SESSION) || $force) {
  528. global $data_dir, $username, $list_special_folders_first,
  529. $folder_prefix, $trash_folder, $sent_folder, $draft_folder,
  530. $move_to_trash, $move_to_sent, $save_as_draft,
  531. $delimiter, $noselect_fix_enable, $imap_server_type,
  532. $show_only_subscribed_folders;
  533. $inbox_subscribed = false;
  534. $listsubscribed = sqimap_capability($imap_stream,'LIST-SUBSCRIBED');
  535. require_once(SM_PATH . 'include/load_prefs.php');
  536. if (!$show_only_subscribed_folders) {
  537. $lsub = 'LIST';
  538. } elseif ($listsubscribed) {
  539. $lsub = 'LIST (SUBSCRIBED)';
  540. } else {
  541. $lsub = 'LSUB';
  542. }
  543. if ($noselect_fix_enable) {
  544. $lsub_args = "$lsub \"$folder_prefix\" \"*%\"";
  545. } else {
  546. $lsub_args = "$lsub \"$folder_prefix\" \"*\"";
  547. }
  548. /* LSUB array */
  549. $lsub_ary = sqimap_run_command ($imap_stream, $lsub_args,
  550. true, $response, $message);
  551. $lsub_ary = compact_mailboxes_response($lsub_ary);
  552. $sorted_lsub_ary = array();
  553. for ($i = 0, $cnt = count($lsub_ary);$i < $cnt; $i++) {
  554. $temp_mailbox_name = find_mailbox_name($lsub_ary[$i]);
  555. $sorted_lsub_ary[] = $temp_mailbox_name;
  556. if (!$inbox_subscribed && strtoupper($temp_mailbox_name) == 'INBOX') {
  557. $inbox_subscribed = true;
  558. }
  559. }
  560. /* natural sort mailboxes */
  561. if (isset($sorted_lsub_ary)) {
  562. usort($sorted_lsub_ary, 'strnatcasecmp');
  563. }
  564. /*
  565. * The LSUB response doesn't provide us information about \Noselect
  566. * mail boxes. The LIST response does, that's why we need to do a LIST
  567. * call to retrieve the flags for the mailbox
  568. * Note: according RFC2060 an imap server may provide \NoSelect flags in the LSUB response.
  569. * in other words, we cannot rely on it.
  570. */
  571. $sorted_list_ary = array();
  572. // if (!$listsubscribed) {
  573. for ($i=0; $i < count($sorted_lsub_ary); $i++) {
  574. if (substr($sorted_lsub_ary[$i], -1) == $delimiter) {
  575. $mbx = substr($sorted_lsub_ary[$i], 0, strlen($sorted_lsub_ary[$i])-1);
  576. }
  577. else {
  578. $mbx = $sorted_lsub_ary[$i];
  579. }
  580. $read = sqimap_run_command ($imap_stream, 'LIST "" ' . sqimap_encode_mailbox_name($mbx),
  581. true, $response, $message);
  582. $read = compact_mailboxes_response($read);
  583. if (isset($read[0])) {
  584. $sorted_list_ary[$i] = $read[0];
  585. } else {
  586. $sorted_list_ary[$i] = '';
  587. }
  588. }
  589. // }
  590. /*
  591. * Just in case they're not subscribed to their inbox,
  592. * we'll get it for them anyway
  593. */
  594. if (!$inbox_subscribed) {
  595. $inbox_ary = sqimap_run_command ($imap_stream, 'LIST "" "INBOX"',
  596. true, $response, $message);
  597. $sorted_list_ary[] = implode('',compact_mailboxes_response($inbox_ary));
  598. $sorted_lsub_ary[] = find_mailbox_name($inbox_ary[0]);
  599. }
  600. $boxesall = sqimap_mailbox_parse ($sorted_list_ary, $sorted_lsub_ary);
  601. /* Now, lets sort for special folders */
  602. $boxesnew = $used = array();
  603. /* Find INBOX */
  604. $cnt = count($boxesall);
  605. $used = array_pad($used,$cnt,false);
  606. for($k = 0; $k < $cnt; ++$k) {
  607. if (strtolower($boxesall[$k]['unformatted']) == 'inbox') {
  608. $boxesnew[] = $boxesall[$k];
  609. $used[$k] = true;
  610. break;
  611. }
  612. }
  613. /* List special folders and their subfolders, if requested. */
  614. if ($list_special_folders_first) {
  615. for($k = 0; $k < $cnt; ++$k) {
  616. if (!$used[$k] && isSpecialMailbox($boxesall[$k]['unformatted'])) {
  617. $boxesnew[] = $boxesall[$k];
  618. $used[$k] = true;
  619. }
  620. }
  621. }
  622. /* Find INBOX's children */
  623. for($k = 0; $k < $cnt; ++$k) {
  624. if (!$used[$k] && isBoxBelow(strtolower($boxesall[$k]['unformatted']), 'inbox') &&
  625. strtolower($boxesall[$k]['unformatted']) != 'inbox') {
  626. $boxesnew[] = $boxesall[$k];
  627. $used[$k] = true;
  628. }
  629. }
  630. /* Rest of the folders */
  631. for($k = 0; $k < $cnt; $k++) {
  632. if (!$used[$k]) {
  633. $boxesnew[] = $boxesall[$k];
  634. }
  635. }
  636. sqsession_register($boxesnew,'boxesnew');
  637. }
  638. return $boxesnew;
  639. }
  640. /**
  641. * Returns a list of all folders, subscribed or not
  642. */
  643. function sqimap_mailbox_list_all($imap_stream) {
  644. global $list_special_folders_first, $folder_prefix, $delimiter;
  645. $read_ary = sqimap_run_command($imap_stream,"LIST \"$folder_prefix\" *",true,$response, $message,false);
  646. $read_ary = compact_mailboxes_response($read_ary);
  647. $g = 0;
  648. $fld_pre_length = strlen($folder_prefix);
  649. for ($i = 0, $cnt = count($read_ary); $i < $cnt; $i++) {
  650. /* Store the raw IMAP reply */
  651. $boxes[$g]['raw'] = $read_ary[$i];
  652. /* Count number of delimiters ($delimiter) in folder name */
  653. $mailbox = find_mailbox_name($read_ary[$i]);
  654. $dm_count = substr_count($mailbox, $delimiter);
  655. if (substr($mailbox, -1) == $delimiter) {
  656. /* If name ends in delimiter - decrement count by one */
  657. $dm_count--;
  658. }
  659. /* Format folder name, but only if it's a INBOX.* or has a parent. */
  660. $boxesallbyname[$mailbox] = $g;
  661. $parentfolder = readMailboxParent($mailbox, $delimiter);
  662. if((eregi('^inbox'.quotemeta($delimiter), $mailbox)) ||
  663. (ereg('^'.$folder_prefix, $mailbox)) ||
  664. ( isset($boxesallbyname[$parentfolder]) && (strlen($parentfolder) > 0) ) ) {
  665. if ($dm_count) {
  666. $boxes[$g]['formatted'] = str_repeat('&nbsp;&nbsp;', $dm_count);
  667. } else {
  668. $boxes[$g]['formatted'] = '';
  669. }
  670. $boxes[$g]['formatted'] .= imap_utf7_decode_local(readShortMailboxName($mailbox, $delimiter));
  671. } else {
  672. $boxes[$g]['formatted'] = imap_utf7_decode_local($mailbox);
  673. }
  674. $boxes[$g]['unformatted-dm'] = $mailbox;
  675. if (substr($mailbox, -1) == $delimiter) {
  676. $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
  677. }
  678. $boxes[$g]['unformatted'] = $mailbox;
  679. $boxes[$g]['unformatted-disp'] = substr($mailbox,$fld_pre_length);
  680. $boxes[$g]['id'] = $g;
  681. /* Now lets get the flags for this mailbox */
  682. $read_mlbx = $read_ary[$i];
  683. $flags = substr($read_mlbx, strpos($read_mlbx, '(')+1);
  684. $flags = substr($flags, 0, strpos($flags, ')'));
  685. $flags = str_replace('\\', '', $flags);
  686. $flags = trim(strtolower($flags));
  687. if ($flags) {
  688. $boxes[$g]['flags'] = explode(' ', $flags);
  689. } else {
  690. $boxes[$g]['flags'] = array();
  691. }
  692. $g++;
  693. }
  694. if(is_array($boxes)) {
  695. sort ($boxes);
  696. }
  697. return $boxes;
  698. }
  699. function sqimap_mailbox_tree($imap_stream) {
  700. global $default_folder_prefix;
  701. if (true) {
  702. global $data_dir, $username, $list_special_folders_first,
  703. $folder_prefix, $delimiter, $trash_folder, $move_to_trash,
  704. $imap_server_type, $show_only_subscribed_folders;
  705. $noselect = false;
  706. $noinferiors = false;
  707. require_once(SM_PATH . 'include/load_prefs.php');
  708. if ($show_only_subscribed_folders) {
  709. $lsub_cmd = 'LSUB';
  710. } else {
  711. $lsub_cmd = 'LIST';
  712. }
  713. /* LSUB array */
  714. $lsub_ary = sqimap_run_command ($imap_stream, "$lsub_cmd \"$folder_prefix\" \"*\"",
  715. true, $response, $message);
  716. $lsub_ary = compact_mailboxes_response($lsub_ary);
  717. /* Check to see if we have an INBOX */
  718. $has_inbox = false;
  719. for ($i = 0, $cnt = count($lsub_ary); $i < $cnt; $i++) {
  720. if (preg_match("/^\*\s+$lsub_cmd.*\s\"?INBOX\"?[^(\/\.)].*$/i",$lsub_ary[$i])) {
  721. $lsub_ary[$i] = strtoupper($lsub_ary[$i]);
  722. // in case of an unsubscribed inbox an imap server can
  723. // return the inbox in the lsub results with a \NoSelect
  724. // flag.
  725. if (!preg_match("/\*\s+$lsub_cmd\s+\(.*\\\\NoSelect.*\).*/i",$lsub_ary[$i])) {
  726. $has_inbox = true;
  727. } else {
  728. // remove the result and request it again with a list
  729. // response at a later stage.
  730. unset($lsub_ary[$i]);
  731. // re-index the array otherwise the addition of the LIST
  732. // response will fail in PHP 4.1.2 and probably other older versions
  733. $lsub_ary = array_values($lsub_ary);
  734. }
  735. break;
  736. }
  737. }
  738. if ($has_inbox == false) {
  739. // do a list request for inbox because we should always show
  740. // inbox even if the user isn't subscribed to it.
  741. $inbox_ary = sqimap_run_command ($imap_stream, 'LIST "" "INBOX"',
  742. true, $response, $message);
  743. $inbox_ary = compact_mailboxes_response($inbox_ary);
  744. if (count($inbox_ary)) {
  745. $lsub_ary[] = $inbox_ary[0];
  746. }
  747. }
  748. /*
  749. * Section about removing the last element was removed
  750. * We don't return "* OK" anymore from sqimap_read_data
  751. */
  752. $sorted_lsub_ary = array();
  753. $cnt = count($lsub_ary);
  754. for ($i = 0; $i < $cnt; $i++) {
  755. $mbx = find_mailbox_name($lsub_ary[$i]);
  756. // only do the noselect test if !uw, is checked later. FIX ME see conf.pl setting
  757. if ($imap_server_type != "uw") {
  758. $noselect = check_is_noselect($lsub_ary[$i]);
  759. $noinferiors = check_is_noinferiors($lsub_ary[$i]);
  760. }
  761. if (substr($mbx, -1) == $delimiter) {
  762. $mbx = substr($mbx, 0, strlen($mbx) - 1);
  763. }
  764. $sorted_lsub_ary[] = array ('mbx' => $mbx, 'noselect' => $noselect, 'noinferiors' => $noinferiors);
  765. }
  766. // FIX ME this requires a config setting inside conf.pl instead of checking on server type
  767. if ($imap_server_type == "uw") {
  768. $aQuery = array();
  769. $aTag = array();
  770. // prepare an array with queries
  771. foreach ($sorted_lsub_ary as $aMbx) {
  772. $mbx = stripslashes($aMbx['mbx']);
  773. sqimap_prepare_pipelined_query('LIST "" ' . sqimap_encode_mailbox_name($mbx), $tag, $aQuery, false);
  774. $aTag[$tag] = $mbx;
  775. }
  776. $sorted_lsub_ary = array();
  777. // execute all the queries at once
  778. $aResponse = sqimap_run_pipelined_command ($imap_stream, $aQuery, false, $aServerResponse, $aServerMessage);
  779. foreach($aTag as $tag => $mbx) {
  780. if ($aServerResponse[$tag] == 'OK') {
  781. $sResponse = implode('', $aResponse[$tag]);
  782. $noselect = check_is_noselect($sResponse);
  783. $noinferiors = check_is_noinferiors($sResponse);
  784. $sorted_lsub_ary[] = array ('mbx' => $mbx, 'noselect' => $noselect, 'noinferiors' => $noinferiors);
  785. }
  786. }
  787. $cnt = count($sorted_lsub_ary);
  788. }
  789. $sorted_lsub_ary = array_values($sorted_lsub_ary);
  790. usort($sorted_lsub_ary, 'mbxSort');
  791. $boxestree = sqimap_fill_mailbox_tree($sorted_lsub_ary,false,$imap_stream);
  792. return $boxestree;
  793. }
  794. }
  795. function mbxSort($a, $b) {
  796. return strnatcasecmp($a['mbx'], $b['mbx']);
  797. }
  798. function sqimap_fill_mailbox_tree($mbx_ary, $mbxs=false,$imap_stream) {
  799. global $data_dir, $username, $list_special_folders_first,
  800. $folder_prefix, $trash_folder, $sent_folder, $draft_folder,
  801. $move_to_trash, $move_to_sent, $save_as_draft,
  802. $delimiter, $imap_server_type;
  803. // $special_folders = array ('INBOX', $sent_folder, $draft_folder, $trash_folder);
  804. /* create virtual root node */
  805. $mailboxes= new mailboxes();
  806. $mailboxes->is_root = true;
  807. $trail_del = false;
  808. $start = 0;
  809. if (isset($folder_prefix) && ($folder_prefix != '')) {
  810. $start = substr_count($folder_prefix,$delimiter);
  811. if (strrpos($folder_prefix, $delimiter) == (strlen($folder_prefix)-1)) {
  812. $mailboxes->mailboxname_full = substr($folder_prefix,0, (strlen($folder_prefix)-1));
  813. } else {
  814. $mailboxes->mailboxname_full = $folder_prefix;
  815. $start++;
  816. }
  817. $mailboxes->mailboxname_sub = $mailboxes->mailboxname_full;
  818. } else {
  819. $start = 0;
  820. }
  821. $cnt = count($mbx_ary);
  822. for ($i=0; $i < $cnt; $i++) {
  823. if ($mbx_ary[$i]['mbx'] !='' ) {
  824. $mbx = new mailboxes();
  825. $mailbox = $mbx_ary[$i]['mbx'];
  826. /*
  827. sent subfolders messes up using existing code as subfolders
  828. were marked, but the parents were ordered somewhere else in
  829. the list, despite having "special folders at top" option set.
  830. Need a better method than this.
  831. */
  832. /*
  833. if ($mailbox == 'INBOX') {
  834. $mbx->is_special = true;
  835. } elseif (stristr($trash_folder , $mailbox)) {
  836. $mbx->is_special = true;
  837. } elseif (stristr($sent_folder , $mailbox)) {
  838. $mbx->is_special = true;
  839. } elseif (stristr($draft_folder , $mailbox)) {
  840. $mbx->is_special = true;
  841. }
  842. switch ($mailbox) {
  843. case 'INBOX':
  844. $mbx->is_inbox = true;
  845. $mbx->is_special = true;
  846. $mbx_ary[$i]['noselect'] = false;
  847. break;
  848. case $trash_folder:
  849. $mbx->is_trash = true;
  850. $mbx->is_special = true;
  851. break;
  852. case $sent_folder:
  853. $mbx->is_sent = true;
  854. $mbx->is_special = true;
  855. break;
  856. case $draft_folder:
  857. $mbx->is_draft = true;
  858. $mbx->is_special = true;
  859. break;
  860. }
  861. */
  862. $mbx->is_special |= ($mbx->is_inbox = (strtoupper($mailbox) == 'INBOX'));
  863. $mbx->is_special |= ($mbx->is_trash = isTrashMailbox($mailbox));
  864. $mbx->is_special |= ($mbx->is_sent = isSentMailbox($mailbox));
  865. $mbx->is_special |= ($mbx->is_draft = isDraftMailbox($mailbox));
  866. if (!$mbx->is_special)
  867. $mbx->is_special = boolean_hook_function('special_mailbox', $mailbox, 1);
  868. if (isset($mbx_ary[$i]['unseen'])) {
  869. $mbx->unseen = $mbx_ary[$i]['unseen'];
  870. }
  871. if (isset($mbx_ary[$i]['nummessages'])) {
  872. $mbx->total = $mbx_ary[$i]['nummessages'];
  873. }
  874. $mbx->is_noselect = $mbx_ary[$i]['noselect'];
  875. $mbx->is_noinferiors = $mbx_ary[$i]['noinferiors'];
  876. $r_del_pos = strrpos($mbx_ary[$i]['mbx'], $delimiter);
  877. if ($r_del_pos) {
  878. $mbx->mailboxname_sub = substr($mbx_ary[$i]['mbx'],$r_del_pos+1);
  879. } else { /* mailbox is root folder */
  880. $mbx->mailboxname_sub = $mbx_ary[$i]['mbx'];
  881. }
  882. $mbx->mailboxname_full = $mbx_ary[$i]['mbx'];
  883. $mailboxes->addMbx($mbx, $delimiter, $start, $list_special_folders_first);
  884. }
  885. }
  886. sqimap_utf7_decode_mbx_tree($mailboxes);
  887. sqimap_get_status_mbx_tree($imap_stream,$mailboxes);
  888. return $mailboxes;
  889. }
  890. function sqimap_utf7_decode_mbx_tree(&$mbx_tree) {
  891. if (strtoupper($mbx_tree->mailboxname_full) == 'INBOX')
  892. $mbx_tree->mailboxname_sub = _("INBOX");
  893. else
  894. $mbx_tree->mailboxname_sub = imap_utf7_decode_local($mbx_tree->mailboxname_sub);
  895. if ($mbx_tree->mbxs) {
  896. $iCnt = count($mbx_tree->mbxs);
  897. for ($i=0;$i<$iCnt;++$i) {
  898. $mbxs_tree->mbxs[$i] = sqimap_utf7_decode_mbx_tree($mbx_tree->mbxs[$i]);
  899. }
  900. }
  901. }
  902. function sqimap_tree_to_ref_array(&$mbx_tree,&$aMbxs) {
  903. if ($mbx_tree)
  904. $aMbxs[] =& $mbx_tree;
  905. if ($mbx_tree->mbxs) {
  906. $iCnt = count($mbx_tree->mbxs);
  907. for ($i=0;$i<$iCnt;++$i) {
  908. sqimap_tree_to_ref_array($mbx_tree->mbxs[$i],$aMbxs);
  909. }
  910. }
  911. }
  912. function sqimap_get_status_mbx_tree($imap_stream,&$mbx_tree) {
  913. global $unseen_notify, $unseen_type, $trash_folder,$move_to_trash;
  914. $aMbxs = $aQuery = array();
  915. sqimap_tree_to_ref_array($mbx_tree,$aMbxs);
  916. // remove the root node
  917. array_shift($aMbxs);
  918. if($unseen_notify == 3) {
  919. $cnt = count($aMbxs);
  920. for($i=0;$i<$cnt;++$i) {
  921. $oMbx =& $aMbxs[$i];
  922. if (!$oMbx->is_noselect) {
  923. $mbx = $oMbx->mailboxname_full;
  924. if ($unseen_type == 2 ||
  925. ($move_to_trash && $oMbx->mailboxname_full == $trash_folder)) {
  926. $query = 'STATUS ' . sqimap_encode_mailbox_name($mbx) . ' (MESSAGES UNSEEN)';
  927. } else {
  928. $query = 'STATUS ' . sqimap_encode_mailbox_name($mbx) . ' (UNSEEN)';
  929. }
  930. sqimap_prepare_pipelined_query($query,$tag,$aQuery,false);
  931. } else {
  932. $oMbx->unseen = $oMbx->total = false;
  933. $tag = false;
  934. }
  935. $oMbx->tag = $tag;
  936. $aMbxs[$i] =& $oMbx;
  937. }
  938. // execute all the queries at once
  939. $aResponse = sqimap_run_pipelined_command ($imap_stream, $aQuery, false, $aServerResponse, $aServerMessage);
  940. $cnt = count($aMbxs);
  941. for($i=0;$i<$cnt;++$i) {
  942. $oMbx =& $aMbxs[$i];
  943. $tag = $oMbx->tag;
  944. if ($tag && $aServerResponse[$tag] == 'OK') {
  945. $sResponse = implode('', $aResponse[$tag]);
  946. if (preg_match('/UNSEEN\s+([0-9]+)/i', $sResponse, $regs)) {
  947. $oMbx->unseen = $regs[1];
  948. }
  949. if (preg_match('/MESSAGES\s+([0-9]+)/i', $sResponse, $regs)) {
  950. $oMbx->total = $regs[1];
  951. }
  952. }
  953. unset($oMbx->tag);
  954. }
  955. } else if ($unseen_notify == 2) { // INBOX only
  956. $cnt = count($aMbxs);
  957. for($i=0;$i<$cnt;++$i) {
  958. $oMbx =& $aMbxs[$i];
  959. if (strtoupper($oMbx->mailboxname_full) == 'INBOX' ||
  960. ($move_to_trash && $oMbx->mailboxname_full == $trash_folder)) {
  961. if ($unseen_type == 2 ||
  962. ($oMbx->mailboxname_full == $trash_folder && $move_to_trash)) {
  963. $aStatus = sqimap_status_messages($imap_stream,$oMbx->mailboxname_full);
  964. $oMbx->unseen = $aStatus['UNSEEN'];
  965. $oMbx->total = $aStatus['MESSAGES'];
  966. } else {
  967. $oMbx->unseen = sqimap_unseen_messages($imap_stream,$oMbx->mailboxname_full);
  968. }
  969. $aMbxs[$i] =& $oMbx;
  970. if (!$move_to_trash && $trash_folder) {
  971. break;
  972. } else {
  973. // trash comes after INBOX
  974. if ($oMbx->mailboxname_full == $trash_folder) {
  975. break;
  976. }
  977. }
  978. }
  979. }
  980. }
  981. }
  982. ?>