Пример #1
0
function formatMailboxName($imapConnection, $box_array)
{
    global $folder_prefix, $trash_folder, $sent_folder, $color, $move_to_sent, $move_to_trash, $unseen_notify, $unseen_type, $collapse_folders, $draft_folder, $save_as_draft, $use_special_folder_color;
    $real_box = $box_array['unformatted'];
    $mailbox = str_replace(' ', '', $box_array['formatted']);
    $mailboxURL = urlencode($real_box);
    /* Strip down the mailbox name. */
    if (ereg("^( *)([^ ]*)\$", $mailbox, $regs)) {
        $mailbox = $regs[2];
    }
    $unseen = 0;
    $status = array('', '');
    if ($unseen_notify == 2 && $real_box == 'INBOX' || $unseen_notify == 3) {
        $tmp_status = create_unseen_string($real_box, $box_array, $imapConnection, $unseen_type);
        if ($status !== false) {
            $status = $tmp_status;
        }
    }
    list($unseen_string, $unseen) = $status;
    $special_color = $use_special_folder_color && isSpecialMailbox($real_box);
    /* Start off with a blank line. */
    $line = '';
    /* If there are unseen message, bold the line. */
    if ($unseen > 0) {
        $line .= '<b>';
    }
    /* Create the link for this folder. */
    if ($status !== false) {
        $line .= '<a href="right_main.php?PG_SHOWALL=0&amp;sort=0&amp;startMessage=1&amp;mailbox=' . $mailboxURL . '" target="right" style="text-decoration:none">';
    }
    if ($special_color) {
        $line .= "<font color=\"{$color['11']}\">";
    }
    if ($mailbox == 'INBOX') {
        $line .= _("INBOX");
    } else {
        $line .= str_replace(array(' ', '<', '>'), array('&nbsp;', '&lt;', '&gt;'), $mailbox);
    }
    if ($special_color == TRUE) {
        $line .= '</font>';
    }
    if ($status !== false) {
        $line .= '</a>';
    }
    /* If there are unseen message, close bolding. */
    if ($unseen > 0) {
        $line .= "</b>";
    }
    /* Print unseen information. */
    if ($unseen_string != '') {
        $line .= "&nbsp;<small>{$unseen_string}</small>";
    }
    /* If it's the trash folder, show a purge link when needed */
    if ($move_to_trash && $real_box == $trash_folder) {
        if (!isset($numMessages)) {
            $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
        }
        if ($numMessages > 0 or $box_array['parent'] == 1) {
            $urlMailbox = urlencode($real_box);
            $line .= "\n<small>\n" . '&nbsp;&nbsp;(<a href="empty_trash.php" style="text-decoration:none">' . _("Purge") . '</a>)' . '</small>';
        }
    }
    $line .= concat_hook_function('left_main_after_each_folder', array(isset($numMessages) ? $numMessages : '', $real_box, $imapConnection));
    /* Return the final product. */
    return $line;
}
Пример #2
0
    echo addForm('folders_delete.php') . "<tt><select name=\"mailbox\">\n" . '         <option value="">[ ' . _("Select a folder") . " ]</option>\n";
    // send NULL for the flag - ALL folders are eligible for delete (except what we've got in skiplist)
    // use long format to make sure folder names make sense when parents may be missing.
    echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes, NULL, true);
    echo "</select></tt>\n" . '<input type="submit" value="' . _("Delete") . "\" />\n" . "</form></td></tr>\n";
} else {
    echo _("No folders found") . "<br /><br /></td></tr>";
}
echo html_tag('tr', html_tag('td', '&nbsp;', 'left', $color[4])) . "</table>\n";
/** UNSUBSCRIBE FOLDERS **/
echo html_tag('table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"') . html_tag('tr', html_tag('td', '<b>' . _("Unsubscribe") . '/' . _("Subscribe") . '</b>', 'center', $color[9], 'colspan="2"')) . html_tag('tr') . html_tag('td', '', 'center', $color[0], 'width="50%"');
if (count($skip_folders) < count($boxes)) {
    echo addForm('folders_subscribe.php?method=unsub') . "<tt><select name=\"mailbox[]\" multiple=\"multiple\" size=\"8\">\n";
    for ($i = 0; $i < count($boxes); $i++) {
        $use_folder = true;
        if (!isSpecialMailbox($boxes[$i]["unformatted"], false)) {
            $box = $boxes[$i]["unformatted-dm"];
            $box2 = str_replace(array(' ', '<', '>'), array('&nbsp;', '&lt;', '&gt;'), imap_utf7_decode_local($boxes[$i]["unformatted-disp"]));
            echo "         <option value=\"{$box}\">{$box2}</option>\n";
        }
    }
    echo "</select></tt><br /><br />\n" . '<input type="submit" value="' . _("Unsubscribe") . "\" />\n" . "</form></td>\n";
} else {
    echo _("No folders were found to unsubscribe from!") . '</td>';
}
$boxes_sub = $boxes;
/** SUBSCRIBE TO FOLDERS **/
echo html_tag('td', '', 'center', $color[0], 'width="50%"');
if (!$no_list_for_subscribe) {
    $boxes_all = sqimap_mailbox_list_all($imapConnection);
    $box = $box2 = array();
Пример #3
0
    }
}
if ($default_sub_of_inbox == false) {
    $mbx_option_list = '<option selected="selected" value="">[ ' . _("None") . " ]</option>\n";
} else {
    $mbx_option_list = '<option value="">[ ' . _("None") . " ]</option>\n";
    $show_selected = array('inbox');
}
// Call sqimap_mailbox_option_list, using existing connection to IMAP server,
// the arrays of folders to include or skip (assembled above),
// use 'noinferiors' as a mailbox filter to leave out folders that can not contain other folders.
// use the long format to show subfolders in an intelligible way if parent is missing (special folder)
$mbx_option_list .= sqimap_mailbox_option_list($imapConnection, $show_selected, $skip_folders, $boxes, 'noinferiors', true);
/** count special folders **/
foreach ($boxes as $index => $aBoxData) {
    if (isSpecialMailbox($aBoxData['unformatted'], false) && !in_array($aBoxData['unformatted'], $skip_folders)) {
        $skip_folders[] = $aBoxData['unformatted'];
    }
}
/**
 * Retrieve list of folders when special folders are excluded. Special folders
 * should be unavailable in rename/delete/unsubscribe. Theoretically user can
 * modify form and perform these operations with special folders, but if user
 * manages to delete/rename/unsubscribe special folder by hacking form...
 *
 * If script or program depends on special folder, they should not assume that
 * folder is available.
 *
 * $filtered_folders contains empty string or html formated option list.
 */
