imap_mailbox.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101
  1. <?php
  2. /**
  3. * imap_mailbox.php
  4. *
  5. * Copyright (c) 1999-2004 The SquirrelMail Project Team
  6. * Licensed under the GNU GPL. For full terms see the file COPYING.
  7. *
  8. * This 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. if (substr($subbox,0,strlen($parentbox)) == $parentbox) {
  164. return true;
  165. } else {
  166. return false;
  167. }
  168. }
  169. /**
  170. * Defines special mailboxes: given a mailbox name, it checks if this is a
  171. * "special" one: INBOX, Trash, Sent or Draft.
  172. */
  173. function isSpecialMailbox( $box ) {
  174. $ret = ( (strtolower($box) == 'inbox') ||
  175. isTrashMailbox($box) || isSentMailbox($box) || isDraftMailbox($box) );
  176. if ( !$ret ) {
  177. $ret = boolean_hook_function('special_mailbox',$box,1);
  178. }
  179. return $ret;
  180. }
  181. /**
  182. * @return bool whether this is a Trash folder
  183. */
  184. function isTrashMailbox ($box) {
  185. global $trash_folder, $move_to_trash;
  186. return $move_to_trash && $trash_folder &&
  187. ( $box == $trash_folder || isBoxBelow($box, $trash_folder) );
  188. }
  189. /**
  190. * @return bool whether this is a Sent folder
  191. */
  192. function isSentMailbox($box) {
  193. global $sent_folder, $move_to_sent;
  194. return $move_to_sent && $sent_folder &&
  195. ( $box == $sent_folder || isBoxBelow($box, $sent_folder) );
  196. }
  197. /**
  198. * @return bool whether this is a Draft folder
  199. */
  200. function isDraftMailbox($box) {
  201. global $draft_folder, $save_as_draft;
  202. return $save_as_draft &&
  203. ( $box == $draft_folder || isBoxBelow($box, $draft_folder) );
  204. }
  205. /**
  206. * Expunges a mailbox, ie. delete all contents.
  207. */
  208. function sqimap_mailbox_expunge ($imap_stream, $mailbox, $handle_errors = true, $id='') {
  209. if ($id) {
  210. if (is_array($id)) {
  211. $id = sqimap_message_list_squisher($id);
  212. }
  213. $id = ' '.$id;
  214. $uid = TRUE;
  215. } else {
  216. $uid = false;
  217. }
  218. $read = sqimap_run_command($imap_stream, 'EXPUNGE'.$id, $handle_errors,
  219. $response, $message, $uid);
  220. $cnt = 0;
  221. if (is_array($read)) {
  222. foreach ($read as $r) {
  223. if (preg_match('/^\*\s[0-9]+\sEXPUNGE/AUi',$r,$regs)) {
  224. $cnt++;
  225. }
  226. }
  227. }
  228. return $cnt;
  229. }
  230. /**
  231. * Expunge specified message, updated $msgs and $msort
  232. *
  233. * Until Marc and I come up with a better way to maintain
  234. * these stupid arrays, we'll use this wrapper function to
  235. * remove the message with the matching UID .. the order
  236. * won't be changed - the array element for the message
  237. * will just be removed.
  238. */
  239. function sqimap_mailbox_expunge_dmn($message_id)
  240. {
  241. global $msgs, $msort, $sort, $imapConnection,
  242. $mailbox, $mbx_response, $auto_expunge,
  243. $sort, $allow_server_sort, $thread_sort_messages, $allow_thread_sort,
  244. $username, $data_dir;
  245. $cnt = 0;
  246. // Got to grab this out of prefs, since it isn't saved from mailbox_view.php
  247. if ($allow_thread_sort) {
  248. $thread_sort_messages = getPref($data_dir, $username, "thread_$mailbox",0);
  249. }
  250. for ($i = 0; $i < count($msort); $i++) {
  251. if ($msgs[$i]['ID'] == $message_id) {
  252. break;
  253. }
  254. }
  255. if ( isset($msgs) ) {
  256. unset($msgs[$i]);
  257. $msgs = array_values($msgs);
  258. sqsession_register($msgs, 'msgs');
  259. }
  260. if ( isset($msort) ) {
  261. unset($msort[$i]);
  262. $msort = array_values($msort);
  263. sqsession_register($msort, 'msort');
  264. }
  265. if ($auto_expunge) {
  266. $cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true);
  267. }
  268. // And after all that mucking around, update the sort list!
  269. // Remind me why the hell we need those two arrays again?!
  270. if ( $allow_thread_sort && $thread_sort_messages ) {
  271. $server_sort_array = get_thread_sort($imapConnection);
  272. } elseif ( $allow_server_sort ) {
  273. $server_sort_array = sqimap_get_sort_order($imapConnection, $sort, $mbx_response);
  274. } else {
  275. $server_sort_array = sqimap_get_php_sort_order($imapConnection, $mbx_response);
  276. }
  277. return $cnt;
  278. }
  279. /**
  280. * Checks whether or not the specified mailbox exists
  281. */
  282. function sqimap_mailbox_exists ($imap_stream, $mailbox) {
  283. if (!isset($mailbox) || empty($mailbox)) {
  284. return false;
  285. }
  286. $mbx = sqimap_run_command($imap_stream, 'LIST "" ' . sqimap_encode_mailbox_name($mailbox),
  287. true, $response, $message);
  288. return isset($mbx[0]);
  289. }
  290. /**
  291. * Selects a mailbox
  292. */
  293. function sqimap_mailbox_select ($imap_stream, $mailbox) {
  294. global $auto_expunge;
  295. if ($mailbox == 'None') {
  296. return;
  297. }
  298. $read = sqimap_run_command($imap_stream, 'SELECT ' . sqimap_encode_mailbox_name($mailbox),
  299. true, $response, $message);
  300. $result = array();
  301. for ($i = 0, $cnt = count($read); $i < $cnt; $i++) {
  302. if (preg_match('/^\*\s+OK\s\[(\w+)\s(\w+)\]/',$read[$i], $regs)) {
  303. $result[strtoupper($regs[1])] = $regs[2];
  304. } else if (preg_match('/^\*\s([0-9]+)\s(\w+)/',$read[$i], $regs)) {
  305. $result[strtoupper($regs[2])] = $regs[1];
  306. } else {
  307. if (preg_match("/PERMANENTFLAGS(.*)/i",$read[$i], $regs)) {
  308. $regs[1]=trim(preg_replace ( array ("/\(/","/\)/","/\]/") ,'', $regs[1])) ;
  309. $result['PERMANENTFLAGS'] = $regs[1];
  310. } else if (preg_match("/FLAGS(.*)/i",$read[$i], $regs)) {
  311. $regs[1]=trim(preg_replace ( array ("/\(/","/\)/") ,'', $regs[1])) ;
  312. $result['FLAGS'] = $regs[1];
  313. }
  314. }
  315. }
  316. if (preg_match('/^\[(.+)\]/',$message, $regs)) {
  317. $result['RIGHTS']=$regs[1];
  318. }
  319. if ($auto_expunge) {
  320. $tmp = sqimap_run_command($imap_stream, 'EXPUNGE', false, $a, $b);
  321. }
  322. return $result;
  323. }
  324. /**
  325. * Creates a folder.
  326. */
  327. function sqimap_mailbox_create ($imap_stream, $mailbox, $type) {
  328. global $delimiter;
  329. if (strtolower($type) == 'noselect') {
  330. $mailbox .= $delimiter;
  331. }
  332. $read_ary = sqimap_run_command($imap_stream, 'CREATE ' .
  333. sqimap_encode_mailbox_name($mailbox),
  334. true, $response, $message);
  335. sqimap_subscribe ($imap_stream, $mailbox);
  336. }
  337. /**
  338. * Subscribes to an existing folder.
  339. */
  340. function sqimap_subscribe ($imap_stream, $mailbox) {
  341. $read_ary = sqimap_run_command($imap_stream, 'SUBSCRIBE ' .
  342. sqimap_encode_mailbox_name($mailbox),
  343. true, $response, $message);
  344. }
  345. /**
  346. * Unsubscribes from an existing folder
  347. */
  348. function sqimap_unsubscribe ($imap_stream, $mailbox) {
  349. $read_ary = sqimap_run_command($imap_stream, 'UNSUBSCRIBE ' .
  350. sqimap_encode_mailbox_name($mailbox),
  351. false, $response, $message);
  352. }
  353. /**
  354. * Deletes the given folder
  355. */
  356. function sqimap_mailbox_delete ($imap_stream, $mailbox) {
  357. global $data_dir, $username;
  358. sqimap_unsubscribe ($imap_stream, $mailbox);
  359. $read_ary = sqimap_run_command($imap_stream, 'DELETE ' .
  360. sqimap_encode_mailbox_name($mailbox),
  361. true, $response, $message);
  362. if ($response !== 'OK') {
  363. // subscribe again
  364. sqimap_subscribe ($imap_stream, $mailbox);
  365. } else {
  366. do_hook_function('rename_or_delete_folder', $args = array($mailbox, 'delete', ''));
  367. removePref($data_dir, $username, "thread_$mailbox");
  368. }
  369. }
  370. /**
  371. * Determines if the user is subscribed to the folder or not
  372. */
  373. function sqimap_mailbox_is_subscribed($imap_stream, $folder) {
  374. $boxesall = sqimap_mailbox_list ($imap_stream);
  375. foreach ($boxesall as $ref) {
  376. if ($ref['unformatted'] == $folder) {
  377. return true;
  378. }
  379. }
  380. return false;
  381. }
  382. /**
  383. * Renames a mailbox.
  384. */
  385. function sqimap_mailbox_rename( $imap_stream, $old_name, $new_name ) {
  386. if ( $old_name != $new_name ) {
  387. global $delimiter, $imap_server_type, $data_dir, $username;
  388. if ( substr( $old_name, -1 ) == $delimiter ) {
  389. $old_name = substr( $old_name, 0, strlen( $old_name ) - 1 );
  390. $new_name = substr( $new_name, 0, strlen( $new_name ) - 1 );
  391. $postfix = $delimiter;
  392. } else {
  393. $postfix = '';
  394. }
  395. $boxesall = sqimap_mailbox_list($imap_stream);
  396. $cmd = 'RENAME ' . sqimap_encode_mailbox_name($old_name) .
  397. ' ' . sqimap_encode_mailbox_name($new_name);
  398. $data = sqimap_run_command($imap_stream, $cmd, true, $response, $message);
  399. sqimap_unsubscribe($imap_stream, $old_name.$postfix);
  400. $oldpref = getPref($data_dir, $username, 'thread_'.$old_name.$postfix);
  401. removePref($data_dir, $username, 'thread_'.$old_name.$postfix);
  402. sqimap_subscribe($imap_stream, $new_name.$postfix);
  403. setPref($data_dir, $username, 'thread_'.$new_name.$postfix, $oldpref);
  404. do_hook_function('rename_or_delete_folder',$args = array($old_name, 'rename', $new_name));
  405. $l = strlen( $old_name ) + 1;
  406. $p = 'unformatted';
  407. foreach ($boxesall as $box) {
  408. if (substr($box[$p], 0, $l) == $old_name . $delimiter) {
  409. $new_sub = $new_name . $delimiter . substr($box[$p], $l);
  410. if ($imap_server_type == 'cyrus') {
  411. $cmd = 'RENAME "' . $box[$p] . '" "' . $new_sub . '"';
  412. $data = sqimap_run_command($imap_stream, $cmd, true,
  413. $response, $message);
  414. }
  415. sqimap_unsubscribe($imap_stream, $box[$p]);
  416. $oldpref = getPref($data_dir, $username, 'thread_'.$box[$p]);
  417. removePref($data_dir, $username, 'thread_'.$box[$p]);
  418. sqimap_subscribe($imap_stream, $new_sub);
  419. setPref($data_dir, $username, 'thread_'.$new_sub, $oldpref);
  420. do_hook_function('rename_or_delete_folder',
  421. $args = array($box[$p], 'rename', $new_sub));
  422. }
  423. }
  424. }
  425. }
  426. /**
  427. * Formats a mailbox into parts for the $boxesall array
  428. *
  429. * The parts are:
  430. *
  431. * raw - Raw LIST/LSUB response from the IMAP server
  432. * formatted - nicely formatted folder name
  433. * unformatted - unformatted, but with delimiter at end removed
  434. * unformatted-dm - folder name as it appears in raw response
  435. * unformatted-disp - unformatted without $folder_prefix
  436. */
  437. function sqimap_mailbox_parse ($line, $line_lsub) {
  438. global $folder_prefix, $delimiter;
  439. /* Process each folder line */
  440. for ($g = 0, $cnt = count($line); $g < $cnt; ++$g) {
  441. /* Store the raw IMAP reply */
  442. if (isset($line[$g])) {
  443. $boxesall[$g]['raw'] = $line[$g];
  444. } else {
  445. $boxesall[$g]['raw'] = '';
  446. }
  447. /* Count number of delimiters ($delimiter) in folder name */
  448. $mailbox = /*trim(*/$line_lsub[$g]/*)*/;
  449. $dm_count = substr_count($mailbox, $delimiter);
  450. if (substr($mailbox, -1) == $delimiter) {
  451. /* If name ends in delimiter, decrement count by one */
  452. $dm_count--;
  453. }
  454. /* Format folder name, but only if it's a INBOX.* or has a parent. */
  455. $boxesallbyname[$mailbox] = $g;
  456. $parentfolder = readMailboxParent($mailbox, $delimiter);
  457. if ( (strtolower(substr($mailbox, 0, 5)) == "inbox") ||
  458. (substr($mailbox, 0, strlen($folder_prefix)) == $folder_prefix) ||
  459. (isset($boxesallbyname[$parentfolder]) &&
  460. (strlen($parentfolder) > 0) ) ) {
  461. $indent = $dm_count - (substr_count($folder_prefix, $delimiter));
  462. if ($indent > 0) {
  463. $boxesall[$g]['formatted'] = str_repeat('&nbsp;&nbsp;', $indent);
  464. } else {
  465. $boxesall[$g]['formatted'] = '';
  466. }
  467. $boxesall[$g]['formatted'] .= imap_utf7_decode_local(readShortMailboxName($mailbox, $delimiter));
  468. } else {
  469. $boxesall[$g]['formatted'] = imap_utf7_decode_local($mailbox);
  470. }
  471. $boxesall[$g]['unformatted-dm'] = $mailbox;
  472. if (substr($mailbox, -1) == $delimiter) {
  473. $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
  474. }
  475. $boxesall[$g]['unformatted'] = $mailbox;
  476. if (substr($mailbox,0,strlen($folder_prefix))==$folder_prefix) {
  477. $mailbox = substr($mailbox, strlen($folder_prefix));
  478. }
  479. $boxesall[$g]['unformatted-disp'] = $mailbox;
  480. $boxesall[$g]['id'] = $g;
  481. $boxesall[$g]['flags'] = array();
  482. if (isset($line[$g])) {
  483. ereg("\(([^)]*)\)",$line[$g],$regs);
  484. // FIXME Flags do contain the \ character. \NoSelect \NoInferiors
  485. // and $MDNSent <= last one doesn't have the \
  486. // It's better to follow RFC3501 instead of using our own naming.
  487. $flags = trim(strtolower(str_replace('\\', '',$regs[1])));
  488. if ($flags) {
  489. $boxesall[$g]['flags'] = explode(' ', $flags);
  490. }
  491. }
  492. }
  493. return $boxesall;
  494. }
  495. /**
  496. * Returns list of options (to be echoed into select statement
  497. * based on available mailboxes and separators
  498. * Caller should surround options with <SELECT..> </SELECT> and
  499. * any formatting.
  500. * $imap_stream - $imapConnection to query for mailboxes
  501. * $show_selected - array containing list of mailboxes to pre-select (0 if none)
  502. * $folder_skip - array of folders to keep out of option list (compared in lower)
  503. * $boxes - list of already fetched boxes (for places like folder panel, where
  504. * you know these options will be shown 3 times in a row.. (most often unset).
  505. * $flag - flag to check for in mailbox flags, used to filter out mailboxes.
  506. * 'noselect' by default to remove unselectable mailboxes.
  507. * 'noinferiors' used to filter out folders that can not contain subfolders.
  508. * NULL to avoid flag check entirely.
  509. * NOTE: noselect and noiferiors are used internally. The IMAP representation is
  510. * \NoSelect and \NoInferiors
  511. * $use_long_format - override folder display preference and always show full folder name.
  512. */
  513. function sqimap_mailbox_option_list($imap_stream, $show_selected = 0, $folder_skip = 0, $boxes = 0,
  514. $flag = 'noselect', $use_long_format = false ) {
  515. global $username, $data_dir;
  516. $mbox_options = '';
  517. if ( $use_long_format ) {
  518. $shorten_box_names = 0;
  519. } else {
  520. $shorten_box_names = getPref($data_dir, $username, 'mailbox_select_style', SMPREF_OFF);
  521. }
  522. if ($boxes == 0) {
  523. $boxes = sqimap_mailbox_list($imap_stream);
  524. }
  525. foreach ($boxes as $boxes_part) {
  526. if ($flag == NULL || !in_array($flag, $boxes_part['flags'])) {
  527. $box = $boxes_part['unformatted'];
  528. if ($folder_skip != 0 && in_array($box, $folder_skip) ) {
  529. continue;
  530. }
  531. $lowerbox = strtolower($box);
  532. // mailboxes are casesensitive => inbox.sent != inbox.Sent
  533. // nevermind, to many dependencies this should be fixed!
  534. if (strtolower($box) == 'inbox') { // inbox is special and not casesensitive
  535. $box2 = _("INBOX");
  536. } else {
  537. switch ($shorten_box_names)
  538. {
  539. case 2: /* delimited, style = 2 */
  540. $box2 = str_replace('&nbsp;&nbsp;', '.&nbsp;', $boxes_part['formatted']);
  541. break;
  542. case 1: /* indent, style = 1 */
  543. $box2 = $boxes_part['formatted'];
  544. break;
  545. default: /* default, long names, style = 0 */
  546. $box2 = str_replace(' ', '&nbsp;', htmlspecialchars(imap_utf7_decode_local($boxes_part['unformatted-disp'])));
  547. break;
  548. }
  549. }
  550. if ($show_selected != 0 && in_array($lowerbox, $show_selected) ) {
  551. $mbox_options .= '<OPTION VALUE="' . htmlspecialchars($box) .'" SELECTED>'.$box2.'</OPTION>' . "\n";
  552. } else {
  553. $mbox_options .= '<OPTION VALUE="' . htmlspecialchars($box) .'">'.$box2.'</OPTION>' . "\n";
  554. }
  555. }
  556. }
  557. return $mbox_options;
  558. }
  559. /**
  560. * Returns sorted mailbox lists in several different ways.
  561. * See comment on sqimap_mailbox_parse() for info about the returned array.
  562. */
  563. function sqimap_mailbox_list($imap_stream) {
  564. global $default_folder_prefix;
  565. if (!isset($boxesnew)) {
  566. global $data_dir, $username, $list_special_folders_first,
  567. $folder_prefix, $trash_folder, $sent_folder, $draft_folder,
  568. $move_to_trash, $move_to_sent, $save_as_draft,
  569. $delimiter, $noselect_fix_enable;
  570. $inbox_in_list = false;
  571. $inbox_subscribed = false;
  572. require_once(SM_PATH . 'include/load_prefs.php');
  573. if ($noselect_fix_enable) {
  574. $lsub_args = "LSUB \"$folder_prefix\" \"*%\"";
  575. } else {
  576. $lsub_args = "LSUB \"$folder_prefix\" \"*\"";
  577. }
  578. /* LSUB array */
  579. $lsub_ary = sqimap_run_command ($imap_stream, $lsub_args,
  580. true, $response, $message);
  581. $lsub_ary = compact_mailboxes_response($lsub_ary);
  582. $sorted_lsub_ary = array();
  583. for ($i = 0, $cnt = count($lsub_ary);$i < $cnt; $i++) {
  584. $temp_mailbox_name = find_mailbox_name($lsub_ary[$i]);
  585. $sorted_lsub_ary[] = $temp_mailbox_name;
  586. if (!$inbox_subscribed && strtoupper($temp_mailbox_name) == 'INBOX') {
  587. $inbox_subscribed = true;
  588. }
  589. }
  590. /* natural sort mailboxes */
  591. if (isset($sorted_lsub_ary)) {
  592. usort($sorted_lsub_ary, 'strnatcasecmp');
  593. }
  594. /*
  595. * The LSUB response doesn't provide us information about \Noselect
  596. * mail boxes. The LIST response does, that's why we need to do a LIST
  597. * call to retrieve the flags for the mailbox
  598. * Note: according RFC2060 an imap server may provide \NoSelect flags in the LSUB response.
  599. * in other words, we cannot rely on it.
  600. */
  601. $sorted_list_ary = array();
  602. for ($i=0; $i < count($sorted_lsub_ary); $i++) {
  603. if (substr($sorted_lsub_ary[$i], -1) == $delimiter) {
  604. $mbx = substr($sorted_lsub_ary[$i], 0, strlen($sorted_lsub_ary[$i])-1);
  605. }
  606. else {
  607. $mbx = $sorted_lsub_ary[$i];
  608. }
  609. $mbx = stripslashes($mbx);
  610. $read = sqimap_run_command ($imap_stream, 'LIST "" ' . sqimap_encode_mailbox_name($mbx),
  611. true, $response, $message);
  612. $read = compact_mailboxes_response($read);
  613. if (isset($read[0])) {
  614. $sorted_list_ary[$i] = $read[0];
  615. } else {
  616. $sorted_list_ary[$i] = '';
  617. }
  618. }
  619. /*
  620. * Just in case they're not subscribed to their inbox,
  621. * we'll get it for them anyway
  622. */
  623. if (!$inbox_subscribed) {
  624. $inbox_ary = sqimap_run_command ($imap_stream, 'LIST "" INBOX',
  625. true, $response, $message);
  626. $sorted_list_ary[] = implode('', compact_mailboxes_response($inbox_ary));
  627. $sorted_lsub_ary[] = find_mailbox_name($inbox_ary[0]);
  628. }
  629. $boxesall = sqimap_mailbox_parse ($sorted_list_ary, $sorted_lsub_ary);
  630. /* Now, lets sort for special folders */
  631. $boxesnew = $used = array();
  632. /* Find INBOX */
  633. $cnt = count($boxesall);
  634. $used = array_pad($used,$cnt,false);
  635. for($k = 0; $k < $cnt; ++$k) {
  636. if (strtolower($boxesall[$k]['unformatted']) == 'inbox') {
  637. $boxesnew[] = $boxesall[$k];
  638. $used[$k] = true;
  639. break;
  640. }
  641. }
  642. /* List special folders and their subfolders, if requested. */
  643. if ($list_special_folders_first) {
  644. for($k = 0; $k < $cnt; ++$k) {
  645. if (!$used[$k] && isSpecialMailbox($boxesall[$k]['unformatted'])) {
  646. $boxesnew[] = $boxesall[$k];
  647. $used[$k] = true;
  648. }
  649. }
  650. }
  651. /* Rest of the folders */
  652. for($k = 0; $k < $cnt; $k++) {
  653. if (!$used[$k]) {
  654. $boxesnew[] = $boxesall[$k];
  655. }
  656. }
  657. }
  658. return $boxesnew;
  659. }
  660. /**
  661. * Returns a list of all folders, subscribed or not
  662. */
  663. function sqimap_mailbox_list_all($imap_stream) {
  664. global $list_special_folders_first, $folder_prefix, $delimiter;
  665. $read_ary = sqimap_run_command($imap_stream,"LIST \"$folder_prefix\" *",true,$response, $message,false);
  666. $read_ary = compact_mailboxes_response($read_ary);
  667. $g = 0;
  668. $phase = 'inbox';
  669. $fld_pre_length = strlen($folder_prefix);
  670. for ($i = 0, $cnt = count($read_ary); $i < $cnt; $i++) {
  671. /* Store the raw IMAP reply */
  672. $boxes[$g]['raw'] = $read_ary[$i];
  673. /* Count number of delimiters ($delimiter) in folder name */
  674. $mailbox = find_mailbox_name($read_ary[$i]);
  675. $dm_count = substr_count($mailbox, $delimiter);
  676. if (substr($mailbox, -1) == $delimiter) {
  677. /* If name ends in delimiter - decrement count by one */
  678. $dm_count--;
  679. }
  680. /* Format folder name, but only if it's a INBOX.* or has a parent. */
  681. $boxesallbyname[$mailbox] = $g;
  682. $parentfolder = readMailboxParent($mailbox, $delimiter);
  683. if((eregi('^inbox'.quotemeta($delimiter), $mailbox)) ||
  684. (ereg('^'.$folder_prefix, $mailbox)) ||
  685. ( isset($boxesallbyname[$parentfolder]) && (strlen($parentfolder) > 0) ) ) {
  686. if ($dm_count) {
  687. $boxes[$g]['formatted'] = str_repeat('&nbsp;&nbsp;', $dm_count);
  688. } else {
  689. $boxes[$g]['formatted'] = '';
  690. }
  691. $boxes[$g]['formatted'] .= imap_utf7_decode_local(readShortMailboxName($mailbox, $delimiter));
  692. } else {
  693. $boxes[$g]['formatted'] = imap_utf7_decode_local($mailbox);
  694. }
  695. $boxes[$g]['unformatted-dm'] = $mailbox;
  696. if (substr($mailbox, -1) == $delimiter) {
  697. $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
  698. }
  699. $boxes[$g]['unformatted'] = $mailbox;
  700. $boxes[$g]['unformatted-disp'] = substr($mailbox,$fld_pre_length);
  701. $boxes[$g]['id'] = $g;
  702. /* Now lets get the flags for this mailbox */
  703. $read_mlbx = $read_ary[$i];
  704. $flags = substr($read_mlbx, strpos($read_mlbx, '(')+1);
  705. $flags = substr($flags, 0, strpos($flags, ')'));
  706. $flags = str_replace('\\', '', $flags);
  707. $flags = trim(strtolower($flags));
  708. if ($flags) {
  709. $boxes[$g]['flags'] = explode(' ', $flags);
  710. } else {
  711. $boxes[$g]['flags'] = array();
  712. }
  713. $g++;
  714. }
  715. if(is_array($boxes)) {
  716. sort ($boxes);
  717. }
  718. return $boxes;
  719. }
  720. function sqimap_mailbox_tree($imap_stream) {
  721. global $boxesnew, $default_folder_prefix, $unseen_notify, $unseen_type;
  722. if (!isset($boxesnew)) {
  723. global $data_dir, $username, $list_special_folders_first,
  724. $folder_prefix, $delimiter, $trash_folder, $move_to_trash,
  725. $imap_server_type;
  726. $inbox_in_list = false;
  727. $inbox_subscribed = false;
  728. $noselect = false;
  729. $noinferiors = false;
  730. require_once(SM_PATH . 'include/load_prefs.php');
  731. /* LSUB array */
  732. $lsub_ary = sqimap_run_command ($imap_stream, "LSUB \"$folder_prefix\" \"*\"",
  733. true, $response, $message);
  734. $lsub_ary = compact_mailboxes_response($lsub_ary);
  735. /* Check to see if we have an INBOX */
  736. $has_inbox = false;
  737. for ($i = 0, $cnt = count($lsub_ary); $i < $cnt; $i++) {
  738. if (preg_match("/^\*\s+LSUB.*\s\"?INBOX\"?[^(\/\.)].*$/i",$lsub_ary[$i])) {
  739. $lsub_ary[$i] = strtoupper($lsub_ary[$i]);
  740. // in case of an unsubscribed inbox an imap server can
  741. // return the inbox in the lsub results with a \NoSelect
  742. // flag.
  743. if (!preg_match("/\*\s+LSUB\s+\(.*\\\\NoSelect.*\).*/i",$lsub_ary[$i])) {
  744. $has_inbox = true;
  745. } else {
  746. // remove the result and request it again with a list
  747. // response at a later stage.
  748. unset($lsub_ary[$i]);
  749. // re-index the array otherwise the addition of the LIST
  750. // response will fail in PHP 4.1.2 and probably other older versions
  751. $lsub_ary = array_values($lsub_ary);
  752. }
  753. break;
  754. }
  755. }
  756. if ($has_inbox == false) {
  757. // do a list request for inbox because we should always show
  758. // inbox even if the user isn't subscribed to it.
  759. $inbox_ary = sqimap_run_command ($imap_stream, 'LIST "" INBOX',
  760. true, $response, $message);
  761. $inbox_ary = compact_mailboxes_response($inbox_ary);
  762. if (count($inbox_ary)) {
  763. $lsub_ary[] = $inbox_ary[0];
  764. }
  765. }
  766. /*
  767. * Section about removing the last element was removed
  768. * We don't return "* OK" anymore from sqimap_read_data
  769. */
  770. $sorted_lsub_ary = array();
  771. $cnt = count($lsub_ary);
  772. for ($i = 0; $i < $cnt; $i++) {
  773. $mbx = find_mailbox_name($lsub_ary[$i]);
  774. // only do the noselect test if !uw, is checked later. FIX ME see conf.pl setting
  775. if ($imap_server_type != "uw") {
  776. $noselect = check_is_noselect($lsub_ary[$i]);
  777. $noinferiors = check_is_noinferiors($lsub_ary[$i]);
  778. }
  779. if (substr($mbx, -1) == $delimiter) {
  780. $mbx = substr($mbx, 0, strlen($mbx) - 1);
  781. }
  782. $sorted_lsub_ary[] = array ('mbx' => $mbx, 'noselect' => $noselect, 'noinferiors' => $noinferiors);
  783. }
  784. // FIX ME this requires a config setting inside conf.pl instead of checking on server type
  785. if ($imap_server_type == "uw") {
  786. $aQuery = array();
  787. $aTag = array();
  788. // prepare an array with queries
  789. foreach ($sorted_lsub_ary as $aMbx) {
  790. $mbx = stripslashes($aMbx['mbx']);
  791. sqimap_prepare_pipelined_query('LIST "" ' . sqimap_encode_mailbox_name($mbx), $tag, $aQuery, false);
  792. $aTag[$tag] = $mbx;
  793. }
  794. $sorted_lsub_ary = array();
  795. // execute all the queries at once
  796. $aResponse = sqimap_run_pipelined_command ($imap_stream, $aQuery, false, $aServerResponse, $aServerMessage);
  797. foreach($aTag as $tag => $mbx) {
  798. if ($aServerResponse[$tag] == 'OK') {
  799. $sResponse = implode('', $aResponse[$tag]);
  800. $noselect = check_is_noselect($sResponse);
  801. $noinferiors = check_is_noinferiors($sResponse);
  802. $sorted_lsub_ary[] = array ('mbx' => $mbx, 'noselect' => $noselect, 'noinferiors' => $noinferiors);
  803. }
  804. }
  805. $cnt = count($sorted_lsub_ary);
  806. }
  807. $sorted_lsub_ary = array_values($sorted_lsub_ary);
  808. array_multisort($sorted_lsub_ary, SORT_ASC, SORT_REGULAR);
  809. $boxesnew = sqimap_fill_mailbox_tree($sorted_lsub_ary,false,$imap_stream);
  810. return $boxesnew;
  811. }
  812. }
  813. function sqimap_fill_mailbox_tree($mbx_ary, $mbxs=false,$imap_stream) {
  814. global $data_dir, $username, $list_special_folders_first,
  815. $folder_prefix, $trash_folder, $sent_folder, $draft_folder,
  816. $move_to_trash, $move_to_sent, $save_as_draft,
  817. $delimiter, $imap_server_type;
  818. $special_folders = array ('INBOX', $sent_folder, $draft_folder, $trash_folder);
  819. /* create virtual root node */
  820. $mailboxes= new mailboxes();
  821. $mailboxes->is_root = true;
  822. $trail_del = false;
  823. $start = 0;
  824. if (isset($folder_prefix) && ($folder_prefix != '')) {
  825. $start = substr_count($folder_prefix,$delimiter);
  826. if (strrpos($folder_prefix, $delimiter) == (strlen($folder_prefix)-1)) {
  827. $trail_del = true;
  828. $mailboxes->mailboxname_full = substr($folder_prefix,0, (strlen($folder_prefix)-1));
  829. } else {
  830. $mailboxes->mailboxname_full = $folder_prefix;
  831. $start++;
  832. }
  833. $mailboxes->mailboxname_sub = $mailboxes->mailboxname_full;
  834. } else {
  835. $start = 0;
  836. }
  837. $cnt = count($mbx_ary);
  838. for ($i=0; $i < $cnt; $i++) {
  839. if ($mbx_ary[$i]['mbx'] !='' ) {
  840. $mbx = new mailboxes();
  841. $mailbox = $mbx_ary[$i]['mbx'];
  842. /*
  843. sent subfolders messes up using existing code as subfolders
  844. were marked, but the parents were ordered somewhere else in
  845. the list, despite having "special folders at top" option set.
  846. Need a better method than this.
  847. */
  848. /*
  849. if ($mailbox == 'INBOX') {
  850. $mbx->is_special = true;
  851. } elseif (stristr($trash_folder , $mailbox)) {
  852. $mbx->is_special = true;
  853. } elseif (stristr($sent_folder , $mailbox)) {
  854. $mbx->is_special = true;
  855. } elseif (stristr($draft_folder , $mailbox)) {
  856. $mbx->is_special = true;
  857. }
  858. switch ($mailbox) {
  859. case 'INBOX':
  860. $mbx->is_inbox = true;
  861. $mbx->is_special = true;
  862. $mbx_ary[$i]['noselect'] = false;
  863. break;
  864. case $trash_folder:
  865. $mbx->is_trash = true;
  866. $mbx->is_special = true;
  867. break;
  868. case $sent_folder:
  869. $mbx->is_sent = true;
  870. $mbx->is_special = true;
  871. break;
  872. case $draft_folder:
  873. $mbx->is_draft = true;
  874. $mbx->is_special = true;
  875. break;
  876. }
  877. */
  878. $mbx->is_special |= ($mbx->is_inbox = (strtoupper($mailbox) == 'INBOX'));
  879. $mbx->is_special |= ($mbx->is_trash = isTrashMailbox($mailbox));
  880. $mbx->is_special |= ($mbx->is_sent = isSentMailbox($mailbox));
  881. $mbx->is_special |= ($mbx->is_draft = isDraftMailbox($mailbox));
  882. if (!$mbx->is_special)
  883. $mbx->is_special = boolean_hook_function('special_mailbox', $mailbox, 1);
  884. if (isset($mbx_ary[$i]['unseen'])) {
  885. $mbx->unseen = $mbx_ary[$i]['unseen'];
  886. }
  887. if (isset($mbx_ary[$i]['nummessages'])) {
  888. $mbx->total = $mbx_ary[$i]['nummessages'];
  889. }
  890. $mbx->is_noselect = $mbx_ary[$i]['noselect'];
  891. $mbx->is_noinferiors = $mbx_ary[$i]['noinferiors'];
  892. $r_del_pos = strrpos($mbx_ary[$i]['mbx'], $delimiter);
  893. if ($r_del_pos) {
  894. $mbx->mailboxname_sub = substr($mbx_ary[$i]['mbx'],$r_del_pos+1);
  895. } else { /* mailbox is root folder */
  896. $mbx->mailboxname_sub = $mbx_ary[$i]['mbx'];
  897. }
  898. $mbx->mailboxname_full = $mbx_ary[$i]['mbx'];
  899. $mailboxes->addMbx($mbx, $delimiter, $start, $list_special_folders_first);
  900. }
  901. }
  902. sqimap_utf7_decode_mbx_tree($mailboxes);
  903. sqimap_get_status_mbx_tree($imap_stream,$mailboxes);
  904. return $mailboxes;
  905. }
  906. function sqimap_utf7_decode_mbx_tree(&$mbx_tree) {
  907. if (strtoupper($mbx_tree->mailboxname_full) == 'INBOX')
  908. $mbx_tree->mailboxname_sub = _("INBOX");
  909. else
  910. $mbx_tree->mailboxname_sub = imap_utf7_decode_local($mbx_tree->mailboxname_sub);
  911. if ($mbx_tree->mbxs) {
  912. $iCnt = count($mbx_tree->mbxs);
  913. for ($i=0;$i<$iCnt;++$i) {
  914. $mbxs_tree->mbxs[$i] = sqimap_utf7_decode_mbx_tree($mbx_tree->mbxs[$i]);
  915. }
  916. }
  917. }
  918. function sqimap_tree_to_ref_array(&$mbx_tree,&$aMbxs) {
  919. if ($mbx_tree)
  920. $aMbxs[] =& $mbx_tree;
  921. if ($mbx_tree->mbxs) {
  922. $iCnt = count($mbx_tree->mbxs);
  923. for ($i=0;$i<$iCnt;++$i) {
  924. sqimap_tree_to_ref_array($mbx_tree->mbxs[$i],$aMbxs);
  925. }
  926. }
  927. }
  928. function sqimap_get_status_mbx_tree($imap_stream,&$mbx_tree) {
  929. global $unseen_notify, $unseen_type, $trash_folder,$move_to_trash;
  930. $aMbxs = $aQuery = $aTag = array();
  931. sqimap_tree_to_ref_array($mbx_tree,$aMbxs);
  932. // remove the root node
  933. array_shift($aMbxs);
  934. if($unseen_notify == 3) {
  935. $cnt = count($aMbxs);
  936. for($i=0;$i<$cnt;++$i) {
  937. $oMbx =& $aMbxs[$i];
  938. if (!$oMbx->is_noselect) {
  939. $mbx = $oMbx->mailboxname_full;
  940. if ($unseen_type == 2 ||
  941. ($move_to_trash && $oMbx->mailboxname_full == $trash_folder)) {
  942. $query = 'STATUS ' . sqimap_encode_mailbox_name($mbx) . ' (MESSAGES UNSEEN)';
  943. } else {
  944. $query = 'STATUS ' . sqimap_encode_mailbox_name($mbx) . ' (UNSEEN)';
  945. }
  946. sqimap_prepare_pipelined_query($query,$tag,$aQuery,false);
  947. } else {
  948. $oMbx->unseen = $oMbx->total = false;
  949. $tag = false;
  950. }
  951. $oMbx->tag = $tag;
  952. $aMbxs[$i] =& $oMbx;
  953. }
  954. // execute all the queries at once
  955. $aResponse = sqimap_run_pipelined_command ($imap_stream, $aQuery, false, $aServerResponse, $aServerMessage);
  956. $cnt = count($aMbxs);
  957. for($i=0;$i<$cnt;++$i) {
  958. $oMbx =& $aMbxs[$i];
  959. $tag = $oMbx->tag;
  960. if ($tag && $aServerResponse[$tag] == 'OK') {
  961. $sResponse = implode('', $aResponse[$tag]);
  962. if (preg_match('/UNSEEN\s+([0-9]+)/i', $sResponse, $regs)) {
  963. $oMbx->unseen = $regs[1];
  964. }
  965. if (preg_match('/MESSAGES\s+([0-9]+)/i', $sResponse, $regs)) {
  966. $oMbx->total = $regs[1];
  967. }
  968. }
  969. unset($oMbx->tag);
  970. }
  971. } else if ($unseen_notify == 2) { // INBOX only
  972. $cnt = count($aMbxs);
  973. for($i=0;$i<$cnt;++$i) {
  974. $oMbx =& $aMbxs[$i];
  975. if (strtoupper($oMbx->mailboxname_full) == 'INBOX' ||
  976. ($move_to_trash && $oMbx->mailboxname_full == $trash_folder)) {
  977. if ($unseen_type == 2 ||
  978. ($oMbx->mailboxname_full == $trash_folder && $move_to_trash)) {
  979. $aStatus = sqimap_status_messages($imap_stream,$oMbx->mailboxname_full);
  980. $oMbx->unseen = $aStatus['UNSEEN'];
  981. $oMbx->total = $aStatus['MESSAGES'];
  982. } else {
  983. $oMbx->unseen = sqimap_unseen_messages($imap_stream,$oMbx->mailboxname_full);
  984. }
  985. $aMbxs[$i] =& $oMbx;
  986. if (!$move_to_trash && $trash_folder) {
  987. break;
  988. } else {
  989. // trash comes after INBOX
  990. if ($oMbx->mailboxname_full == $trash_folder) {
  991. break;
  992. }
  993. }
  994. }
  995. }
  996. }
  997. }
  998. ?>