Пример #1
0
function sqimap_run_command_list($imap_stream, $query, $handle_errors, &$response, &$message, $unique_id = false)
{
    if ($imap_stream) {
        $sid = sqimap_session_id($unique_id);
        fputs($imap_stream, $sid . ' ' . $query . "\r\n");
        $read = sqimap_read_data_list($imap_stream, $sid, $handle_errors, $response, $message, $query);
        return $read;
    } else {
        echo date("d.m.Y @ G:i:s") . ": ERROR: No available IMAP stream.\n";
        return false;
    }
}
Пример #2
0
function imap_test($imap_stream, $string)
{
    global $default_charset;
    $message = '';
    $responses = array();
    $sid = sqimap_session_id();
    $results = array();
    $query = "{$sid} " . trim($string) . "\r\n";
    print "<tr><td>" . htmlspecialchars($query) . "</td></tr>";
    fputs($imap_stream, $query);
    $response = sqimap_read_data_list($imap_stream, $sid, false, $responses, $message);
    array_push($response, $message);
    return $response;
}
function sqimap_append($imap_stream, $sent_folder, $length)
{
    fputs($imap_stream, sqimap_session_id() . " APPEND \"{$sent_folder}\" (\\Seen) \\{{$length}}\r\n");
    $tmp = fgets($imap_stream, 1024);
}
Пример #4
0
/**
 * 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 \"{$sent_folder}\" (\\Seen) {" . $length . "}\r\n");
    $tmp = fgets($imap_stream, 1024);
    sqimap_append_checkresponse($tmp, $sent_folder);
}
function sqimap_get_headerfield($imap_stream, $field)
{
    $sid = sqimap_session_id(false);
    $results = array();
    $read_list = array();
    $query = "{$sid} FETCH 1:* (UID BODY.PEEK[HEADER.FIELDS ({$field})])\r\n";
    fputs($imap_stream, $query);
    $readin_list = sqimap_read_data_list($imap_stream, $sid, false, $response, $message);
    $i = 0;
    foreach ($readin_list as $r) {
        $r = implode('', $r);
        /* first we unfold the header */
        $r = str_replace(array("\r\n\t", "\r\n\\s"), array('', ''), $r);
        /* 
         * now we can make a new header array with each element representing 
         * a headerline
         */
        $r = explode("\r\n", $r);
        if (!$uid_support) {
            if (!preg_match("/^\\*\\s+([0-9]+)\\s+FETCH/iAU", $r[0], $regs)) {
                set_up_language($squirrelmail_language);
                echo '<br><b><font color=$color[2]>' . _("ERROR : Could not complete request.") . '</b><br>' . _("Unknown response from IMAP server: ") . ' 1.' . $r[0] . "</font><br>\n";
            } else {
                $id = $regs[1];
            }
        } else {
            if (!preg_match("/^\\*\\s+([0-9]+)\\s+FETCH.*UID\\s+([0-9]+)\\s+/iAU", $r[0], $regs)) {
                set_up_language($squirrelmail_language);
                echo '<br><b><font color=$color[2]>' . _("ERROR : Could not complete request.") . '</b><br>' . _("Unknown response from IMAP server: ") . ' 1.' . $r[0] . "</font><br>\n";
            } else {
                $id = $regs[2];
            }
        }
        $field = $r[1];
        $field = substr($field, strlen($field) + 2);
        $result[] = array($id, $field);
    }
    return $result;
}
Пример #6
0
/**
 *  Returns a list of all folders, subscribed or not
 */