$rendel_folder_list = sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes, NULL, true);
Пример #4
0
/**
 * Returns sorted mailbox lists in several different ways.
 * See comment on sqimap_mailbox_parse() for info about the returned array.
 */
function sqimap_mailbox_list($imap_stream, $force = false)
{
    global $default_folder_prefix;
    if (!sqgetGlobalVar('boxesnew', $boxesnew, SQ_SESSION) || $force) {
        global $data_dir, $username, $list_special_folders_first, $folder_prefix, $trash_folder, $sent_folder, $draft_folder, $move_to_trash, $move_to_sent, $save_as_draft, $delimiter, $noselect_fix_enable;
        $inbox_in_list = false;
        $inbox_subscribed = false;
        require_once SM_PATH . 'include/load_prefs.php';
        if ($noselect_fix_enable) {
            $lsub_args = "LSUB \"{$folder_prefix}\" \"*%\"";
        } else {
            $lsub_args = "LSUB \"{$folder_prefix}\" \"*\"";
        }
        /* LSUB array */
        $lsub_ary = sqimap_run_command($imap_stream, $lsub_args, true, $response, $message);
        $sorted_lsub_ary = array();
        for ($i = 0, $cnt = count($lsub_ary); $i < $cnt; $i++) {
            /*
             * Workaround for mailboxes returned as literal
             * Doesn't work if the mailbox name is multiple lines
             * (larger then fgets buffer)
             */
            if (isset($lsub_ary[$i + 1]) && substr($lsub_ary[$i], -3) == "}\r\n") {
                if (ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)\$", $lsub_ary[$i], $regs)) {
                    $i++;
                    $lsub_ary[$i] = $regs[1] . '"' . addslashes(trim($lsub_ary[$i])) . '"' . $regs[2];
                }
            }
            $temp_mailbox_name = find_mailbox_name($lsub_ary[$i]);
            $sorted_lsub_ary[] = $temp_mailbox_name;
            if (!$inbox_subscribed && strtoupper($temp_mailbox_name) == 'INBOX') {
                $inbox_subscribed = true;
            }
        }
        /* remove duplicates */
        $sorted_lsub_ary = array_unique($sorted_lsub_ary);
        /* natural sort mailboxes */
        if (isset($sorted_lsub_ary)) {
            mailtree_sort($sorted_lsub_ary);
        }
        /*
         * The LSUB response doesn't provide us information about \Noselect
         * mail boxes. The LIST response does, that's why we need to do a LIST
         * call to retrieve the flags for the mailbox
         * Note: according RFC2060 an imap server may provide \NoSelect flags in the LSUB response.
         * in other words, we cannot rely on it.
         */
        $sorted_list_ary = array();
        for ($i = 0; $i < count($sorted_lsub_ary); $i++) {
            if (substr($sorted_lsub_ary[$i], -1) == $delimiter) {
                $mbx = substr($sorted_lsub_ary[$i], 0, strlen($sorted_lsub_ary[$i]) - 1);
            } else {
                $mbx = $sorted_lsub_ary[$i];
            }
            $read = sqimap_run_command($imap_stream, "LIST \"\" \"{$mbx}\"", true, $response, $message);
            /* Another workaround for literals */
            if (isset($read[1]) && substr($read[1], -3) == "}\r\n") {
                if (ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)\$", $read[0], $regs)) {
                    $read[0] = $regs[1] . '"' . addslashes(trim($read[1])) . '"' . $regs[2];
                }
            }
            if (isset($read[0])) {
                $sorted_list_ary[$i] = $read[0];
            } else {
                $sorted_list_ary[$i] = '';
            }
        }
        /*
         * Just in case they're not subscribed to their inbox,
         * we'll get it for them anyway
         */
        if (!$inbox_subscribed) {
            $inbox_ary = sqimap_run_command($imap_stream, "LIST \"\" \"INBOX\"", true, $response, $message);
            /* Another workaround for literals */
            if (isset($inbox_ary[1]) && substr($inbox_ary[0], -3) == "}\r\n") {
                if (ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)\$", $inbox_ary[0], $regs)) {
                    $inbox_ary[0] = $regs[1] . '"' . addslashes(trim($inbox_ary[1])) . '"' . $regs[2];
                }
            }
            $sorted_list_ary[] = $inbox_ary[0];
            $sorted_lsub_ary[] = find_mailbox_name($inbox_ary[0]);
        }
        $boxesall = sqimap_mailbox_parse($sorted_list_ary, $sorted_lsub_ary);
        /* Now, lets sort for special folders */
        $boxesnew = $used = array();
        /* Find INBOX */
        $cnt = count($boxesall);
        $used = array_pad($used, $cnt, false);
        for ($k = 0; $k < $cnt; ++$k) {
            if (strtolower($boxesall[$k]['unformatted']) == 'inbox') {
                $boxesnew[] = $boxesall[$k];
                $used[$k] = true;
                break;
            }
        }
        /* List special folders and their subfolders, if requested. */
        if ($list_special_folders_first) {
            for ($k = 0; $k < $cnt; ++$k) {
                if (!$used[$k] && isSpecialMailbox($boxesall[$k]['unformatted'])) {
                    $boxesnew[] = $boxesall[$k];
                    $used[$k] = true;
                }
            }
        }
        /* Find INBOX's children */
        for ($k = 0; $k < $cnt; ++$k) {
            if (!$used[$k] && isBoxBelow(strtolower($boxesall[$k]['unformatted']), 'inbox') && strtolower($boxesall[$k]['unformatted']) != 'inbox') {
                $boxesnew[] = $boxesall[$k];
                $used[$k] = true;
            }
        }
        /* Rest of the folders */
        for ($k = 0; $k < $cnt; $k++) {
            if (!$used[$k]) {
                $boxesnew[] = $boxesall[$k];
            }
        }
        sqsession_register($boxesnew, 'boxesnew');
    }
    return $boxesnew;
}
Пример #5
0
/**
 * Gets the list of mailboxes for sqimap_maolbox_tree and sqimap_mailbox_list
 *
 * This is because both of those functions had duplicated logic, but with slightly different
 * implementations. This will make both use the same implementation, which should make it
 * easier to maintain and easier to modify in the future
 * @param stream $imap_stream imap connection resource
 * @param bool $force force a reload and ignore cache
 * @param bool $show_only_subscribed controls listing of visible or all folders
 * @param bool $session_register controls registration of retrieved data in session.
 * @return object boxesnew - array of mailboxes and their attributes
 * @since 1.5.1
 */
