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

📄 nntphandler.java

📁 邮件服务器系统 支持SMTP POP3 是著名的Apache写 有一定的参考价值
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            if (spaceIndex >= 0) {                wildmat = argument.substring(0, spaceIndex);                argument = argument.substring(spaceIndex + 1);            } else {                getLogger().error("NEWNEWS had an invalid argument");                writeLoggedFlushedResponse("501 Syntax error");                return;            }        } else {            getLogger().error("NEWNEWS had a null argument");            writeLoggedFlushedResponse("501 Syntax error");            return;        }        Date theDate = null;        try {            theDate = getDateFrom(argument);        } catch (NNTPException nntpe) {            getLogger().error("NEWNEWS had an invalid argument", nntpe);            writeLoggedFlushedResponse("501 Syntax error");            return;        }        writeLoggedFlushedResponse("230 list of new articles by message-id follows");        Iterator groupIter = theConfigData.getNNTPRepository().getMatchedGroups(wildmat);        while ( groupIter.hasNext() ) {            Iterator articleIter = ((NNTPGroup)(groupIter.next())).getArticlesSince(theDate);            while (articleIter.hasNext()) {                StringBuffer iterBuffer =                    new StringBuffer(64)                        .append(((NNTPArticle)articleIter.next()).getUniqueID());                writeLoggedResponse(iterBuffer.toString());            }        }        writeLoggedFlushedResponse(".");    }    /**     * Lists the groups added since the date passed in as     * an argument.     *     * @param argument the argument passed in with the NEWGROUPS command.     *                 Should be a date.     */    private void doNEWGROUPS(String argument) {        // see section 11.3        // both draft-ietf-nntpext-base-15.txt and rfc977 have only group names         // in response lines, but INN sends         // '<group name> <last article> <first article> <posting allowed>'        // NOTE: following INN over either document.        //        // TODO: Check this.  Audit at http://www.academ.com/pipermail/ietf-nntp/2001-July/002185.html        // doesn't mention the supposed discrepancy.  Consider changing code to         // be in line with spec.        Date theDate = null;        try {            theDate = getDateFrom(argument);        } catch (NNTPException nntpe) {            getLogger().error("NEWGROUPS had an invalid argument", nntpe);            writeLoggedFlushedResponse("501 Syntax error");            return;        }        Iterator iter = theConfigData.getNNTPRepository().getGroupsSince(theDate);        writeLoggedFlushedResponse("231 list of new newsgroups follows");        while ( iter.hasNext() ) {            NNTPGroup currentGroup = (NNTPGroup)iter.next();            StringBuffer iterBuffer =                new StringBuffer(128)                    .append(currentGroup.getName())                    .append(" ")                    .append(currentGroup.getLastArticleNumber())                    .append(" ")                    .append(currentGroup.getFirstArticleNumber())                    .append(" ")                    .append((currentGroup.isPostAllowed()?"y":"n"));            writeLoggedResponse(iterBuffer.toString());        }        writeLoggedFlushedResponse(".");    }    /**     * Lists the help text for the service.     *     * @param argument the argument passed in with the HELP command.     */    private void doHELP(String argument) {        writeLoggedResponse("100 Help text follows");        writeLoggedFlushedResponse(".");    }    /**     * Acknowledges a SLAVE command.  No special preference is given     * to slave connections.     *     * @param argument the argument passed in with the SLAVE command.     */    private void doSLAVE(String argument) {        writeLoggedFlushedResponse("202 slave status noted");    }    /**     * Returns the current date according to the news server.     *     * @param argument the argument passed in with the DATE command     */    private void doDATE(String argument) {        Date dt = new Date(System.currentTimeMillis()-UTC_OFFSET);        String dtStr = DF_RFC2980.format(new Date(dt.getTime() - UTC_OFFSET));        writeLoggedFlushedResponse("111 " + dtStr);    }    /**     * Quits the transaction.     *     * @param argument the argument passed in with the QUIT command     */    private void doQUIT(String argument) {        writeLoggedFlushedResponse("205 closing connection");    }    /**     * Handles the LIST command and its assorted extensions.     *     * @param argument the argument passed in with the LIST command.     */    private void doLIST(String argument) {        // see section 9.4.1        String wildmat = "*";        boolean isListNewsgroups = false;        String extension = argument;        if (argument != null) {            int spaceIndex = argument.indexOf(" ");            if (spaceIndex >= 0) {                wildmat = argument.substring(spaceIndex + 1);                extension = argument.substring(0, spaceIndex);            }            extension = extension.toUpperCase(Locale.US);        }        if (extension != null) {            if (extension.equals("ACTIVE")) {                isListNewsgroups = false;            } else if (extension.equals("NEWSGROUPS") ) {                isListNewsgroups = true;            } else if (extension.equals("EXTENSIONS") ) {                doLISTEXTENSIONS();                return;            } else if (extension.equals("OVERVIEW.FMT") ) {                doLISTOVERVIEWFMT();                return;            } else if (extension.equals("ACTIVE.TIMES") ) {                // not supported - 9.4.2.1, 9.4.3.1, 9.4.4.1                writeLoggedFlushedResponse("503 program error, function not performed");                return;            } else if (extension.equals("DISTRIBUTIONS") ) {                // not supported - 9.4.2.1, 9.4.3.1, 9.4.4.1                writeLoggedFlushedResponse("503 program error, function not performed");                return;            } else if (extension.equals("DISTRIB.PATS") ) {                // not supported - 9.4.2.1, 9.4.3.1, 9.4.4.1                writeLoggedFlushedResponse("503 program error, function not performed");                return;            } else {                writeLoggedFlushedResponse("501 Syntax error");                return;            }        }        Iterator iter = theConfigData.getNNTPRepository().getMatchedGroups(wildmat);        writeLoggedFlushedResponse("215 list of newsgroups follows");        while ( iter.hasNext() ) {            NNTPGroup theGroup = (NNTPGroup)iter.next();            if (isListNewsgroups) {                writeLoggedResponse(theGroup.getListNewsgroupsFormat());            } else {                writeLoggedResponse(theGroup.getListFormat());            }        }        writeLoggedFlushedResponse(".");    }    /**     * Informs the server that the client has an article with the specified     * message-ID.     *     * @param id the message id     */    private void doIHAVE(String id) {        // see section 9.3.2.1        if (!isMessageId(id)) {            writeLoggedFlushedResponse("501 command syntax error");            return;        }        NNTPArticle article = theConfigData.getNNTPRepository().getArticleFromID(id);        if ( article != null ) {            writeLoggedFlushedResponse("435 article not wanted - do not send it");        } else {            writeLoggedFlushedResponse("335 send article to be transferred. End with <CR-LF>.<CR-LF>");            try {                createArticle();            } catch (RuntimeException e) {                writeLoggedFlushedResponse("436 transfer failed - try again later");                throw e;            }            writeLoggedFlushedResponse("235 article received ok");        }    }    /**     * Posts an article to the news server.     *     * @param argument the argument passed in with the POST command     */    private void doPOST(String argument) {        // see section 9.3.1.1        if ( argument != null ) {            writeLoggedFlushedResponse("501 Syntax error - unexpected parameter");        }        writeLoggedFlushedResponse("340 send article to be posted. End with <CR-LF>.<CR-LF>");        createArticle();        writeLoggedFlushedResponse("240 article received ok");    }    /**     * Executes the STAT command.  Sets the current article pointer,     * returns article information.     *     * @param the argument passed in to the STAT command,     *        which should be an article number or message id.     *        If no parameter is provided, the current selected     *        article is used.     */    private void doSTAT(String param) {        // section 9.2.4        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("223 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("223 ")                                .append(article.getArticleNumber())                                .append(" ")                                .append(articleID);                    writeLoggedFlushedResponse(respBuffer.toString());                }            }        }    }    /**     * Executes the BODY command.  Sets the current article pointer,     * returns article information and body.     *     * @param the argument passed in to the BODY command,     *        which should be an article number or message id.     *        If no parameter is provided, the current selected     *        article is used.     */    private void doBODY(String param) {        // section 9.2.3        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("222 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("222 ")                                .append(article.getArticleNumber())                                .append(" ")                                .append(articleID);                    writeLoggedFlushedResponse(respBuffer.toString());                }            }        }        if (article != null) {            writer.flush();            article.writeBody(new ExtraDotOutputStream(outs));            writeLoggedFlushedResponse(".");

⌨️ 快捷键说明

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