⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nntphandler.java

📁 邮件服务器系统 支持SMTP POP3 是著名的Apache写 有一定的参考价值
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        }    }    /**     * Executes the HEAD command.  Sets the current article pointer,     * returns article information and headers.     *     * @param the argument passed in to the HEAD command,     *        which should be an article number or message id.     *        If no parameter is provided, the current selected     *        article is used.     */    private void doHEAD(String param) {        // section 9.2.2        NNTPArticle article = null;        if (isMessageId(param)) {            article = theConfigData.getNNTPRepository().getArticleFromID(param);            if ( article == null ) {                writeLoggedFlushedResponse("430 no such article");                return;            } else {                StringBuffer respBuffer =                    new StringBuffer(64)                            .append("221 0 ")                            .append(param);                writeLoggedFlushedResponse(respBuffer.toString());            }        } else {            int newArticleNumber = currentArticleNumber;            if ( group == null ) {                writeLoggedFlushedResponse("412 no newsgroup selected");                return;            } else {                if ( param == null ) {                    if ( currentArticleNumber < 0 ) {                        writeLoggedFlushedResponse("420 no current article selected");                        return;                    } else {                        article = group.getArticle(currentArticleNumber);                    }                }                else {                    newArticleNumber = Integer.parseInt(param);                    article = group.getArticle(newArticleNumber);                }                if ( article == null ) {                    writeLoggedFlushedResponse("423 no such article number in this group");                    return;                } else {                    currentArticleNumber = newArticleNumber;                    String articleID = article.getUniqueID();                    if (articleID == null) {                        articleID = "<0>";                    }                    StringBuffer respBuffer =                        new StringBuffer(128)                                .append("221 ")                                .append(article.getArticleNumber())                                .append(" ")                                .append(articleID);                    writeLoggedFlushedResponse(respBuffer.toString());                }            }        }        if (article != null) {            writer.flush();            article.writeHead(new ExtraDotOutputStream(outs));            writeLoggedFlushedResponse(".");        }    }    /**     * Executes the ARTICLE command.  Sets the current article pointer,     * returns article information and contents.     *     * @param the argument passed in to the ARTICLE command,     *        which should be an article number or message id.     *        If no parameter is provided, the current selected     *        article is used.     */    private void doARTICLE(String param) {        // section 9.2.1        NNTPArticle article = null;        if (isMessageId(param)) {            article = theConfigData.getNNTPRepository().getArticleFromID(param);            if ( article == null ) {                writeLoggedFlushedResponse("430 no such article");                return;            } else {                StringBuffer respBuffer =                    new StringBuffer(64)                            .append("220 0 ")                            .append(param);                writeLoggedResponse(respBuffer.toString());            }        } else {            int newArticleNumber = currentArticleNumber;            if ( group == null ) {                writeLoggedFlushedResponse("412 no newsgroup selected");                return;            } else {                if ( param == null ) {                    if ( currentArticleNumber < 0 ) {                        writeLoggedFlushedResponse("420 no current article selected");                        return;                    } else {                        article = group.getArticle(currentArticleNumber);                    }                }                else {                    newArticleNumber = Integer.parseInt(param);                    article = group.getArticle(newArticleNumber);                }                if ( article == null ) {                    writeLoggedFlushedResponse("423 no such article number in this group");                    return;                } else {                    currentArticleNumber = newArticleNumber;                    String articleID = article.getUniqueID();                    if (articleID == null) {                        articleID = "<0>";                    }                    StringBuffer respBuffer =                        new StringBuffer(128)                                .append("220 ")                                .append(article.getArticleNumber())                                .append(" ")                                .append(articleID);                    writeLoggedFlushedResponse(respBuffer.toString());                }            }        }        if (article != null) {            writer.flush();            article.writeArticle(new ExtraDotOutputStream(outs));            writeLoggedFlushedResponse(".");        }    }    /**     * Advances the current article pointer to the next article in the group.     *     * @param argument the argument passed in with the NEXT command     */    private void doNEXT(String argument) {        // section 9.1.1.3.1        if ( argument != null ) {            writeLoggedFlushedResponse("501 Syntax error - unexpected parameter");        } else if ( group == null ) {            writeLoggedFlushedResponse("412 no newsgroup selected");        } else if ( currentArticleNumber < 0 ) {            writeLoggedFlushedResponse("420 no current article has been selected");        } else if ( currentArticleNumber >= group.getLastArticleNumber() ) {            writeLoggedFlushedResponse("421 no next article in this group");        } else {            currentArticleNumber++;            NNTPArticle article = group.getArticle(currentArticleNumber);            StringBuffer respBuffer =                new StringBuffer(64)                        .append("223 ")                        .append(article.getArticleNumber())                        .append(" ")                        .append(article.getUniqueID());            writeLoggedFlushedResponse(respBuffer.toString());        }    }    /**     * Moves the currently selected article pointer to the article     * previous to the currently selected article in the selected group.     *     * @param argument the argument passed in with the LAST command     */    private void doLAST(String argument) {        // section 9.1.1.2.1        if ( argument != null ) {            writeLoggedFlushedResponse("501 Syntax error - unexpected parameter");        } else if ( group == null ) {            writeLoggedFlushedResponse("412 no newsgroup selected");        } else if ( currentArticleNumber < 0 ) {            writeLoggedFlushedResponse("420 no current article has been selected");        } else if ( currentArticleNumber <= group.getFirstArticleNumber() ) {            writeLoggedFlushedResponse("422 no previous article in this group");        } else {            currentArticleNumber--;            NNTPArticle article = group.getArticle(currentArticleNumber);            StringBuffer respBuffer =                new StringBuffer(64)                        .append("223 ")                        .append(article.getArticleNumber())                        .append(" ")                        .append(article.getUniqueID());            writeLoggedFlushedResponse(respBuffer.toString());        }    }    /**     * Selects a group to be the current newsgroup.     *     * @param group the name of the group being selected.     */    private void doGROUP(String groupName) {        if (groupName == null) {            writeLoggedFlushedResponse("501 Syntax error - missing required parameter");            return;        }        NNTPGroup newGroup = theConfigData.getNNTPRepository().getGroup(groupName);        // section 9.1.1.1        if ( newGroup == null ) {            writeLoggedFlushedResponse("411 no such newsgroup");        } else {            group = newGroup;            // if the number of articles in group == 0            // then the server may return this information in 3 ways,             // The clients must honor all those 3 ways.            // our response is:             // highWaterMark == lowWaterMark and number of articles == 0            int articleCount = group.getNumberOfArticles();            int lowWaterMark = group.getFirstArticleNumber();            int highWaterMark = group.getLastArticleNumber();            // Set the current article pointer.  If no            // articles are in the group, the current article            // pointer should be explicitly unset.            if (articleCount != 0) {                currentArticleNumber = lowWaterMark;            } else {                currentArticleNumber = -1;            }            StringBuffer respBuffer =                new StringBuffer(128)                        .append("211 ")                        .append(articleCount)                        .append(" ")                        .append(lowWaterMark)                        .append(" ")                        .append(highWaterMark)                        .append(" ")                        .append(group.getName())                        .append(" group selected");            writeLoggedFlushedResponse(respBuffer.toString());        }    }    /**     * Lists the extensions supported by this news server.     */    private void doLISTEXTENSIONS() {        // 8.1.1        writeLoggedResponse("202 Extensions supported:");        writeLoggedResponse("LISTGROUP");        writeLoggedResponse("AUTHINFO");        writeLoggedResponse("OVER");        writeLoggedResponse("XOVER");        writeLoggedResponse("HDR");        writeLoggedResponse("XHDR");        writeLoggedFlushedResponse(".");    }    /**     * Informs the server that the client is a newsreader.     *     * @param argument the argument passed in with the MODE READER command     */    private void doMODEREADER(String argument) {        // 7.2        writeLoggedFlushedResponse(theConfigData.getNNTPRepository().isReadOnly()                       ? "201 Posting Not Permitted" : "200 Posting Permitted");    }    /**     * Informs the server that the client is a news server.     *     * @param argument the argument passed in with the MODE STREAM command     */    private void doMODESTREAM(String argument) {        // 7.2        writeLoggedFlushedResponse("500 Command not understood");    }    /**     * Gets a listing of article numbers in specified group name     * or in the already selected group if the groupName is null.     *     * @param groupName the name of the group to list     */    private void doLISTGROUP(String groupName) {        // 9.5.1.1.1        if (groupName==null) {            if ( group == null) {                writeLoggedFlushedResponse("412 no news group currently selected");                return;            }        }        else {            group = theConfigData.getNNTPRepository().getGroup(groupName);            if ( group == null ) {                writeLoggedFlushedResponse("411 no such newsgroup");                return;            }        }        if ( group != null ) {            // this.group = group;            // Set the current article pointer.  If no            // articles are in the group, the current article            // pointer should be explicitly unset.            if (group.getNumberOfArticles() > 0) {                currentArticleNumber = group.getFirstArticleNumber();            } else {                currentArticleNumber = -1;            }            writeLoggedFlushedResponse("211 list of article numbers follow");            Iterator iter = group.getArticles();            while (iter.hasNext()) {                NNTPArticle article = (NNTPArticle)iter.next();                writeLoggedResponse(article.getArticleNumber() + "");            }            writeLoggedFlushedResponse(".");        }    }    /**     * Handles the LIST OVERVIEW.FMT command.  Not supported.     */    private void doLISTOVERVIEWFMT() {        // 9.5.3.1.1        writeLoggedFlushedResponse("215 Information follows");        String[] overviewHeaders = theConfigData.getNNTPRepository().getOverviewFormat();        for (int i = 0;  i < overviewHeaders.length; i++) {            writeLoggedResponse(overviewHeaders[i]);        }        writeLoggedFlushedResponse(".");    }    /**     * Handles the PAT command.  Not supported.     *     * @param argument the argument passed in with the PAT command     */    private void doPAT(String argument) {        // 9.5.3.1.1 in draft-12        writeLoggedFlushedResponse("500 Command not recognized");    }    /**     * Get the values of the headers for the selected newsgroup,      * with an optional range modifier.     *     * @param argument the argument passed in with the XHDR command.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -