You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ba...@apache.org on 2007/01/02 23:42:18 UTC
svn commit: r491953 - in /james/server/sandbox/handlerapi-experiment: ./
src/java/org/apache/james/smtpserver/core/
Author: bago
Date: Tue Jan 2 14:42:17 2007
New Revision: 491953
URL: http://svn.apache.org/viewvc?view=rev&rev=491953
Log:
Created a AddDefaultAttributesMessageHook and moved there some specific MailImpl attribute additions.
Added AddDefaultAttributesMessageHook as a default MessageHook in corecommandhandlers.
Added:
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/AddDefaultAttributesMessageHook.java (with props)
Modified:
james/server/sandbox/handlerapi-experiment/TODO
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/CoreCmdHandlerLoader.java
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/DataCmdHandler.java
Modified: james/server/sandbox/handlerapi-experiment/TODO
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/TODO?view=diff&rev=491953&r1=491952&r2=491953
==============================================================================
--- james/server/sandbox/handlerapi-experiment/TODO (original)
+++ james/server/sandbox/handlerapi-experiment/TODO Tue Jan 2 14:42:17 2007
@@ -8,4 +8,3 @@
- The AuthHook define a way to hook plain text user-pass tuple: this mean this won't work as soon as we'll try to implement another SASL mechanism: this is a common issue with POP3 APOP and IMAP SALS auth.
- Decide what to do with services and DI (logging and more).
- SenderAuthIdentifyVerificationRcptHook use session.getConfigurationData().isVerifyIdentity() to decide wether to enable itself or not: isn't it better to add the handler to the config and commenting/uncommenting the handler already do the trick? If so we shoudl simply remove that configuration and remove the check in the code.
-- DataCmdHandler.mailPostProcessor could be moved to a MessageHandler added by default as the first core handler.
Added: james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/AddDefaultAttributesMessageHook.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/AddDefaultAttributesMessageHook.java?view=auto&rev=491953
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/AddDefaultAttributesMessageHook.java (added)
+++ james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/AddDefaultAttributesMessageHook.java Tue Jan 2 14:42:17 2007
@@ -0,0 +1,60 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you 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.smtpserver.core;
+
+import org.apache.james.core.MailImpl;
+import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.smtpserver.hook.HookResult;
+import org.apache.james.smtpserver.hook.HookReturnCode;
+import org.apache.james.smtpserver.hook.MessageHook;
+import org.apache.mailet.Mail;
+
+/**
+ * This hook adds the default attributes to the just created Mail
+ */
+public class AddDefaultAttributesMessageHook implements MessageHook {
+
+ /**
+ * The mail attribute holding the SMTP AUTH user name, if any.
+ */
+ private final static String SMTP_AUTH_USER_ATTRIBUTE_NAME = "org.apache.james.SMTPAuthUser";
+
+ /**
+ * The mail attribute which get set if the client is allowed to relay
+ */
+ private final static String SMTP_AUTH_NETWORK_NAME = "org.apache.james.SMTPIsAuthNetwork";
+
+
+ public HookResult onMessage(SMTPSession session, Mail mail) {
+ if (mail instanceof MailImpl) {
+
+ ((MailImpl) mail).setRemoteHost(session.getRemoteHost());
+ ((MailImpl) mail).setRemoteAddr(session.getRemoteIPAddress());
+ if (session.getUser() != null) {
+ mail.setAttribute(SMTP_AUTH_USER_ATTRIBUTE_NAME, session.getUser());
+ }
+
+ if (session.isRelayingAllowed()) {
+ mail.setAttribute(SMTP_AUTH_NETWORK_NAME,"true");
+ }
+ }
+ return new HookResult(HookReturnCode.DECLINED);
+ }
+
+}
Propchange: james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/AddDefaultAttributesMessageHook.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/CoreCmdHandlerLoader.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/CoreCmdHandlerLoader.java?view=diff&rev=491953&r1=491952&r2=491953
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/CoreCmdHandlerLoader.java (original)
+++ james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/CoreCmdHandlerLoader.java Tue Jan 2 14:42:17 2007
@@ -44,6 +44,7 @@
private final Object RSETCMDHANDLER = RsetCmdHandler.class.getName();
private final Object VRFYCMDHANDLER = VrfyCmdHandler.class.getName();
private final Object WELCOMEMESSAGEHANDLER = WelcomeMessageHandler.class.getName();
+ private final Object ADDDEFAULTATTRIBUTESHANDLER = AddDefaultAttributesMessageHook.class.getClass();
private final Object SENDMAILHANDLER = SendMailHandler.class.getName();
private final Object USERSREPOSITORYAUTHHANDLER = UsersRepositoryAuthHook.class.getName();
private final Object POSTMASTERABUSEHOOK = PostmasterAbuseRcptHook.class.getName();
@@ -58,6 +59,7 @@
// Insert the basecommands in the Map
commands.add(WELCOMEMESSAGEHANDLER);
+ commands.add(ADDDEFAULTATTRIBUTESHANDLER);
commands.add(SENDMAILHANDLER);
commands.add(AUTHCMDHANDLER);
commands.add(DATACMDHANDLER);
Modified: james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/DataCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/DataCmdHandler.java?view=diff&rev=491953&r1=491952&r2=491953
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/DataCmdHandler.java (original)
+++ james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/DataCmdHandler.java Tue Jan 2 14:42:17 2007
@@ -163,16 +163,6 @@
// Keys used to store/lookup data in the internal state hash map
- /**
- * The mail attribute holding the SMTP AUTH user name, if any.
- */
- private final static String SMTP_AUTH_USER_ATTRIBUTE_NAME = "org.apache.james.SMTPAuthUser";
-
- /**
- * The mail attribute which get set if the client is allowed to relay
- */
- private final static String SMTP_AUTH_NETWORK_NAME = "org.apache.james.SMTPIsAuthNetwork";
-
private List messageHandlers;
/**
@@ -352,15 +342,6 @@
* @param mail
*/
private void mailPostProcessor(SMTPSession session, MailImpl mail) {
- mail.setRemoteHost(session.getRemoteHost());
- mail.setRemoteAddr(session.getRemoteIPAddress());
- if (session.getUser() != null) {
- mail.setAttribute(SMTP_AUTH_USER_ATTRIBUTE_NAME, session.getUser());
- }
-
- if (session.isRelayingAllowed()) {
- mail.setAttribute(SMTP_AUTH_NETWORK_NAME,"true");
- }
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org