📄 smtpserver.java
字号:
if (getLogger().isInfoEnabled()) { getLogger().info("The idle timeout will be reset every " + lengthReset + " bytes."); } heloEhloEnforcement = handlerConfiguration.getChild("heloEhloEnforcement").getValueAsBoolean(true); if (authRequiredString.equals("true")) authRequired = AUTH_REQUIRED; //set the logger ContainerUtil.enableLogging(handlerChain,getLogger()); try { ContainerUtil.service(handlerChain,serviceManager); } catch (ServiceException e) { if (getLogger().isErrorEnabled()) { getLogger().error("Failed to service handlerChain",e); } throw new ConfigurationException("Failed to service handlerChain"); } //read from the XML configuration and create and configure each of the handlers ContainerUtil.configure(handlerChain,handlerConfiguration.getChild("handlerchain")); } else { mailetcontext.setAttribute(Constants.HELLO_NAME, "localhost"); } } /** * @see org.apache.avalon.framework.activity.Initializable#initialize() */ public void initialize() throws Exception { super.initialize(); if (!isEnabled()) { return; } if (connectionLimit != null) { theHandlerPool = new HardResourceLimitingPool(theHandlerFactory, 5, connectionLimit.intValue()); if (getLogger().isDebugEnabled()) { getLogger().debug("Using a bounded pool for SMTP handlers with upper limit " + connectionLimit.intValue()); } } else { // NOTE: The maximum here is not a real maximum. The handler pool will continue to // provide handlers beyond this value. theHandlerPool = new DefaultPool(theHandlerFactory, null, 5, 30); getLogger().debug("Using an unbounded pool for SMTP handlers."); } if (theHandlerPool instanceof LogEnabled) { ((LogEnabled)theHandlerPool).enableLogging(getLogger()); } if (theHandlerPool instanceof Initializable) { ((Initializable)theHandlerPool).initialize(); } theWatchdogFactory = getWatchdogFactory(); } /** * @see org.apache.james.core.AbstractJamesService#getDefaultPort() */ protected int getDefaultPort() { return 25; } /** * @see org.apache.james.core.AbstractJamesService#getServiceType() */ public String getServiceType() { return "SMTP Service"; } /** * @see org.apache.avalon.cornerstone.services.connection.AbstractHandlerFactory#newHandler() */ protected ConnectionHandler newHandler() throws Exception { SMTPHandler theHandler = (SMTPHandler)theHandlerPool.get(); if (getLogger().isDebugEnabled()) { getLogger().debug("Getting SMTPHandler from pool."); } Watchdog theWatchdog = theWatchdogFactory.getWatchdog(theHandler.getWatchdogTarget()); theHandler.setConfigurationData(theConfigData); theHandler.setWatchdog(theWatchdog); //pass the handler chain to every SMTPhandler theHandler.setHandlerChain(handlerChain); return theHandler; } /** * @see org.apache.avalon.cornerstone.services.connection.ConnectionHandlerFactory#releaseConnectionHandler(ConnectionHandler) */ public void releaseConnectionHandler( ConnectionHandler connectionHandler ) { if (!(connectionHandler instanceof SMTPHandler)) { throw new IllegalArgumentException("Attempted to return non-SMTPHandler to pool."); } if (getLogger().isDebugEnabled()) { getLogger().debug("Returning SMTPHandler to pool."); } theHandlerPool.put((Poolable)connectionHandler); } /** * The factory for producing handlers. */ private static class SMTPHandlerFactory implements ObjectFactory { /** * @see org.apache.avalon.excalibur.pool.ObjectFactory#newInstance() */ public Object newInstance() throws Exception { return new SMTPHandler(); } /** * @see org.apache.avalon.excalibur.pool.ObjectFactory#getCreatedClass() */ public Class getCreatedClass() { return SMTPHandler.class; } /** * @see org.apache.avalon.excalibur.pool.ObjectFactory#decommision(Object) */ public void decommission( Object object ) throws Exception { return; } } /** * A class to provide SMTP handler configuration to the handlers */ private class SMTPHandlerConfigurationDataImpl implements SMTPHandlerConfigurationData { /** * @see org.apache.james.smtpserver.SMTPHandlerConfigurationData#getHelloName() */ public String getHelloName() { return SMTPServer.this.helloName; } /** * @see org.apache.james.smtpserver.SMTPHandlerConfigurationData#getResetLength() */ public int getResetLength() { return SMTPServer.this.lengthReset; } /** * @see org.apache.james.smtpserver.SMTPHandlerConfigurationData#getMaxMessageSize() */ public long getMaxMessageSize() { return SMTPServer.this.maxMessageSize; } /** * @see org.apache.james.smtpserver.SMTPHandlerConfigurationData#isAuthRequired(String) */ public boolean isRelayingAllowed(String remoteIP) { boolean relayingAllowed = false; if (authorizedNetworks != null) { relayingAllowed = SMTPServer.this.authorizedNetworks.matchInetNetwork(remoteIP); } return relayingAllowed; } /** * @see org.apache.james.smtpserver.SMTPHandlerConfigurationData#isAuthRequired(String) */ public boolean isAuthRequired(String remoteIP) { if (SMTPServer.this.authRequired == AUTH_ANNOUNCE) return true; boolean authRequired = SMTPServer.this.authRequired != AUTH_DISABLED; if (authorizedNetworks != null) { authRequired = authRequired && !SMTPServer.this.authorizedNetworks.matchInetNetwork(remoteIP); } return authRequired; } /** * @see org.apache.james.smtpserver.SMTPHandlerConfigurationData#isAuthRequired() */ public boolean isAuthRequired() { return SMTPServer.this.authRequired != AUTH_DISABLED; } /** * @see org.apache.james.smtpserver.SMTPHandlerConfigurationData#isVerifyIdentity() */ public boolean isVerifyIdentity() { return SMTPServer.this.verifyIdentity; } /** * @see org.apache.james.smtpserver.SMTPHandlerConfigurationData#getMailServer() */ public MailServer getMailServer() { return SMTPServer.this.mailServer; } /** * @see org.apache.james.smtpserver.SMTPHandlerConfigurationData#getUsersRepository() */ public UsersRepository getUsersRepository() { return SMTPServer.this.users; } /** * @see org.apache.james.smtpserver.SMTPHandlerConfigurationData#useHeloEnforcement() */ public boolean useHeloEhloEnforcement() { return SMTPServer.this.heloEhloEnforcement; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -