コード例 #1
0
    /**
     * @param int $pageNumber
     * @param string $condition
     * @param FolderCollection $folders
     * @param bool $inHeadersOnly
     * @param Account $account
     * @return WebMailMessageCollection
     */
    function SearchMessages($pageNumber, $condition, &$folders, $inHeadersOnly, &$account)
    {
        $tempstr = '';
        $foldersId = '';
        foreach (array_keys($folders->Instance()) as $key) {
            $folder =& $folders->Get($key);
            $foldersId .= $foldersId == '' ? $folder->IdDb : ',' . $folder->IdDb;
        }
        $filter = '';
        $asc = true;
        $this->_setSortOrder($account->DefaultOrder, $filter, $asc);
        $condition = str_replace('[', '[[]', $condition);
        $condition = $this->_escapeString('%' . $condition . '%');
        if ($inHeadersOnly) {
            if (($pageNumber - 1) * $account->MailsPerPage > 0) {
                $tempstr = ' AND id_msg NOT IN 
								(SELECT TOP %d id_msg FROM %sawm_messages 
								WHERE id_acct = %d AND id_folder_db IN (%s) AND	
								(from_msg LIKE %s OR to_msg LIKE %s OR cc_msg LIKE %s OR bcc_msg
								LIKE %s OR subject LIKE %s) ORDER BY %s %s)';
                $tempstr = sprintf($tempstr, ($pageNumber - 1) * $account->MailsPerPage, $this->_settings->DbPrefix, $account->Id, $foldersId, $condition, $condition, $condition, $condition, $condition, $filter, $asc ? 'ASC' : 'DESC');
            }
            $sql = 'SELECT TOP %d id_msg, %s AS uid, id_folder_db, from_msg, to_msg, cc_msg,
							bcc_msg, subject, %s AS nmsg_date, size, priority, x_spam,
							attachments, seen, flagged, deleted, replied, forwarded, grayed
						FROM %sawm_messages
						WHERE id_acct = %d AND id_folder_db IN (%s) AND	
							(from_msg LIKE %s OR to_msg LIKE %s OR cc_msg LIKE %s OR bcc_msg
							LIKE %s OR subject LIKE %s)%s
						ORDER BY %s %s';
            return sprintf($sql, $account->MailsPerPage, $this->_getMsgIdUidFieldName(true, $account->MailProtocol), CDateTime::GetMsSqlDateFormat('msg_date'), $this->_settings->DbPrefix, $account->Id, $foldersId, $condition, $condition, $condition, $condition, $condition, $tempstr, $filter, $asc ? 'ASC' : 'DESC');
        } else {
            if (($pageNumber - 1) * $account->MailsPerPage > 0) {
                $tempstr = ' AND id_msg NOT IN 
							(SELECT TOP %d id_msg FROM %sawm_messages
							WHERE id_acct = %d AND id_folder_db IN (%s) AND	
								(from_msg LIKE %s OR to_msg LIKE %s OR cc_msg LIKE %s OR bcc_msg
								LIKE %s OR subject LIKE %s OR body_text LIKE %s) ORDER BY %s %s)';
                $tempstr = sprintf($tempstr, ($pageNumber - 1) * $account->MailsPerPage, $this->_settings->DbPrefix, $account->Id, $foldersId, $condition, $condition, $condition, $condition, $condition, $condition, $filter, $asc ? 'ASC' : 'DESC');
            }
            $sql = 'SELECT TOP %d id_msg, %s AS uid, id_folder_db, from_msg, to_msg, cc_msg,
							bcc_msg, subject, %s AS nmsg_date, size, priority, x_spam,
							attachments, seen, flagged, deleted, replied, forwarded, grayed
						FROM %sawm_messages
						WHERE id_acct = %d AND id_folder_db IN (%s) AND	
							(from_msg LIKE %s OR to_msg LIKE %s OR cc_msg LIKE %s OR bcc_msg
							LIKE %s OR subject LIKE %s OR body_text LIKE %s)%s
						ORDER BY %s %s';
            return sprintf($sql, $account->MailsPerPage, $this->_getMsgIdUidFieldName(true, $account->MailProtocol), CDateTime::GetMsSqlDateFormat('msg_date'), $this->_settings->DbPrefix, $account->Id, $foldersId, $condition, $condition, $condition, $condition, $condition, $condition, $tempstr, $filter, $asc ? 'ASC' : 'DESC');
        }
    }