function sqimap_mailbox_list_all($imap_stream)
{
    global $list_special_folders_first, $folder_prefix, $delimiter;
    $ssid = sqimap_session_id();
    $lsid = strlen($ssid);
    fputs($imap_stream, $ssid . " LIST \"{$folder_prefix}\" *\r\n");
    $read_ary = sqimap_read_data($imap_stream, $ssid, true, $response, $message);
    $g = 0;
    $phase = 'inbox';
    $fld_pre_length = strlen($folder_prefix);
    for ($i = 0, $cnt = count($read_ary); $i < $cnt; $i++) {
        /* Another workaround for EIMS */
        if (isset($read_ary[$i + 1]) && ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)\$", $read_ary[$i], $regs)) {
            $i++;
            $read_ary[$i] = $regs[1] . '"' . addslashes(trim($read_ary[$i])) . '"' . $regs[2];
        }
        if (substr($read_ary[$i], 0, $lsid) != $ssid) {
            /* Store the raw IMAP reply */
            $boxes[$g]['raw'] = $read_ary[$i];
            /* Count number of delimiters ($delimiter) in folder name */
            $mailbox = find_mailbox_name($read_ary[$i]);
            $dm_count = substr_count($mailbox, $delimiter);
            if (substr($mailbox, -1) == $delimiter) {
                /* If name ends in delimiter - decrement count by one */
                $dm_count--;
            }
            /* Format folder name, but only if it's a INBOX.* or has a parent. */
            $boxesallbyname[$mailbox] = $g;
            $parentfolder = readMailboxParent($mailbox, $delimiter);
            if (eregi('^inbox' . quotemeta($delimiter), $mailbox) || ereg('^' . $folder_prefix, $mailbox) || isset($boxesallbyname[$parentfolder]) && strlen($parentfolder) > 0) {
                if ($dm_count) {
                    $boxes[$g]['formatted'] = str_repeat('&nbsp;&nbsp;', $dm_count);
                } else {
                    $boxes[$g]['formatted'] = '';
                }
                $boxes[$g]['formatted'] .= imap_utf7_decode_local(readShortMailboxName($mailbox, $delimiter));
            } else {
                $boxes[$g]['formatted'] = imap_utf7_decode_local($mailbox);
            }
            $boxes[$g]['unformatted-dm'] = $mailbox;
            if (substr($mailbox, -1) == $delimiter) {
                $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
            }
            $boxes[$g]['unformatted'] = $mailbox;
            $boxes[$g]['unformatted-disp'] = substr($mailbox, $fld_pre_length);
            $boxes[$g]['id'] = $g;
            /* Now lets get the flags for this mailbox */
            $read_mlbx = $read_ary[$i];
            //            $read_mlbx = sqimap_run_command ($imap_stream, "LIST \"\" \"$mailbox\"",
            //                                             true, $response, $message);
            /* Another workaround for EIMS */
            //            if (isset($read_mlbx[1]) &&
            //                ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$", $read_mlbx[0], $regs)) {
            //                $read_mlbx[0] = $regs[1] . '"' . addslashes(trim($read_mlbx[1])) . '"' . $regs[2];
            //            }
            //            echo  $read_mlbx[0] .' raw 2 <br>';
            $flags = substr($read_mlbx, strpos($read_mlbx, '(') + 1);
            $flags = substr($flags, 0, strpos($flags, ')'));
            $flags = str_replace('\\', '', $flags);
            $flags = trim(strtolower($flags));
            if ($flags) {
                $boxes[$g]['flags'] = explode(' ', $flags);
            } else {
                $boxes[$g]['flags'] = array();
            }
        }
        $g++;
    }
    if (is_array($boxes)) {
        sort($boxes);
    }
    return $boxes;
}
Пример #7
0
/**
 * 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);
}
Пример #8
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;
}
Пример #9
0
/**
 * Creates and runs the IMAP command to filter messages
 * @param string $imap_stream TODO: Document this parameter
 * @param string $where Which part of the message to search (TO, CC, SUBJECT, etc...)
 * @param string $what String to search for
 * @param string $where_to Folder it will move to
 * @param string $user_scan Whether to search all or just unseen
 * @param string $should_expunge
 * @access private
 */
