📄 nntphandler.java
字号:
/*********************************************************************** * Copyright (c) 2000-2004 The Apache Software Foundation. * * All rights reserved. * * ------------------------------------------------------------------- * * Licensed under the Apache License, Version 2.0 (the "License"); you * * may not use this file except in compliance with the License. You * * may obtain a copy of the License at: * * * * http://www.apache.org/licenses/LICENSE-2.0 * * * * Unless required by applicable law or agreed to in writing, software * * distributed under the License is distributed on an "AS IS" BASIS, * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * * implied. See the License for the specific language governing * * permissions and limitations under the License. * ***********************************************************************/package org.apache.james.nntpserver;import org.apache.avalon.cornerstone.services.connection.ConnectionHandler;import org.apache.avalon.excalibur.pool.Poolable;import org.apache.avalon.framework.activity.Disposable;import org.apache.avalon.framework.configuration.Configurable;import org.apache.avalon.framework.configuration.Configuration;import org.apache.avalon.framework.configuration.ConfigurationException;import org.apache.avalon.framework.logger.AbstractLogEnabled;import org.apache.avalon.framework.logger.Logger;import org.apache.james.core.MailHeaders;import org.apache.james.nntpserver.repository.NNTPArticle;import org.apache.james.nntpserver.repository.NNTPGroup;import org.apache.james.nntpserver.repository.NNTPRepository;import org.apache.james.services.UsersRepository;import org.apache.james.services.UsersStore;import org.apache.james.util.CharTerminatedInputStream;import org.apache.james.util.DotStuffingInputStream;import org.apache.james.util.ExtraDotOutputStream;import org.apache.james.util.InternetPrintWriter;import org.apache.james.util.RFC977DateFormat;import org.apache.james.util.RFC2980DateFormat;import org.apache.james.util.SimplifiedDateFormat;import org.apache.james.util.watchdog.Watchdog;import org.apache.james.util.watchdog.WatchdogTarget;import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.ByteArrayInputStream;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.OutputStream;import java.io.OutputStreamWriter;import java.io.PrintWriter;import java.io.SequenceInputStream;import java.net.Socket;import java.text.DateFormat;import java.text.ParseException;import java.util.ArrayList;import java.util.Calendar;import java.util.Date;import java.util.Iterator;import java.util.List;import java.util.Locale;import java.util.StringTokenizer;import javax.mail.MessagingException;/** * The NNTP protocol is defined by RFC 977. * This implementation is based on IETF draft 15, posted on 15th July '2002. * URL: http://www.ietf.org/internet-drafts/draft-ietf-nntpext-base-15.txt * * Common NNTP extensions are in RFC 2980. */public class NNTPHandler extends AbstractLogEnabled implements ConnectionHandler, Poolable { /** * used to calculate DATE from - see 11.3 */ private static final SimplifiedDateFormat DF_RFC977 = new RFC977DateFormat(); /** * Date format for the DATE keyword - see 11.1.1 */ private static final SimplifiedDateFormat DF_RFC2980 = new RFC2980DateFormat(); /** * The UTC offset for this time zone. */ public static final long UTC_OFFSET = Calendar.getInstance().get(Calendar.ZONE_OFFSET); /** * The text string for the NNTP MODE command. */ private final static String COMMAND_MODE = "MODE"; /** * The text string for the NNTP LIST command. */ private final static String COMMAND_LIST = "LIST"; /** * The text string for the NNTP GROUP command. */ private final static String COMMAND_GROUP = "GROUP"; /** * The text string for the NNTP NEXT command. */ private final static String COMMAND_NEXT = "NEXT"; /** * The text string for the NNTP LAST command. */ private final static String COMMAND_LAST = "LAST"; /** * The text string for the NNTP ARTICLE command. */ private final static String COMMAND_ARTICLE = "ARTICLE"; /** * The text string for the NNTP HEAD command. */ private final static String COMMAND_HEAD = "HEAD"; /** * The text string for the NNTP BODY command. */ private final static String COMMAND_BODY = "BODY"; /** * The text string for the NNTP STAT command. */ private final static String COMMAND_STAT = "STAT"; /** * The text string for the NNTP POST command. */ private final static String COMMAND_POST = "POST"; /** * The text string for the NNTP IHAVE command. */ private final static String COMMAND_IHAVE = "IHAVE"; /** * The text string for the NNTP QUIT command. */ private final static String COMMAND_QUIT = "QUIT"; /** * The text string for the NNTP SLAVE command. */ private final static String COMMAND_SLAVE = "SLAVE"; /** * The text string for the NNTP DATE command. */ private final static String COMMAND_DATE = "DATE"; /** * The text string for the NNTP HELP command. */ private final static String COMMAND_HELP = "HELP"; /** * The text string for the NNTP NEWGROUPS command. */ private final static String COMMAND_NEWGROUPS = "NEWGROUPS"; /** * The text string for the NNTP NEWNEWS command. */ private final static String COMMAND_NEWNEWS = "NEWNEWS"; /** * The text string for the NNTP LISTGROUP command. */ private final static String COMMAND_LISTGROUP = "LISTGROUP"; /** * The text string for the NNTP OVER command. */ private final static String COMMAND_OVER = "OVER"; /** * The text string for the NNTP XOVER command. */ private final static String COMMAND_XOVER = "XOVER"; /** * The text string for the NNTP HDR command. */ private final static String COMMAND_HDR = "HDR"; /** * The text string for the NNTP XHDR command. */ private final static String COMMAND_XHDR = "XHDR"; /** * The text string for the NNTP AUTHINFO command. */ private final static String COMMAND_AUTHINFO = "AUTHINFO"; /** * The text string for the NNTP PAT command. */ private final static String COMMAND_PAT = "PAT"; /** * The text string for the NNTP MODE READER parameter. */ private final static String MODE_TYPE_READER = "READER"; /** * The text string for the NNTP MODE STREAM parameter. */ private final static String MODE_TYPE_STREAM = "STREAM"; /** * The text string for the NNTP AUTHINFO USER parameter. */ private final static String AUTHINFO_PARAM_USER = "USER"; /** * The text string for the NNTP AUTHINFO PASS parameter. */ private final static String AUTHINFO_PARAM_PASS = "PASS"; /** * The character array that indicates termination of an NNTP message */ private final static char[] NNTPTerminator = { '\r', '\n', '.', '\r', '\n' }; /** * The thread executing this handler */ private Thread handlerThread; /** * The remote host name obtained by lookup on the socket. */ private String remoteHost; /** * The remote IP address of the socket. */ private String remoteIP; /** * The TCP/IP socket over which the POP3 interaction * is occurring */ private Socket socket; /** * The incoming stream of bytes coming from the socket. */ private InputStream in; /** * The reader associated with incoming characters. */ private BufferedReader reader; /** * The socket's output stream */ private OutputStream outs; /** * The writer to which outgoing messages are written. */ private PrintWriter writer; /** * The current newsgroup. */ private NNTPGroup group; /** * The current newsgroup. */ private int currentArticleNumber = -1; /** * Per-service configuration data that applies to all handlers * associated with the service. */ private NNTPHandlerConfigurationData theConfigData; /** * The user id associated with the NNTP dialogue */ private String user = null; /** * The password associated with the NNTP dialogue */ private String password = null; /** * Whether the user for this session has already authenticated. * Used to optimize authentication checks */ boolean isAlreadyAuthenticated = false; /** * The watchdog being used by this handler to deal with idle timeouts. */ private Watchdog theWatchdog; /** * The watchdog target that idles out this handler. */ private WatchdogTarget theWatchdogTarget = new NNTPWatchdogTarget(); /** * Set the configuration data for the handler * * @param theData configuration data for the handler */ void setConfigurationData(NNTPHandlerConfigurationData theData) { theConfigData = theData; } /** * Set the Watchdog for use by this handler. * * @param theWatchdog the watchdog */ void setWatchdog(Watchdog theWatchdog) { this.theWatchdog = theWatchdog; } /** * Gets the Watchdog Target that should be used by Watchdogs managing * this connection. * * @return the WatchdogTarget */ WatchdogTarget getWatchdogTarget() { return theWatchdogTarget; } /** * Idle out this connection */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -