function sqimap_messages_delete($imap_stream, $start, $end, $mailbox)
{
    global $move_to_trash, $trash_folder, $auto_expunge, $uid_support;
    if ($move_to_trash == true && (sqimap_mailbox_exists($imap_stream, $trash_folder) && $mailbox != $trash_folder)) {
        sqimap_messages_copy($imap_stream, $start, $end, $trash_folder);
    }
    sqimap_messages_flag($imap_stream, $start, $end, "Deleted", true);
}
Ejemplo n.º 2
0
/**
 * Recursively walk a tree of folders to create them under the trash folder.
 */
function walkTreeInPostOrderCreatingFoldersUnderTrash($index, $imap_stream, $tree, $topFolderName)
{
    global $trash_folder, $delimiter;
    $position = strrpos($topFolderName, $delimiter);
    if ($position !== FALSE) {
        $position++;
    }
    $subFolderName = substr($tree[$index]['value'], $position);
    if ($tree[$index]['doIHaveChildren']) {
        sqimap_mailbox_create($imap_stream, $trash_folder . $delimiter . $subFolderName, "");
        $mbx_response = sqimap_mailbox_select($imap_stream, $tree[$index]['value']);
        $messageCount = $mbx_response['EXISTS'];
        if ($messageCount > 0) {
            sqimap_messages_copy($imap_stream, 1, '*', $trash_folder . $delimiter . $subFolderName);
        }
        // after copy close the mailbox to get in unselected state
        sqimap_run_command($imap_stream, 'CLOSE', false, $response, $message);
        for ($j = 0; $j < count($tree[$index]['subNodes']); $j++) {
            walkTreeInPostOrderCreatingFoldersUnderTrash($tree[$index]['subNodes'][$j], $imap_stream, $tree, $topFolderName);
        }
    } else {
        sqimap_mailbox_create($imap_stream, $trash_folder . $delimiter . $subFolderName, '');
        $mbx_response = sqimap_mailbox_select($imap_stream, $tree[$index]['value']);
        $messageCount = $mbx_response['EXISTS'];
        if ($messageCount > 0) {
            sqimap_messages_copy($imap_stream, 1, '*', $trash_folder . $delimiter . $subFolderName);
        }
        // after copy close the mailbox to get in unselected state
        sqimap_run_command($imap_stream, 'CLOSE', false, $response, $message);
    }
}
Ejemplo n.º 3
0
/**
 * Deletes specified messages and moves them to trash if possible
 * Obsolete
 */
function sqimap_messages_delete($imap_stream, $start, $end, $mailbox)
{
    global $move_to_trash, $trash_folder, $auto_expunge, $uid_support;
    if ($move_to_trash == true && (sqimap_mailbox_exists($imap_stream, $trash_folder) && $mailbox != $trash_folder)) {
        /**
         * turn off internal error handling (fifth argument = false) and
         * ignore copy to trash errors (allows to delete messages when overquota)
         */
        sqimap_messages_copy($imap_stream, $start, $end, $trash_folder, false);
    }
    sqimap_messages_flag($imap_stream, $start, $end, "Deleted", true);
}
Ejemplo n.º 4
0
function delete_move_next_move()
{
    global $imapConnection, $move_id, $targetMailbox, $auto_expunge, $mailbox;
    // Move message
    sqimap_messages_copy($imapConnection, $move_id, $move_id, $targetMailbox);
    sqimap_messages_flag($imapConnection, $move_id, $move_id, "Deleted");
    if ($auto_expunge == true) {
        sqimap_mailbox_expunge($imapConnection, $mailbox, true);
    }
}
Ejemplo n.º 5
0
function delete_move_next_move()
{
    global $imapConnection, $mailbox, $auto_expunge, $lastTargetMailbox;
    sqgetGlobalVar('move_id', $move_id, SQ_POST);
    sqgetGlobalVar('mailbox', $mailbox, SQ_FORM);
    sqgetGlobalVar('targetMailbox', $targetMailbox, SQ_POST);
    // Move message
    sqimap_messages_copy($imapConnection, $move_id, $move_id, $targetMailbox);
    sqimap_messages_flag($imapConnection, $move_id, $move_id, 'Deleted', true);
    if ($auto_expunge) {
        delete_move_expunge_from_all($move_id);
        // sqimap_mailbox_expunge($imapConnection, $mailbox, true);
    }
    if ($targetMailbox != $lastTargetMailbox) {
        $lastTargetMailbox = $targetMailbox;
        sqsession_register($lastTargetMailbox, 'lastTargetMailbox');
    }
}
Ejemplo n.º 6
0
function walkTreeInPostOrderCreatingFoldersUnderTrash($index, $imap_stream, $tree, $topFolderName)
{
    global $trash_folder, $delimiter;
    $position = strrpos($topFolderName, $delimiter) + 1;
    $subFolderName = substr($tree[$index]['value'], $position);
    if ($tree[$index]['doIHaveChildren']) {
        sqimap_mailbox_create($imap_stream, $trash_folder . $delimiter . $subFolderName, "");
        $mbx_response = sqimap_mailbox_select($imap_stream, $tree[$index]['value']);
        $messageCount = $mbx_response['EXISTS'];
        if ($messageCount > 0) {
            sqimap_messages_copy($imap_stream, 1, '*', $trash_folder . $delimiter . $subFolderName);
        }
        for ($j = 0; $j < count($tree[$index]['subNodes']); $j++) {
            walkTreeInPostOrderCreatingFoldersUnderTrash($tree[$index]['subNodes'][$j], $imap_stream, $tree, $topFolderName);
        }
    } else {
        sqimap_mailbox_create($imap_stream, $trash_folder . $delimiter . $subFolderName, '');
        $mbx_response = sqimap_mailbox_select($imap_stream, $tree[$index]['value']);
        $messageCount = $mbx_response['EXISTS'];
        if ($messageCount > 0) {
            sqimap_messages_copy($imap_stream, 1, '*', $trash_folder . $delimiter . $subFolderName);
        }
    }
}
Ejemplo n.º 7
0
/**
 * FIXME: Undocumented function
 * @access private
 */