function sqimap_get_mailboxes($imap_stream, $force = false, $show_only_subscribed = true, $session_register = true)
{
    global $show_only_subscribed_folders, $noselect_fix_enable, $folder_prefix, $list_special_folders_first, $imap_server_type;
    $inbox_subscribed = false;
    $listsubscribed = sqimap_capability($imap_stream, 'LIST-SUBSCRIBED');
    if ($show_only_subscribed) {
        $show_only_subscribed = $show_only_subscribed_folders;
    }
    //require_once(SM_PATH . 'include/load_prefs.php');
    /**
     * There are three main listing commands we can use in IMAP:
     * LSUB        shows just the list of subscribed folders
     *            may include flags, but these are not necessarily accurate or authoratative
     *            \NoSelect has special meaning: the folder does not exist -OR- it means this
     *            folder is not subscribed but children may be
     *            [RFC-2060]
     * LIST        this shows every mailbox on the system
     *            flags are always included and are accurate and authoratative
     *            \NoSelect means folder should not be selected
     *            [RFC-2060]
     * LIST (SUBSCRIBED)    implemented with LIST-SUBSCRIBED extension
     *            this is like list but returns only subscribed folders
     *            flag meanings are like LIST, not LSUB
     *            \NonExistent means mailbox doesn't exist
     *            \PlaceHolder means parent is not valid (selectable), but one or more children are
     *            \NoSelect indeed means that the folder should not be selected
     *            IMAPEXT-LIST-EXTENSIONS-04 August 2003 B. Leiba
     */
    if (!$show_only_subscribed) {
        $lsub = 'LIST';
        $sub_cache_name = 'list_cache';
    } elseif ($listsubscribed) {
        $lsub = 'LIST (SUBSCRIBED)';
        $sub_cache_name = 'listsub_cache';
    } else {
        $lsub = 'LSUB';
        $sub_cache_name = 'lsub_cache';
    }
    // Some IMAP servers allow subfolders to exist even if the parent folders do not
    // This fixes some problems with the folder list when this is the case, causing the
    // NoSelect folders to be displayed
    if ($noselect_fix_enable) {
        $lsub_args = "{$lsub} \"{$folder_prefix}\" \"*%\"";
        $list_args = "LIST \"{$folder_prefix}\" \"*%\"";
    } else {
        $lsub_args = "{$lsub} \"{$folder_prefix}\" \"*\"";
        $list_args = "LIST \"{$folder_prefix}\" \"*\"";
    }
    // get subscribed mailbox list from cache (session)
    // if not there, then get it from the imap server and store in cache
    if (!$force) {
        sqgetGlobalVar($sub_cache_name, $lsub_cache, SQ_SESSION);
    }
    $lsub_assoc_ary = array();
    if (!empty($lsub_cache)) {
        $lsub_assoc_ary = $lsub_cache;
    } else {
        $lsub_ary = sqimap_run_command($imap_stream, $lsub_args, true, $response, $message);
        $lsub_ary = compact_mailboxes_response($lsub_ary);
        if (!empty($lsub_ary)) {
            foreach ($lsub_ary as $rawline) {
                $temp_mailbox_name = find_mailbox_name($rawline);
                $lsub_assoc_ary[$temp_mailbox_name] = $rawline;
            }
            unset($lsub_ary);
            sqsession_register($lsub_assoc_ary, $sub_cache_name);
        }
    }
    // Now to get the mailbox flags
    // The LSUB response may return \NoSelect flags, etc. but it is optional
    // according to RFC3501, and even when returned it may not be accurate
    // or authoratative. LIST will always return accurate results.
    if ($lsub == 'LIST' || $lsub == 'LIST (SUBSCRIBED)') {
        // we've already done a LIST or LIST (SUBSCRIBED)
        // and NOT a LSUB, so no need to do it again
        $list_assoc_ary = $lsub_assoc_ary;
    } else {
        // we did a LSUB so now we need to do a LIST
        // first see if it is in cache
        $list_cache_name = 'list_cache';
        if (!$force) {
            sqgetGlobalVar($list_cache_name, $list_cache, SQ_SESSION);
        }
        if (!empty($list_cache)) {
            $list_assoc_ary = $list_cache;
            // we could store this in list_cache_name but not necessary
        } else {
            // not in cache so we need to go get it from the imap server
            $list_assoc_ary = array();
            $list_ary = sqimap_run_command($imap_stream, $list_args, true, $response, $message);
            $list_ary = compact_mailboxes_response($list_ary);
            if (!empty($list_ary)) {
                foreach ($list_ary as $rawline) {
                    $temp_mailbox_name = find_mailbox_name($rawline);
                    $list_assoc_ary[$temp_mailbox_name] = $rawline;
                }
                unset($list_ary);
                sqsession_register($list_assoc_ary, $list_cache_name);
            }
        }
    }
    // If they aren't subscribed to the inbox, then add it anyway (if its in LIST)
    $inbox_subscribed = false;
    if (!empty($lsub_assoc_ary)) {
        foreach ($lsub_assoc_ary as $temp_mailbox_name => $rawline) {
            if (strtoupper($temp_mailbox_name) == 'INBOX') {
                $inbox_subscribed = true;
            }
        }
    }
    if (!$inbox_subscribed) {
        if (!empty($list_assoc_ary)) {
            foreach ($list_assoc_ary as $temp_mailbox_name => $rawline) {
                if (strtoupper($temp_mailbox_name) == 'INBOX') {
                    $lsub_assoc_ary[$temp_mailbox_name] = $rawline;
                }
            }
        }
    }
    // Now we have the raw output, we need to create an array of mailbox names we will return
    if (!$show_only_subscribed) {
        $final_folders_assoc_ary = $list_assoc_ary;
    } else {
        /**
         * only show subscribed folders
         * we need to merge the folders here... we can't trust the flags, etc. from the lsub_assoc_array
         * so we use the lsub_assoc_array as the list of folders and the values come from list_assoc_array
         */
        if (!empty($lsub_assoc_ary)) {
            foreach ($lsub_assoc_ary as $temp_mailbox_name => $rawline) {
                if (!empty($list_assoc_ary[$temp_mailbox_name])) {
                    $final_folders_assoc_ary[$temp_mailbox_name] = $list_assoc_ary[$temp_mailbox_name];
                }
            }
        }
    }
    // Now produce a flat, sorted list
    if (!empty($final_folders_assoc_ary)) {
        uksort($final_folders_assoc_ary, 'strnatcasecmp');
        foreach ($final_folders_assoc_ary as $temp_mailbox_name => $rawline) {
            $final_folders_ary[] = $rawline;
        }
    }
    // this will put it into an array we can use later
    // containing:
    // raw    - Raw LIST/LSUB response from the IMAP server
    // formatted - formatted folder name
    // unformatted - unformatted, but with the delimiter at the end removed
    // unformated-dm - folder name as it appears in raw response
    // unformatted-disp - unformatted without $folder_prefix
    // id - the array element number (0, 1, 2, etc.)
    // flags - mailbox flags
    if (!empty($final_folders_ary)) {
        $boxesall = sqimap_mailbox_parse($final_folders_ary);
    } else {
        // they have no mailboxes
        $boxesall = array();
    }
    /* Now, lets sort for special folders */
    $boxesnew = $used = array();
    /* Find INBOX */
    $cnt = count($boxesall);
    $used = array_pad($used, $cnt, false);
    $has_inbox = false;
    for ($k = 0; $k < $cnt; ++$k) {
        if (strtoupper($boxesall[$k]['unformatted']) == 'INBOX') {
            $boxesnew[] = $boxesall[$k];
            $used[$k] = true;
            $has_inbox = true;
            break;
        }
    }
    if ($has_inbox == false) {
        // do a list request for inbox because we should always show
        // inbox even if the user isn't subscribed to it.
        $inbox_ary = sqimap_run_command($imap_stream, 'LIST "" "INBOX"', true, $response, $message);
        $inbox_ary = compact_mailboxes_response($inbox_ary);
        if (count($inbox_ary)) {
            $inbox_entry = sqimap_mailbox_parse($inbox_ary);
            // add it on top of the list
            if (!empty($boxesnew)) {
                array_unshift($boxesnew, $inbox_entry[0]);
            } else {
                $boxesnew[] = $inbox_entry[0];
            }
            /* array_unshift($used,true); */
        }
    }
    /* List special folders and their subfolders, if requested. */
    if ($list_special_folders_first) {
        for ($k = 0; $k < $cnt; ++$k) {
            if (!$used[$k] && isSpecialMailbox($boxesall[$k]['unformatted'])) {
                $boxesnew[] = $boxesall[$k];
                $used[$k] = true;
            }
        }
    }
    /* Find INBOX's children */
    for ($k = 0; $k < $cnt; ++$k) {
        $isboxbelow = isBoxBelow(strtoupper($boxesall[$k]['unformatted']), 'INBOX');
        if (strtoupper($boxesall[$k]['unformatted']) == 'INBOX') {
            $is_inbox = 1;
        } else {
            $is_inbox = 0;
        }
        if (!$used[$k] && $isboxbelow && $is_inbox) {
            $boxesnew[] = $boxesall[$k];
            $used[$k] = true;
        }
    }
    /* Rest of the folders */
    for ($k = 0; $k < $cnt; $k++) {
        if (!$used[$k]) {
            $boxesnew[] = $boxesall[$k];
        }
    }
    /**
     * Don't register boxes in session, if $session_register is set to false
     * Prevents registration of sqimap_mailbox_list_all() results.
     */
    if ($session_register) {
        sqsession_register($boxesnew, 'boxesnew');
    }
    return $boxesnew;
}
Пример #6
0
/**
 * Returns sorted mailbox lists in several different ways.
 * See comment on sqimap_mailbox_parse() for info about the returned array.
 */
