Esempio n. 1
0
/**
 * Given an array of folder_names, subscribes to each of them.
 */
function folders_subscribe($imapConnection, $folder_names)
{
    global $color, $oTemplate;
    if (count($folder_names) == 0 || $folder_names[0] == '') {
        plain_error_message(_("You have not selected a folder to subscribe. Please do so.") . '<br /><a href="../src/folders.php">' . _("Click here to go back") . '</a>.', $color);
        sqimap_logout($imapConnection);
        $oTemplate->display('footer.tpl');
        exit;
    }
    global $no_list_for_subscribe, $imap_server_type;
    if ($no_list_for_subscribe && $imap_server_type == 'cyrus') {
        /* Cyrus, atleast, does not typically allow subscription to
         * nonexistent folders (this is an optional part of IMAP),
         * lets catch it here and report back cleanly. */
        if (!sqimap_mailbox_exists($imapConnection, $folder_names[0])) {
            plain_error_message(_("Subscription Unsuccessful - Folder does not exist.") . '<br /><a href="../src/folders.php">' . _("Click here to go back") . '</a>.', $color);
            sqimap_logout($imapConnection);
            exit;
        }
    }
    foreach ($folder_names as $folder_name) {
        sqimap_subscribe($imapConnection, $folder_name);
    }
    return;
}
Esempio n. 2
0
if (isset($left_refresh) && $left_refresh != '' && !stristr($left_refresh, 'none')) {
    $xtra = "\n<meta http-equiv=\"Expires\" content=\"Thu, 01 Dec 1994 16:00:00 GMT\">\n" . "<meta http-equiv=\"Pragma\" content=\"no-cache\">\n" . "<meta http-equiv=\"REFRESH\" content=\"{$left_refresh};URL=left_main.php\">\n";
} else {
    $xtra = '';
}
displayHtmlHeader($org_title, $xtra);
/* If requested and not yet complete, attempt to autocreate folders. */
if ($auto_create_special && !$auto_create_done) {
    $autocreate = array($sent_folder, $trash_folder, $draft_folder);
    foreach ($autocreate as $folder) {
        if ($folder != '' && $folder != 'none') {
            if (!sqimap_mailbox_exists($imapConnection, $folder)) {
                sqimap_mailbox_create($imapConnection, $folder, '');
            } else {
                if (!sqimap_mailbox_is_subscribed($imapConnection, $folder)) {
                    sqimap_subscribe($imapConnection, $folder);
                }
            }
        }
    }
    /* Let the world know that autocreation is complete! Hurrah! */
    $auto_create_done = TRUE;
    sqsession_register($auto_create_done, 'auto_create_done');
    /* retrieve the mailboxlist. We do this at a later stage again but if
         the right_frame loads faster then the second call retrieves a cached
         version of the mailboxlist without the newly created folders.
         The second parameter forces a non cached mailboxlist return.
       */
    $boxes = sqimap_mailbox_list($imapConnection, true);
}
echo "\n<body bgcolor=\"{$color['3']}\" text=\"{$color['6']}\" link=\"{$color['6']}\" vlink=\"{$color['6']}\" alink=\"{$color['6']}\">\n";
Esempio n. 3
0
/**
 * Update sent_subfolders settings
 *
 * function updates default sent folder value and 
 * creates required imap folders
 */