function filter_search_and_delete($imap_stream, $where, $what, $where_to, $user_scan, $should_expunge)
{
    global $languages, $squirrelmail_language, $allow_charset_search, $imap_server_type;
    //TODO: make use of new mailbox cache. See mailbox_display.phpinfo
    if (strtolower($where_to) == 'inbox') {
        return array();
    }
    if ($user_scan == 'new') {
        $category = 'UNSEEN';
    } else {
        $category = 'ALL';
    }
    $category .= ' UNDELETED';
    if ($allow_charset_search && isset($languages[$squirrelmail_language]['CHARSET']) && $languages[$squirrelmail_language]['CHARSET']) {
        $search_str = 'SEARCH CHARSET ' . strtoupper($languages[$squirrelmail_language]['CHARSET']) . ' ' . $category;
    } else {
        $search_str = 'SEARCH CHARSET US-ASCII ' . $category;
    }
    if ($where == 'Header') {
        $what = explode(':', $what);
        $where = strtoupper($where);
        $where = trim($where . ' ' . $what[0]);
        $what = addslashes(trim($what[1]));
    }
    // see comments in squirrelmail sqimap_search function
    if ($imap_server_type == 'macosx' || $imap_server_type == 'hmailserver') {
        $search_str .= ' ' . $where . ' ' . $what;
        /* read data back from IMAP */
        $read = sqimap_run_command($imap_stream, $search_str, true, $response, $message, TRUE);
    } else {
        $search_str .= ' ' . $where . ' {' . strlen($what) . "}";
        $sid = sqimap_session_id(true);
        fputs($imap_stream, $sid . ' ' . $search_str . "\r\n");
        $read2 = sqimap_fgets($imap_stream);
        # server should respond with Ready for argument, then we will send search text
        #echo "RR2 $read2<br>";
        fputs($imap_stream, "{$what}\r\n");
        #echo "SS $what<br>";
        $read2 = sqimap_fgets($imap_stream);
        #echo "RR2 $read2<br>";
        $read[] = $read2;
        $read3 = sqimap_fgets($imap_stream);
        #echo "RR3 $read3<br>";
        list($rtag, $response, $message) = explode(' ', $read3, 3);
        ##        $read2 = sqimap_retrieve_imap_response($imap_stream, $sid, true,
        ##              $response, $message, $search_str, false, true, false);
        #echo "RR2 $read2 / RESPONSE $response<br>";
    }
    if (isset($read[0])) {
        $ids = array();
        for ($i = 0, $iCnt = count($read); $i < $iCnt; ++$i) {
            if (preg_match("/^\\* SEARCH (.+)\$/", $read[$i], $regs)) {
                $ids += explode(' ', trim($regs[1]));
            }
        }
        if ($response == 'OK' && count($ids)) {
            if (sqimap_mailbox_exists($imap_stream, $where_to)) {
                if (!sqimap_msgs_list_move($imap_stream, $ids, $where_to, false)) {
                    // if errors occurred, don't try to filter again during this session
                    sqsession_register(TRUE, 'filters_error');
                    global $color;
                    error_box(_("A problem occurred filtering messages. Check filter settings and account quota if applicable. Filtering is disabled for the remainder of this login session."), $color);
                }
                // expunge even in the case of errors, in case some
                // messages were filtered before the error happened
                $should_expunge = true;
            }
        } elseif ($response != 'OK') {
            $query = $search_str . "\r\n" . $what . "\r\n";
            if ($response == 'NO') {
                if (strpos($message, 'BADCHARSET') !== false || strpos($message, 'character') !== false) {
                    sqm_trigger_imap_error('SQM_IMAP_BADCHARSET', $query, $response, $message);
                } else {
                    sqm_trigger_imap_error('SQM_IMAP_ERROR', $query, $response, $message);
                }
            } else {
                sqm_trigger_imap_error('SQM_IMAP_ERROR', $query, $response, $message);
            }
        }
    }
    return $should_expunge;
}