function sqimap_mailbox_list($imap_stream, $force = false)
{
    global $default_folder_prefix;
    if (!sqgetGlobalVar('boxesnew', $boxesnew, SQ_SESSION) || $force) {
        global $data_dir, $username, $list_special_folders_first, $folder_prefix, $trash_folder, $sent_folder, $draft_folder, $move_to_trash, $move_to_sent, $save_as_draft, $delimiter, $noselect_fix_enable, $imap_server_type;
        $inbox_in_list = false;
        $inbox_subscribed = false;
        $listsubscribed = sqimap_capability($imap_stream, 'LIST-SUBSCRIBED');
        require_once SM_PATH . 'include/load_prefs.php';
        if ($listsubscribed) {
            $lsub = 'LIST (SUBSCRIBED)';
        } else {
            $lsub = 'LSUB';
        }
        if ($noselect_fix_enable) {
            $lsub_args = "{$lsub} \"{$folder_prefix}\" \"*%\"";
        } else {
            $lsub_args = "{$lsub} \"{$folder_prefix}\" \"*\"";
        }
        /* LSUB array */
        $lsub_ary = sqimap_run_command($imap_stream, $lsub_args, true, $response, $message);
        $lsub_ary = compact_mailboxes_response($lsub_ary);
        $sorted_lsub_ary = array();
        for ($i = 0, $cnt = count($lsub_ary); $i < $cnt; $i++) {
            $temp_mailbox_name = find_mailbox_name($lsub_ary[$i]);
            $sorted_lsub_ary[] = $temp_mailbox_name;
            if (!$inbox_subscribed && strtoupper($temp_mailbox_name) == 'INBOX') {
                $inbox_subscribed = true;
            }
        }
        /* natural sort mailboxes */
        if (isset($sorted_lsub_ary)) {
            usort($sorted_lsub_ary, 'strnatcasecmp');
        }
        /*
         * The LSUB response doesn't provide us information about \Noselect
         * mail boxes. The LIST response does, that's why we need to do a LIST
         * call to retrieve the flags for the mailbox
         * Note: according RFC2060 an imap server may provide \NoSelect flags in the LSUB response.
         * in other words, we cannot rely on it.
         */
        $sorted_list_ary = array();
        //       if (!$listsubscribed) {
        for ($i = 0; $i < count($sorted_lsub_ary); $i++) {
            if (substr($sorted_lsub_ary[$i], -1) == $delimiter) {
                $mbx = substr($sorted_lsub_ary[$i], 0, strlen($sorted_lsub_ary[$i]) - 1);
            } else {
                $mbx = $sorted_lsub_ary[$i];
            }
            $read = sqimap_run_command($imap_stream, 'LIST "" ' . sqimap_encode_mailbox_name($mbx), true, $response, $message);
            $read = compact_mailboxes_response($read);
            if (isset($read[0])) {
                $sorted_list_ary[$i] = $read[0];
            } else {
                $sorted_list_ary[$i] = '';
            }
        }
        //       }
        /*
         * Just in case they're not subscribed to their inbox,
         * we'll get it for them anyway
         */
        if (!$inbox_subscribed) {
            $inbox_ary = sqimap_run_command($imap_stream, 'LIST "" "INBOX"', true, $response, $message);
            $sorted_list_ary[] = implode('', compact_mailboxes_response($inbox_ary));
            $sorted_lsub_ary[] = find_mailbox_name($inbox_ary[0]);
        }
        $boxesall = sqimap_mailbox_parse($sorted_list_ary, $sorted_lsub_ary);
        /* Now, lets sort for special folders */
        $boxesnew = $used = array();
        /* Find INBOX */
        $cnt = count($boxesall);
        $used = array_pad($used, $cnt, false);
        for ($k = 0; $k < $cnt; ++$k) {
            if (strtolower($boxesall[$k]['unformatted']) == 'inbox') {
                $boxesnew[] = $boxesall[$k];
                $used[$k] = true;
                break;
            }
        }
        /* List special folders and their subfolders, if requested. */
        if ($list_special_folders_first) {
            for ($k = 0; $k < $cnt; ++$k) {
                if (!$used[$k] && isSpecialMailbox($boxesall[$k]['unformatted'])) {
                    $boxesnew[] = $boxesall[$k];
                    $used[$k] = true;
                }
            }
        }
        /* Rest of the folders */
        for ($k = 0; $k < $cnt; $k++) {
            if (!$used[$k]) {
                $boxesnew[] = $boxesall[$k];
            }
        }
        sqsession_register($boxesnew, 'boxesnew');
    }
    return $boxesnew;
}
Пример #7
0
function newmail_folder_status($statusarr)
{
    global $newmail_media_enable, $newmail_popup, $newmail_changetitle, $trash_folder, $sent_folder, $totalNewArr, $newmail_unseen_notify, $unseen_notify, $newmail_recent;
    /* if $newmail_unseen_notify is set to zero, plugin follows $unseen_notify */
    if ($newmail_unseen_notify == 0) {
        $newmail_unseen_notify = $unseen_notify;
    }
    $mailbox = $statusarr['MAILBOX'];
    if (($newmail_media_enable == 'on' || $newmail_popup == 'on' || $newmail_changetitle == 'on') && ($newmail_unseen_notify > SMPREF_UNSEEN_NONE && $newmail_unseen_notify <= SMPREF_UNSEEN_NORMAL)) {
        // Skip folders for Sent and Trash
        // TODO: make this optional
        if ($statusarr['MAILBOX'] == $sent_folder || $statusarr['MAILBOX'] == $trash_folder) {
            return 0;
        }
        if ($mailbox == 'INBOX' && $newmail_unseen_notify == SMPREF_UNSEEN_INBOX || $newmail_unseen_notify == SMPREF_UNSEEN_SPECIAL && isSpecialMailbox($mailbox) || $newmail_unseen_notify == SMPREF_UNSEEN_NORMAL && !isSpecialMailbox($mailbox) || $newmail_unseen_notify == SMPREF_UNSEEN_ALL) {
            if ($newmail_recent == 'on' && !empty($statusarr['RECENT'])) {
                $totalNewArr[$mailbox] = $statusarr['RECENT'];
            } elseif ($newmail_recent != 'on' && !empty($statusarr['UNSEEN'])) {
                $totalNewArr[$mailbox] = $statusarr['UNSEEN'];
            }
        }
    }
}