function sent_subfolders_update_sentfolder()
{
    global $sent_folder, $auto_create_special, $auto_create_done;
    global $sent_subfolders_base, $sent_subfolders_setting;
    global $data_dir, $imapServerAddress, $imapPort;
    global $use_sent_subfolders, $move_to_sent, $imap_server_type;
    sqgetGlobalVar('username', $username, SQ_SESSION);
    sqgetGlobalVar('key', $key, SQ_COOKIE);
    sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
    if ($use_sent_subfolders || $move_to_sent) {
        $year = date('Y');
        $month = date('m');
        $quarter = sent_subfolder_getQuarter($month);
        /*
            Regarding the structure we've got three main possibilities.
            One sent holder. level 0.
            Multiple year holders with messages in it. level 1.
            Multiple year folders with holders in it. level 2.
        */
        /*
                if( $imap_server_type == 'uw' ) {
                    $cnd_delimiter = '';
                } else {
                    $cnd_delimiter = $delimiter;
                }
        */
        $cnd_delimiter = $delimiter;
        switch ($sent_subfolders_setting) {
            case SMPREF_SENT_SUBFOLDERS_YEARLY:
                $level = 1;
                $sent_subfolder = $sent_subfolders_base . $cnd_delimiter . $year;
                break;
            case SMPREF_SENT_SUBFOLDERS_QUARTERLY:
                $level = 2;
                $sent_subfolder = $sent_subfolders_base . $cnd_delimiter . $year . $delimiter . $quarter;
                $year_folder = $sent_subfolders_base . $year;
                break;
            case SMPREF_SENT_SUBFOLDERS_MONTHLY:
                $level = 2;
                $sent_subfolder = $sent_subfolders_base . $cnd_delimiter . $year . $delimiter . $month;
                $year_folder = $sent_subfolders_base . $year;
                break;
            case SMPREF_SENT_SUBFOLDERS_DISABLED:
            default:
                $level = 0;
                $sent_subfolder = $sent_folder;
                $year_folder = $sent_folder;
        }
        /* If this folder is NOT the current sent folder, update stuff. */
        if ($sent_subfolder != $sent_folder) {
            /* First, update the sent folder. */
            setPref($data_dir, $username, 'sent_folder', $sent_subfolder);
            setPref($data_dir, $username, 'move_to_sent', SMPREF_ON);
            $sent_folder = $sent_subfolder;
            $move_to_sent = SMPREF_ON;
            /* Auto-create folders, if they do not yet exist. */
            if ($sent_folder != 'none') {
                /* Create the imap connection. */
                $ic = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10);
                /* Auto-create the year folder, if it does not yet exist. */
                if (!sqimap_mailbox_exists($ic, $year_folder)) {
                    sqimap_mailbox_create($ic, $year_folder, $level == 1 ? '' : 'noselect');
                } else {
                    if (!sqimap_mailbox_is_subscribed($ic, $year_folder)) {
                        sqimap_subscribe($ic, $year_folder);
                    }
                }
                /* Auto-create the subfolder, if it does not yet exist. */
                if (!sqimap_mailbox_exists($ic, $sent_folder)) {
                    sqimap_mailbox_create($ic, $sent_folder, '');
                } else {
                    if (!sqimap_mailbox_is_subscribed($ic, $sent_subfolder)) {
                        sqimap_subscribe($ic, $sent_subfolder);
                    }
                }
                /* Close the imap connection. */
                sqimap_logout($ic);
            }
        }
    }
}
$location = get_location();
if (!isset($mailbox) || !isset($mailbox[0]) || $mailbox[0] == '') {
    header("Location: {$location}/folders.php");
    exit(0);
}
$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
if ($method == 'sub') {
    if ($no_list_for_subscribe && $imap_server_type == 'cyrus') {
        /* Cyrus, atleast, does not typically allow subscription to
         * nonexistent folders (this is an optional part of IMAP),
         * lets catch it here and report back cleanly. */
        if (!sqimap_mailbox_exists($imapConnection, $mailbox[0])) {
            header("Location: {$location}/folders.php?success=subscribe-doesnotexist");
            sqimap_logout($imapConnection);
            exit(0);
        }
    }
    for ($i = 0; $i < count($mailbox); $i++) {
        $mailbox[$i] = trim($mailbox[$i]);
        sqimap_subscribe($imapConnection, $mailbox[$i]);
    }
    $success = 'subscribe';
} else {
    for ($i = 0; $i < count($mailbox); $i++) {
        $mailbox[$i] = trim($mailbox[$i]);
        sqimap_unsubscribe($imapConnection, $mailbox[$i]);
    }
    $success = 'unsubscribe';
}
sqimap_logout($imapConnection);
header("Location: {$location}/folders.php?success={$success}");
Esempio n. 5
0
/**
 * Update sent_subfolders settings
 *
 * function updates default sent folder value and
 * creates required imap folders
 */
