+
+ /***********************************************************************
+ ** Determines if the user is subscribed to the folder or not
+ **********************************************************************/
+ function sqimap_mailbox_is_subscribed($imap_stream, $folder) {
+ $boxes = sqimap_mailbox_list ($imap_stream);
+ foreach ($boxes as $ref) {
+ if ($ref['unformatted'] == $folder)
+ return true;
+ }
+ return false;
+ }
+
+
+
+ /******************************************************************************
+ ** Formats a mailbox into 4 parts for the $boxes array
+ **
+ ** The four parts are:
+ **
+ ** raw - Raw LIST/LSUB response from the IMAP server
+ ** formatted - nicely formatted folder name
+ ** unformatted - unformatted, but with delimiter at end removed
+ ** unformatted-dm - folder name as it appears in raw response
+ ** unformatted-disp - unformatted without $folder_prefix
+ **
+ ******************************************************************************/
+ function sqimap_mailbox_parse ($line, $line_lsub, $dm) {
+ global $folder_prefix;
+
+ // Process each folder line
+ for ($g=0; $g < count($line); $g++) {
+
+ // Store the raw IMAP reply
+ if (isset($line[$g]))
+ $boxes[$g]["raw"] = $line[$g];
+ else
+ $boxes[$g]["raw"] = "";
+
+
+ // Count number of delimiters ($dm) in folder name
+ $mailbox = trim($line_lsub[$g]);
+ $dm_count = countCharInString($mailbox, $dm);
+ if (substr($mailbox, -1) == $dm)
+ $dm_count--; // If name ends in delimiter - decrement count by one
+
+ // Format folder name, but only if it's a INBOX.* or have
+ // a parent.
+ $boxesbyname[$mailbox] = $g;
+ $parentfolder = readMailboxParent($mailbox, $dm);
+ if((strtolower(substr($mailbox, 0, 5)) == "inbox") ||
+ (substr($mailbox, 0, strlen($folder_prefix)) == $folder_prefix) ||
+ (isset($boxesbyname[$parentfolder]) && (strlen($parentfolder) > 0) ) ) {
+ $indent = $dm_count - (countCharInString($folder_prefix, $dm));
+ if ($indent > 0)
+ $boxes[$g]["formatted"] = str_repeat(" ", $indent);
+ else
+ $boxes[$g]["formatted"] = '';
+ $boxes[$g]["formatted"] .= readShortMailboxName($mailbox, $dm);
+ } else {
+ $boxes[$g]["formatted"] = $mailbox;
+ }
+
+ $boxes[$g]['unformatted-dm'] = $mailbox;
+ if (substr($mailbox, -1) == $dm)
+ $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
+ $boxes[$g]['unformatted'] = $mailbox;
+ if (substr($mailbox,0,strlen($folder_prefix))==$folder_prefix)
+ $mailbox = substr($mailbox, strlen($folder_prefix));
+ $boxes[$g]['unformatted-disp'] = $mailbox;
+ $boxes[$g]['id'] = $g;
+
+ $boxes[$g]['flags'] = array();
+ if (isset($line[$g])) {
+ ereg("\(([^)]*)\)",$line[$g],$regs);
+ $flags = trim(strtolower(str_replace('\\', '',$regs[1])));
+ if ($flags)
+ $boxes[$g]['flags'] = explode(' ', $flags);
+ }
+ }