Author: norman
Date: Fri Nov 26 20:32:13 2010
New Revision: 1039553
URL: http://svn.apache.org/viewvc?rev=1039553&view=rev
Log:
Allow the HookReturnCode.DISCONNECT and allow to use bitwise operations to use
something like HookReturnCode.OK | HookReturnCode.DISCONNECT. See PROTOCOLS-14
Modified:
james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/AbstractHookableCmdHandler.java
james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/AuthCmdHandler.java
james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/hook/HookResult.java
james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/hook/HookReturnCode.java
Modified:
james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/AbstractHookableCmdHandler.java
URL:
http://svn.apache.org/viewvc/james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/AbstractHookableCmdHandler.java?rev=1039553&r1=1039552&r2=1039553&view=diff
==============================================================================
---
james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/AbstractHookableCmdHandler.java
(original)
+++
james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/AbstractHookableCmdHandler.java
Fri Nov 26 20:32:13 2010
@@ -97,8 +97,12 @@ public abstract class AbstractHookableCm
}
// call the core cmd if we receive a ok return code of the
hook so no other hooks are executed
- if (hRes.getResult() == HookReturnCode.OK) {
- return doCoreCmd(session, command, parameters);
+ if ((hRes.getResult() & HookReturnCode.OK) ==
HookReturnCode.OK) {
+ SMTPResponse response = doCoreCmd(session, command,
parameters);
+ if ((hRes.getResult() & HookReturnCode.DISCONNECT) ==
HookReturnCode.DISCONNECT) {
+ response.setEndSession(true);
+ }
+ return response;
} else {
SMTPResponse res = calcDefaultSMTPResponse(hRes);
if (res != null) {
@@ -132,27 +136,43 @@ public abstract class AbstractHookableCm
String smtpRetCode = result.getSmtpRetCode();
String smtpDesc = result.getSmtpDescription();
- if (rCode == HookReturnCode.DENY) {
+ if ((rCode &HookReturnCode.DENY) == HookReturnCode.DENY) {
if (smtpRetCode == null)
smtpRetCode = SMTPRetCode.TRANSACTION_FAILED;
if (smtpDesc == null)
smtpDesc = "Email rejected";
- return new SMTPResponse(smtpRetCode, smtpDesc);
+ SMTPResponse response = new SMTPResponse(smtpRetCode,
smtpDesc);
+ if ((rCode & HookReturnCode.DISCONNECT) ==
HookReturnCode.DISCONNECT) {
+ response.setEndSession(true);
+ }
+ return response;
} else if (rCode == HookReturnCode.DENYSOFT) {
if (smtpRetCode == null)
smtpRetCode = SMTPRetCode.LOCAL_ERROR;
if (smtpDesc == null)
smtpDesc = "Temporary problem. Please try again later";
- return new SMTPResponse(smtpRetCode, smtpDesc);
- } else if (rCode == HookReturnCode.OK) {
+ SMTPResponse response = new SMTPResponse(smtpRetCode,
smtpDesc);
+ if ((rCode & HookReturnCode.DISCONNECT) ==
HookReturnCode.DISCONNECT) {
+ response.setEndSession(true);
+ }
+ return response;
+ } else if ((rCode & HookReturnCode.OK) == HookReturnCode.OK) {
if (smtpRetCode == null)
smtpRetCode = SMTPRetCode.MAIL_OK;
if (smtpDesc == null)
smtpDesc = "Command accepted";
- return new SMTPResponse(smtpRetCode, smtpDesc);
+ SMTPResponse response = new SMTPResponse(smtpRetCode,
smtpDesc);
+ if ((rCode & HookReturnCode.DISCONNECT) ==
HookReturnCode.DISCONNECT) {
+ response.setEndSession(true);
+ }
+ return response;
+ } else if ((rCode & HookReturnCode.DISCONNECT) ==
HookReturnCode.DISCONNECT) {
+ SMTPResponse response = new SMTPResponse("");
+ response.setEndSession(true);
+ return response;
} else {
// Return null as default
return null;
Modified:
james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/AuthCmdHandler.java
URL:
http://svn.apache.org/viewvc/james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/AuthCmdHandler.java?rev=1039553&r1=1039552&r2=1039553&view=diff
==============================================================================
---
james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/AuthCmdHandler.java
(original)
+++
james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/AuthCmdHandler.java
Fri Nov 26 20:32:13 2010
@@ -373,27 +373,47 @@ public class AuthCmdHandler
String smtpRetCode = result.getSmtpRetCode();
String smtpDesc = result.getSmtpDescription();
- if (rCode == HookReturnCode.DENY) {
+ if ((rCode & HookReturnCode.DENY) == HookReturnCode.DENY) {
if (smtpRetCode == null)
smtpRetCode = SMTPRetCode.AUTH_FAILED;
if (smtpDesc == null)
smtpDesc = "Authentication Failed";
- return new SMTPResponse(smtpRetCode, smtpDesc);
- } else if (rCode == HookReturnCode.DENYSOFT) {
+ SMTPResponse response = new SMTPResponse(smtpRetCode,
smtpDesc);
+
+ if ((rCode & HookReturnCode.DISCONNECT) ==
HookReturnCode.DISCONNECT) {
+ response.setEndSession(true);
+ }
+ return response;
+ } else if ((rCode & HookReturnCode.DENYSOFT) ==
HookReturnCode.DENYSOFT) {
if (smtpRetCode == null)
smtpRetCode = SMTPRetCode.LOCAL_ERROR;
if (smtpDesc == null)
smtpDesc = "Temporary problem. Please try again later";
- return new SMTPResponse(smtpRetCode, smtpDesc);
- } else if (rCode == HookReturnCode.OK) {
+ SMTPResponse response = new SMTPResponse(smtpRetCode,
smtpDesc);
+
+ if ((rCode & HookReturnCode.DISCONNECT) ==
HookReturnCode.DISCONNECT) {
+ response.setEndSession(true);
+ }
+ return response;
+ } else if ((rCode & HookReturnCode.OK) == HookReturnCode.OK) {
if (smtpRetCode == null)
smtpRetCode = SMTPRetCode.AUTH_OK;
if (smtpDesc == null)
smtpDesc = "Authentication Succesfull";
-
- return new SMTPResponse(smtpRetCode, smtpDesc);
+
+ SMTPResponse response = new SMTPResponse(smtpRetCode,
smtpDesc);
+
+ if ((rCode & HookReturnCode.DISCONNECT) ==
HookReturnCode.DISCONNECT) {
+ response.setEndSession(true);
+ }
+ return response;
+ } else if ((rCode & HookReturnCode.DISCONNECT) ==
HookReturnCode.DISCONNECT) {
+ SMTPResponse response = new SMTPResponse("");
+ response.setEndSession(true);
+
+ return response;
} else {
// Return null as default
return null;
Modified:
james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/hook/HookResult.java
URL:
http://svn.apache.org/viewvc/james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/hook/HookResult.java?rev=1039553&r1=1039552&r2=1039553&view=diff
==============================================================================
---
james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/hook/HookResult.java
(original)
+++
james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/hook/HookResult.java
Fri Nov 26 20:32:13 2010
@@ -23,7 +23,7 @@ package org.apache.james.protocols.smtp.
* Result which get used for hooks
*
*/
-public class HookResult {
+public final class HookResult {
private int result;
private String smtpRetCode;
@@ -32,11 +32,29 @@ public class HookResult {
/**
* Construct new HookResult
*
- * @param result
+ * @param result
* @param smtpRetCode
* @param smtpDescription
*/
public HookResult(int result, String smtpRetCode, CharSequence
smtpDescription) {
+ boolean match = false;
+
+ if ((result & HookReturnCode.DECLINED) == HookReturnCode.DECLINED) {
+ if (match == true) throw new IllegalArgumentException();
+ match = true;
+ }
+ if ((result & HookReturnCode.OK) == HookReturnCode.OK) {
+ if (match == true) throw new IllegalArgumentException();
+ match = true;
+ }
+ if ((result & HookReturnCode.DENY) == HookReturnCode.DENY) {
+ if (match == true) throw new IllegalArgumentException();
+ match = true;
+ }
+ if ((result & HookReturnCode.DENYSOFT) == HookReturnCode.DENYSOFT) {
+ if (match == true) throw new IllegalArgumentException();
+ match = true;
+ }
this.result = result;
this.smtpRetCode = smtpRetCode;
this.smtpDescription = (smtpDescription == null) ? null :
smtpDescription.toString();
@@ -61,6 +79,7 @@ public class HookResult {
this(result,null,null);
}
+
/**
* Return the result
*
Modified:
james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/hook/HookReturnCode.java
URL:
http://svn.apache.org/viewvc/james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/hook/HookReturnCode.java?rev=1039553&r1=1039552&r2=1039553&view=diff
==============================================================================
---
james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/hook/HookReturnCode.java
(original)
+++
james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/hook/HookReturnCode.java
Fri Nov 26 20:32:13 2010
@@ -23,8 +23,9 @@
package org.apache.james.protocols.smtp.hook;
public class HookReturnCode {
- public final static int OK = 0;
- public final static int DENY = 1;
- public final static int DENYSOFT = 2;
- public final static int DECLINED = 3;
+ public final static int OK = 0x1;
+ public final static int DENY = 0x1 << 1;
+ public final static int DENYSOFT = 0x1 << 2;
+ public final static int DECLINED = 0x1 << 3;
+ public final static int DISCONNECT = 0x1 << 4;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]