function spam_filters($imap_stream)
{
    global $data_dir, $username, $uid_support;
    global $SpamFilters_YourHop;
    global $SpamFilters_DNScache;
    global $SpamFilters_SharedCache;
    global $SpamFilters_BulkQuery;
    $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
    $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
    $filters = load_spam_filters();
    if ($SpamFilters_SharedCache) {
        filters_LoadCache();
    }
    $run = 0;
    foreach ($filters as $Key => $Value) {
        if ($Value['enabled']) {
            $run++;
        }
    }
    // short-circuit
    if ($run == 0) {
        return;
    }
    sqimap_mailbox_select($imap_stream, 'INBOX');
    // Ask for a big list of all "Received" headers in the inbox with
    // flags for each message.  Kinda big.
    if ($filters_spam_scan != 'new') {
        $read = sqimap_run_command($imap_stream, 'FETCH 1:* (FLAGS BODY.PEEK[HEADER.FIELDS ' . '(RECEIVED)])', true, $response, $message, $uid_support);
    } else {
        $read = sqimap_run_command($imap_stream, 'SEARCH UNSEEN', true, $response, $message, $uid_support);
        if ($response != 'OK' || trim($read[0]) == '* SEARCH') {
            $read = sqimap_run_command($imap_stream, 'FETCH 1:* (FLAGS BODY.PEEK[HEADER.FIELDS ' . '(RECEIVED)])', true, $response, $message, $uid_support);
        } else {
            if (isset($read[0])) {
                if (preg_match("/^\\* SEARCH (.+)\$/", $read[0], $regs)) {
                    $search_array = preg_split("/ /", trim($regs[1]));
                }
            }
            $msgs_str = sqimap_message_list_squisher($search_array);
            $imap_query = 'FETCH ' . $msgs_str;
            $imap_query .= ' (FLAGS BODY.PEEK[HEADER.FIELDS ';
            $imap_query .= '(RECEIVED)])';
            $read = sqimap_run_command($imap_stream, $imap_query, true, $response, $message, $uid_support);
        }
    }
    if (isset($response) && $response != 'OK') {
        return;
    }
    if (strlen($SpamFilters_BulkQuery) > 0) {
        filters_bulkquery($filters_spam_scan, $filters, $read);
    }
    $i = 0;
    while ($i < count($read)) {
        // EIMS will give funky results
        $Chunks = explode(' ', $read[$i]);
        if ($Chunks[0] != '*') {
            $i++;
            continue;
        }
        $MsgNum = $Chunks[1];
        $IPs = array();
        $i++;
        $IsSpam = 0;
        // Look through all of the Received headers for IP addresses
        // Stop when I get ")" on a line
        // Stop if I get "*" on a line (don't advance)
        // and above all, stop if $i is bigger than the total # of lines
        while ($i < count($read) && ($read[$i][0] != ')' && $read[$i][0] != '*' && $read[$i][0] != "\n") && !$IsSpam) {
            // Check to see if this line is the right "Received from" line
            // to check
            if (is_int(strpos($read[$i], $SpamFilters_YourHop))) {
                // short-circuit and skip work if we don't scan this one
                $read[$i] = ereg_replace('[^0-9\\.]', ' ', $read[$i]);
                $elements = explode(' ', $read[$i]);
                foreach ($elements as $value) {
                    if ($value != '' && ereg('[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}', $value, $regs)) {
                        $Chunks = explode('.', $value);
                        if (filters_spam_check_site($Chunks[0], $Chunks[1], $Chunks[2], $Chunks[3], $filters)) {
                            $IsSpam++;
                            break;
                            // no sense in checking more IPs
                        }
                        // If we've checked one IP and YourHop is
                        // just a space
                        if ($SpamFilters_YourHop == ' ') {
                            break;
                            // don't check any more
                        }
                    }
                }
            }
            $i++;
        }
        // Lookie!  It's spam!  Yum!
        if ($IsSpam) {
            if (sqimap_mailbox_exists($imap_stream, $filters_spam_folder)) {
                // check if message copy was successful
                if (sqimap_messages_copy($imap_stream, $MsgNum, $MsgNum, $filters_spam_folder, false)) {
                    sqimap_messages_flag($imap_stream, $MsgNum, $MsgNum, 'Deleted', false);
                }
            }
        } else {
        }
    }
    sqimap_mailbox_expunge($imap_stream, 'INBOX');
    if ($SpamFilters_SharedCache) {
        filters_SaveCache();
    } else {
        sqsession_register($SpamFilters_DNScache, 'SpamFilters_DNScache');
    }
}