Exemplo n.º 1
0
/**
 * Starts the filtering process
 * @param array $hook_args (since 1.5.2) do hook arguments. Is used to check
 * hook name, array key = 0.
 * @access private
 */
function start_filters($hook_args)
{
    global $imapServerAddress, $imapPort, $imap_stream_options, $imap_stream, $imapConnection, $UseSeparateImapConnection, $AllowSpamFilters, $filter_inbox_count, $username;
    // if there were filtering errors previously during
    // this login session, we won't try again
    //
    // (errors that this plugin was able to catch or a "NO"
    // response/failure from IMAP found in the current session,
    // which could have resulted from an attempted filter copy
    // (over quota), in which case execution halts before this
    // plugin can catch the problem -- note, however, that any
    // other IMAP "NO" failure (caused by unrelated actions) at
    // any time during the current session will cause this plugin
    // to effectively shut down)
    //
    sqgetGlobalVar('filters_error', $filters_error, SQ_SESSION, FALSE);
    sqgetGlobalVar('IMAP_FATAL_ERROR_TYPE', $imap_fatal_error, SQ_SESSION, '');
    if ($filters_error || $imap_fatal_error == 'NO') {
        return;
    }
    /**
     * check hook that calls filtering. If filters are called by right_main_after_header,
     * do filtering only when we are in INBOX folder.
     */
    if ($hook_args[0] == 'right_main_after_header' && (sqgetGlobalVar('mailbox', $mailbox, SQ_FORM) && $mailbox != 'INBOX')) {
        return;
    }
    $filters = load_filters();
    // No point running spam filters if there aren't any to run //
    if ($AllowSpamFilters) {
        $spamfilters = load_spam_filters();
        $AllowSpamFilters = false;
        foreach ($spamfilters as $value) {
            if ($value['enabled'] == SMPREF_ON) {
                $AllowSpamFilters = true;
                break;
            }
        }
    }
    // No user filters, and no spam filters, no need to continue //
    if (!$AllowSpamFilters && empty($filters)) {
        return;
    }
    // Detect if we have already connected to IMAP or not.
    // Also check if we are forced to use a separate IMAP connection
    if (!isset($imap_stream) && !isset($imapConnection) || $UseSeparateImapConnection) {
        $stream = sqimap_login($username, false, $imapServerAddress, $imapPort, 10, $imap_stream_options);
        $previously_connected = false;
    } else {
        if (isset($imapConnection)) {
            $stream = $imapConnection;
            $previously_connected = true;
        } else {
            $previously_connected = true;
            $stream = $imap_stream;
        }
    }
    if (!isset($filter_inbox_count)) {
        $aStatus = sqimap_status_messages($stream, 'INBOX', array('MESSAGES'));
        if (!empty($aStatus['MESSAGES'])) {
            $filter_inbox_count = $aStatus['MESSAGES'];
        } else {
            $filter_inbox_count = 0;
        }
    }
    if ($filter_inbox_count > 0) {
        sqimap_mailbox_select($stream, 'INBOX');
        // Filter spam from inbox before we sort them into folders
        if ($AllowSpamFilters) {
            spam_filters($stream);
        }
        // Sort into folders
        user_filters($stream);
    }
    if (!$previously_connected) {
        sqimap_logout($stream);
    }
}
Exemplo n.º 2
0
/**
 * FIXME: Undocumented function
 * @access private
 */
function start_filters()
{
    global $mailbox, $imapServerAddress, $imapPort, $imap, $imap_general, $filters, $imap_stream, $imapConnection, $UseSeparateImapConnection, $AllowSpamFilters;
    sqgetGlobalVar('username', $username, SQ_SESSION);
    sqgetGlobalVar('key', $key, SQ_COOKIE);
    $filters = load_filters();
    // No point running spam filters if there aren't any to run //
    if ($AllowSpamFilters) {
        $spamfilters = load_spam_filters();
        $AllowSpamFilters = false;
        foreach ($spamfilters as $filterkey => $value) {
            if ($value['enabled'] == SMPREF_ON) {
                $AllowSpamFilters = true;
                break;
            }
        }
    }
    // No user filters, and no spam filters, no need to continue //
    if (!$AllowSpamFilters && empty($filters)) {
        return;
    }
    // Detect if we have already connected to IMAP or not.
    // Also check if we are forced to use a separate IMAP connection
    if (!isset($imap_stream) && !isset($imapConnection) || $UseSeparateImapConnection) {
        $stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10);
        $previously_connected = false;
    } else {
        if (isset($imapConnection)) {
            $stream = $imapConnection;
            $previously_connected = true;
        } else {
            $previously_connected = true;
            $stream = $imap_stream;
        }
    }
    $aStatus = sqimap_status_messages($stream, 'INBOX', array('MESSAGES'));
    if ($aStatus['MESSAGES']) {
        sqimap_mailbox_select($stream, 'INBOX');
        // Filter spam from inbox before we sort them into folders
        if ($AllowSpamFilters) {
            spam_filters($stream);
        }
        // Sort into folders
        user_filters($stream);
    }
    if (!$previously_connected) {
        sqimap_logout($stream);
    }
}
Exemplo n.º 3
0
 private function build_filter_query()
 {
     $filters = user_filters();
     $where = $args = $join = array();
     $where[] = 'CharId  IS NOT NULL';
     if ($this->isFilterEditor()) {
         $join[] = 'INNER JOIN {P2T} p2t ON  p2t.Author=p.CharId';
     }
     if ($this->isFilterCE()) {
         $where[] = 'p.IsCertifiedEditor=1';
     }
     if ($this->isFilterCR()) {
         $where[] = 'p.IsCertifiedReferee=1';
     }
     if ($this->isFilterRegistered()) {
         $join[] = 'INNER JOIN {profile_fields} f ON f.name = \'profile_charid\'';
         $join[] = 'INNER JOIN {profile_values} v ON f.fid=v.fid  AND v.value=p.CharId';
     }
     if ($sstr = $this->getFilterSearch()) {
         $where[] = 'Concat(p.Name," ",p.Surname) LIKE "%%' . $sstr . '%%"';
     }
     $where = !empty($where) ? 'AND ' . implode(' AND ', $where) : '';
     $join = !empty($join) ? ' ' . implode(' ', array_unique($join)) : '';
     return array('where' => $where, 'join' => $join, 'args' => $args);
 }