Example #1
0
/**
 * Copy a set of messages ($id) to another mailbox ($mailbox)
 * @param int $imap_stream The resource ID for the IMAP socket
 * @param string $id The list of messages to copy
 * @param string $mailbox The destination to copy to
 * @param bool $handle_errors Show error messages in case of a NO, BAD or BYE response
 * @return bool If the copy completed without errors
 */
function sqimap_msgs_list_copy($imap_stream, $id, $mailbox, $handle_errors = true)
{
    $msgs_id = sqimap_message_list_squisher($id);
    $read = sqimap_run_command($imap_stream, "COPY {$msgs_id} " . sqimap_encode_mailbox_name($mailbox), $handle_errors, $response, $message, TRUE);
    if ($response == 'OK') {
        return true;
    } else {
        return false;
    }
}
/**
 * Deprecated !!!!!!! DO NOT USE THIS, use sqimap_msgs_list_copy instead
 */
function sqimap_messages_copy($imap_stream, $start, $end, $mailbox)
{
    $read = sqimap_run_command($imap_stream, "COPY {$start}:{$end} " . sqimap_encode_mailbox_name($mailbox), true, $response, $message, TRUE);
}
Example #3
0
/**
 * @param stream $imap_stream imap connection resource
 * @param object $mbx_tree
 * @since since 1.5.0
 */
function sqimap_get_status_mbx_tree($imap_stream, &$mbx_tree)
{
    global $unseen_notify, $unseen_type, $trash_folder, $move_to_trash;
    $aMbxs = $aQuery = array();
    sqimap_tree_to_ref_array($mbx_tree, $aMbxs);
    // remove the root node
    array_shift($aMbxs);
    if ($unseen_notify == 3) {
        $cnt = count($aMbxs);
        for ($i = 0; $i < $cnt; ++$i) {
            $oMbx =& $aMbxs[$i];
            if (!$oMbx->is_noselect) {
                $mbx = $oMbx->mailboxname_full;
                if ($unseen_type == 2 || $move_to_trash && $oMbx->mailboxname_full == $trash_folder) {
                    $query = 'STATUS ' . sqimap_encode_mailbox_name($mbx) . ' (MESSAGES UNSEEN RECENT)';
                } else {
                    $query = 'STATUS ' . sqimap_encode_mailbox_name($mbx) . ' (UNSEEN RECENT)';
                }
                sqimap_prepare_pipelined_query($query, $tag, $aQuery, false);
            } else {
                $oMbx->unseen = $oMbx->total = $oMbx->recent = false;
                $tag = false;
            }
            $oMbx->tag = $tag;
            $aMbxs[$i] =& $oMbx;
        }
        // execute all the queries at once
        $aResponse = sqimap_run_pipelined_command($imap_stream, $aQuery, false, $aServerResponse, $aServerMessage);
        $cnt = count($aMbxs);
        for ($i = 0; $i < $cnt; ++$i) {
            $oMbx =& $aMbxs[$i];
            $tag = $oMbx->tag;
            if ($tag && $aServerResponse[$tag] == 'OK') {
                $sResponse = implode('', $aResponse[$tag]);
                if (preg_match('/UNSEEN\\s+([0-9]+)/i', $sResponse, $regs)) {
                    $oMbx->unseen = $regs[1];
                }
                if (preg_match('/MESSAGES\\s+([0-9]+)/i', $sResponse, $regs)) {
                    $oMbx->total = $regs[1];
                }
                if (preg_match('/RECENT\\s+([0-9]+)/i', $sResponse, $regs)) {
                    $oMbx->recent = $regs[1];
                }
            }
            unset($oMbx->tag);
        }
    } else {
        if ($unseen_notify == 2) {
            // INBOX only
            $cnt = count($aMbxs);
            for ($i = 0; $i < $cnt; ++$i) {
                $oMbx =& $aMbxs[$i];
                if (strtoupper($oMbx->mailboxname_full) == 'INBOX' || $move_to_trash && $oMbx->mailboxname_full == $trash_folder) {
                    if ($unseen_type == 2 || $oMbx->mailboxname_full == $trash_folder && $move_to_trash) {
                        $aStatus = sqimap_status_messages($imap_stream, $oMbx->mailboxname_full);
                        $oMbx->unseen = $aStatus['UNSEEN'];
                        $oMbx->total = $aStatus['MESSAGES'];
                        $oMbx->recent = $aStatus['RECENT'];
                    } else {
                        $oMbx->unseen = sqimap_unseen_messages($imap_stream, $oMbx->mailboxname_full);
                    }
                    $aMbxs[$i] =& $oMbx;
                    if (!$move_to_trash && $trash_folder) {
                        break;
                    } else {
                        // trash comes after INBOX
                        if ($oMbx->mailboxname_full == $trash_folder) {
                            break;
                        }
                    }
                }
            }
        }
    }
    $cnt = count($aMbxs);
    for ($i = 0; $i < $cnt; ++$i) {
        $oMbx =& $aMbxs[$i];
        unset($hook_status);
        if (!empty($oMbx->unseen)) {
            $hook_status['UNSEEN'] = $oMbx->unseen;
        }
        if (!empty($oMbx->total)) {
            $hook_status['MESSAGES'] = $oMbx->total;
        }
        if (!empty($oMbx->recent)) {
            $hook_status['RECENT'] = $oMbx->recent;
        }
        if (!empty($hook_status)) {
            $hook_status['MAILBOX'] = $oMbx->mailboxname_full;
            $hook_status['CALLER'] = 'sqimap_get_status_mbx_tree';
            // helps w/ debugging
            do_hook('folder_status', $hook_status);
        }
    }
}
/**
 * Saves a message to a given folder -- used for saving sent messages
 */
function sqimap_append($imap_stream, $sent_folder, $length)
{
    fputs($imap_stream, sqimap_session_id() . ' APPEND ' . sqimap_encode_mailbox_name($sent_folder) . " (\\Seen) \\{{$length}}\r\n");
    $tmp = fgets($imap_stream, 1024);
}
Example #5
0
/**
 * Saves a message to a given folder -- used for saving sent messages
 * @param stream $imap_stream
 * @param string $sent_folder
 * @param $length
 * @return string $sid
 */
function sqimap_append($imap_stream, $sMailbox, $length)
{
    $sid = sqimap_session_id();
    $query = $sid . ' APPEND ' . sqimap_encode_mailbox_name($sMailbox) . " (\\Seen) {" . $length . "}";
    fputs($imap_stream, "{$query}\r\n");
    $tmp = fgets($imap_stream, 1024);
    sqimap_append_checkresponse($tmp, $sMailbox, $sid, $query);
    return $sid;
}