function sent_subfolders_update_sentfolder_do()
{
    global $sent_folder, $username, $data_dir, $imapServerAddress, $imapPort, $imap_stream_options, $move_to_sent;
    sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
    $use_sent_subfolders = getPref($data_dir, $username, 'use_sent_subfolders', SMPREF_OFF);
    $sent_subfolders_setting = getPref($data_dir, $username, 'sent_subfolders_setting', SMPREF_SENT_SUBFOLDERS_DISABLED);
    $sent_subfolders_base = getPref($data_dir, $username, 'sent_subfolders_base', $sent_folder);
    if ($use_sent_subfolders || $move_to_sent) {
        $year = date('Y');
        $month = date('m');
        $quarter = sent_subfolder_getQuarter($month);
        /**
         * Regarding the structure we've got three main possibilities.
         * One sent holder. level 0.
         * Multiple year holders with messages in it. level 1.
         * Multiple year folders with holders in it. level 2.
         */
        switch ($sent_subfolders_setting) {
            case SMPREF_SENT_SUBFOLDERS_YEARLY:
                $level = 1;
                $sent_subfolder = $sent_subfolders_base . $delimiter . $year;
                break;
            case SMPREF_SENT_SUBFOLDERS_QUARTERLY:
                $level = 2;
                $sent_subfolder = $sent_subfolders_base . $delimiter . $year . $delimiter . $quarter;
                $year_folder = $sent_subfolders_base . $delimiter . $year;
                break;
            case SMPREF_SENT_SUBFOLDERS_MONTHLY:
                $level = 2;
                $sent_subfolder = $sent_subfolders_base . $delimiter . $year . $delimiter . $month;
                $year_folder = $sent_subfolders_base . $delimiter . $year;
                break;
            case SMPREF_SENT_SUBFOLDERS_DISABLED:
            default:
                $level = 0;
                $sent_subfolder = $sent_folder;
                $year_folder = $sent_folder;
        }
        /* If this folder is NOT the current sent folder, update stuff. */
        if ($sent_subfolder != $sent_folder) {
            /* Auto-create folders, if they do not yet exist. */
            if ($sent_subfolder != 'none') {
                /* Create the imap connection. */
                $ic = sqimap_login($username, false, $imapServerAddress, $imapPort, 10, $imap_stream_options);
                $boxes = false;
                /**
                 * If sent_subfolder can't store messages (noselect) ||
                 * year_folder can't store subfolders (noinferiors) in level=2 setup ||
                 * subfolder_base can't store subfolders (noinferiors), setup is broken
                 */
                if (sqimap_mailbox_is_noselect($ic, $sent_subfolder, $boxes) || $level == 2 && sqimap_mailbox_is_noinferiors($ic, $year_folder, $boxes) || sqimap_mailbox_is_noinferiors($ic, $sent_subfolders_base, $boxes)) {
                    error_box(_("Sent subfolders options are misconfigured."));
                } else {
                    if ($level == 2) {
                        /* Auto-create the year folder, if it does not yet exist. */
                        if (!sqimap_mailbox_exists($ic, $year_folder)) {
                            sqimap_mailbox_create($ic, $year_folder, 'noselect');
                            // TODO: safety check for imap servers that can't create subfolders
                        } else {
                            if (!sqimap_mailbox_is_subscribed($ic, $year_folder)) {
                                sqimap_subscribe($ic, $year_folder);
                            }
                        }
                    }
                    /* Auto-create the subfolder, if it does not yet exist. */
                    if (!sqimap_mailbox_exists($ic, $sent_subfolder)) {
                        sqimap_mailbox_create($ic, $sent_subfolder, '');
                    } else {
                        if (!sqimap_mailbox_is_subscribed($ic, $sent_subfolder)) {
                            sqimap_subscribe($ic, $sent_subfolder);
                        }
                    }
                    /* Update sent_folder setting in prefs only if the base
                       subfolders setting is not the same as the normal sent
                       folder...  otherwise, it is quite misleading to the user.
                       If the sent folder is the same as the subfolders base, it's
                       OK to leave the sent folder as is.
                       The sent_folder setting itself needs to be the actual
                       subfolder (not the base) for proper functionality */
                    if ($sent_subfolders_base != $sent_folder) {
                        setPref($data_dir, $username, 'sent_folder', $sent_subfolders_base);
                        setPref($data_dir, $username, 'move_to_sent', SMPREF_ON);
                        setPref($data_dir, $username, 'translate_special_folders', SMPREF_OFF);
                    }
                    $sent_folder = $sent_subfolder;
                    $move_to_sent = SMPREF_ON;
                }
                /* Close the imap connection. */
                sqimap_logout($ic);
            }
        }
    }
}
Esempio n. 6
0
/**
 * Renames a mailbox.
 */
function sqimap_mailbox_rename($imap_stream, $old_name, $new_name)
{
    if ($old_name != $new_name) {
        global $delimiter, $imap_server_type, $data_dir, $username;
        if (substr($old_name, -1) == $delimiter) {
            $old_name = substr($old_name, 0, strlen($old_name) - 1);
            $new_name = substr($new_name, 0, strlen($new_name) - 1);
            $postfix = $delimiter;
        } else {
            $postfix = '';
        }
        $boxesall = sqimap_mailbox_list_all($imap_stream);
        $cmd = 'RENAME "' . $old_name . '" "' . $new_name . '"';
        $data = sqimap_run_command($imap_stream, $cmd, true, $response, $message);
        sqimap_unsubscribe($imap_stream, $old_name . $postfix);
        $oldpref_thread = getPref($data_dir, $username, 'thread_' . $old_name . $postfix);
        $oldpref_collapse = getPref($data_dir, $username, 'collapse_folder_' . $old_name . $postfix);
        removePref($data_dir, $username, 'thread_' . $old_name . $postfix);
        removePref($data_dir, $username, 'collapse_folder_' . $old_name . $postfix);
        sqimap_subscribe($imap_stream, $new_name . $postfix);
        setPref($data_dir, $username, 'thread_' . $new_name . $postfix, $oldpref_thread);
        setPref($data_dir, $username, 'collapse_folder_' . $new_name . $postfix, $oldpref_collapse);
        do_hook_function('rename_or_delete_folder', $args = array($old_name, 'rename', $new_name));
        $l = strlen($old_name) + 1;
        $p = 'unformatted';
        foreach ($boxesall as $box) {
            if (substr($box[$p], 0, $l) == $old_name . $delimiter) {
                $new_sub = $new_name . $delimiter . substr($box[$p], $l);
                /* With Cyrus IMAPd >= 2.0 rename is recursive, so don't check for errors here */
                if ($imap_server_type == 'cyrus') {
                    $cmd = 'RENAME "' . $box[$p] . '" "' . $new_sub . '"';
                    $data = sqimap_run_command($imap_stream, $cmd, false, $response, $message);
                }
                $was_subscribed = sqimap_mailbox_is_subscribed($imap_stream, $box[$p]);
                if ($was_subscribed) {
                    sqimap_unsubscribe($imap_stream, $box[$p]);
                }
                $oldpref_thread = getPref($data_dir, $username, 'thread_' . $box[$p]);
                $oldpref_collapse = getPref($data_dir, $username, 'collapse_folder_' . $box[$p]);
                removePref($data_dir, $username, 'thread_' . $box[$p]);
                removePref($data_dir, $username, 'collapse_folder_' . $box[$p]);
                if ($was_subscribed) {
                    sqimap_subscribe($imap_stream, $new_sub);
                }
                setPref($data_dir, $username, 'thread_' . $new_sub, $oldpref_thread);
                setPref($data_dir, $username, 'collapse_folder_' . $new_sub, $oldpref_collapse);
                do_hook_function('rename_or_delete_folder', $args = array($box[$p], 'rename', $new_sub));
            }
        }
    }
}
Esempio n. 7
0
             */
            if ($show_only_subscribed_folders) {
                $mailbox_cache = false;
            } else {
                $mailbox_cache = $mailboxes;
            }
            if (!sqimap_mailbox_exists($imapConnection, $folder, $mailbox_cache)) {
                sqimap_mailbox_create($imapConnection, $folder, '');
                $folders_created = true;
            } else {
                // check for subscription is useless and expensive, just
                // surpress the NO response. Unless we're on Mecury, which
                // will just subscribe a folder again if it's already
                // subscribed.
                if (strtolower($imap_server_type) != 'mercury32' || !sqimap_mailbox_is_subscribed($imapConnection, $folder)) {
                    sqimap_subscribe($imapConnection, $folder, false);
                    $folders_created = true;
                }
            }
        }
    }
    /* Let the world know that autocreation is complete! Hurrah! */
    $auto_create_done = TRUE;
    sqsession_register($auto_create_done, 'auto_create_done');
    // reload mailbox list
    if ($folders_created) {
        $mailboxes = sqimap_get_mailboxes($imapConnection, true, $show_only_subscribed_folders);
    }
}
$clock = '';
if ($date_format != 6) {
function sqimap_mailbox_tree($imap_stream)
{
    global $boxesnew, $default_folder_prefix, $unseen_notify, $unseen_type;
    if (!isset($boxesnew)) {
        global $data_dir, $username, $list_special_folders_first, $folder_prefix, $delimiter, $trash_folder, $move_to_trash;
        $inbox_in_list = false;
        $inbox_subscribed = false;
        require_once SM_PATH . 'include/load_prefs.php';
        /* LSUB array */
        $lsub_ary = sqimap_run_command($imap_stream, "LSUB \"{$folder_prefix}\" \"*\"", true, $response, $message);
        /*
         * Section about removing the last element was removed 
         * We don't return "* OK" anymore from sqimap_read_data
         */
        $sorted_lsub_ary = array();
        $cnt = count($lsub_ary);
        for ($i = 0; $i < $cnt; $i++) {
            /*
             * Workaround for EIMS
             * Doesn't work if the mailbox name is multiple lines
             */
            if (isset($lsub_ary[$i + 1]) && 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];
            }
            /*
            if (preg_match("/^\*\s+LSUB\s+\((.*)\)\s+\"(.*)\"\s+\"?(.+(?=\")|.+).*$/",$lsub_ary[$i],$regs)) {
                $flag = $regs[1];
                $mbx = trim($regs[3]);
                $sorted_lsub_ary[] = array ('mbx' => $mbx, 'flag' => $flag); 
            }
            */
            $mbx = find_mailbox_name($lsub_ary[$i]);
            $noselect = check_is_noselect($lsub_ary[$i]);
            if (substr($mbx, -1) == $delimiter) {
                $mbx = substr($mbx, 0, strlen($mbx) - 1);
            }
            $sorted_lsub_ary[] = array('mbx' => $mbx, 'noselect' => $noselect);
        }
        array_multisort($sorted_lsub_ary, SORT_ASC, SORT_REGULAR);
        for ($i = 0; $i < $cnt; $i++) {
            if ($sorted_lsub_ary[$i]['mbx'] == 'INBOX') {
                $inbox_in_list = true;
                break;
            }
        }
        /*
         * Just in case they're not subscribed to their inbox,
         * we'll get it for them anyway
         */
        if (!$inbox_in_list) {
            $inbox_ary = sqimap_run_command($imap_stream, "LIST \"\" \"INBOX\"", true, $response, $message);
            /* Another workaround for EIMS */
            if (isset($inbox_ary[1]) && ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)\$", $inbox_ary[0], $regs)) {
                $inbox_ary[0] = $regs[1] . '"' . addslashes(trim($inbox_ary[1])) . '"' . $regs[2];
            }
            $mbx = find_mailbox_name($inbox_ary[0]);
            if (substr($mbx, -1) == $delimiter) {
                $mbx = substr($mbx, 0, strlen($mbx) - 1);
            }
            if ($mbx == 'INBOX') {
                $sorted_lsub_ary[] = array('mbx' => $mbx, 'flag' => '');
                sqimap_subscribe($imap_stream, 'INBOX');
                $cnt++;
            }
            /*
            if (preg_match("/^\*\s+LIST\s+\((.*)\)\s+\"(.*)\"\s+\"?(.+(?=\")|.+).*$/",$inbox_ary[0],$regs)) {
                $flag = $regs[1];
                $mbx = trim($regs[3]);
                if (substr($mbx, -1) == $delimiter) {
                    $mbx = substr($mbx, 0, strlen($mbx) - 1);
                }
                $sorted_lsub_ary[] = array ('mbx' => $mbx, 'flag' => $flag); 
            }
            */
        }
        for ($i = 0; $i < $cnt; $i++) {
            $mbx = $sorted_lsub_ary[$i]['mbx'];
            if ($unseen_notify == 2 && $mbx == 'INBOX' || $unseen_notify == 3 || $move_to_trash && $mbx == $trash_folder) {
                if ($sorted_lsub_ary[$i]['noselect']) {
                    $sorted_lsub_ary[$i]['unseen'] = 0;
                } else {
                    $sorted_lsub_ary[$i]['unseen'] = sqimap_unseen_messages($imap_stream, $mbx);
                }
                if ($unseen_type == 2 || $move_to_trash && $mbx == $trash_folder || $mbx == $trash_folder) {
                    if ($sorted_lsub_ary[$i]['noselect']) {
                        $sorted_lsub_ary[$i]['nummessages'] = 0;
                    } else {
                        $sorted_lsub_ary[$i]['nummessages'] = sqimap_get_num_messages($imap_stream, $mbx);
                    }
                }
            }
        }
        $boxesnew = sqimap_fill_mailbox_tree($sorted_lsub_ary);
        return $boxesnew;
    }
}
/**
 * Renames a mailbox.
 */
function sqimap_mailbox_rename($imap_stream, $old_name, $new_name)
{
    if ($old_name != $new_name) {
        global $delimiter, $imap_server_type, $data_dir, $username;
        if (substr($old_name, -1) == $delimiter) {
            $old_name = substr($old_name, 0, strlen($old_name) - 1);
            $new_name = substr($new_name, 0, strlen($new_name) - 1);
            $postfix = $delimiter;
        } else {
            $postfix = '';
        }
        $boxesall = sqimap_mailbox_list($imap_stream);
        $cmd = 'RENAME ' . sqimap_encode_mailbox_name($old_name) . ' ' . sqimap_encode_mailbox_name($new_name);
        $data = sqimap_run_command($imap_stream, $cmd, true, $response, $message);
        sqimap_unsubscribe($imap_stream, $old_name . $postfix);
        $oldpref = getPref($data_dir, $username, 'thread_' . $old_name . $postfix);
        removePref($data_dir, $username, 'thread_' . $old_name . $postfix);
        sqimap_subscribe($imap_stream, $new_name . $postfix);
        setPref($data_dir, $username, 'thread_' . $new_name . $postfix, $oldpref);
        do_hook_function('rename_or_delete_folder', $args = array($old_name, 'rename', $new_name));
        $l = strlen($old_name) + 1;
        $p = 'unformatted';
        foreach ($boxesall as $box) {
            if (substr($box[$p], 0, $l) == $old_name . $delimiter) {
                $new_sub = $new_name . $delimiter . substr($box[$p], $l);
                if ($imap_server_type == 'cyrus') {
                    $cmd = 'RENAME "' . $box[$p] . '" "' . $new_sub . '"';
                    $data = sqimap_run_command($imap_stream, $cmd, true, $response, $message);
                }
                sqimap_unsubscribe($imap_stream, $box[$p]);
                $oldpref = getPref($data_dir, $username, 'thread_' . $box[$p]);
                removePref($data_dir, $username, 'thread_' . $box[$p]);
                sqimap_subscribe($imap_stream, $new_sub);
                setPref($data_dir, $username, 'thread_' . $new_sub, $oldpref);
                do_hook_function('rename_or_delete_folder', $args = array($box[$p], 'rename', $new_sub));
            }
        }
    }
}