Package org.apache.james.protocols.smtp.hook

Examples of org.apache.james.protocols.smtp.hook.HookResult


       
        if (!session.isRelayingAllowed()) {
            if (isValidRecipient(session, rcpt) == false) {
                //user not exist
                session.getLogger().info("Rejected message. Unknown user: " + rcpt.toString());
                return new HookResult(HookReturnCode.DENY,SMTPRetCode.TRANSACTION_FAILED, DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.ADDRESS_MAILBOX) + " Unknown user: " + rcpt.toString());
            }
        } else {
            session.getLogger().debug("Sender allowed");
        }
        return new HookResult(HookReturnCode.DECLINED);
    }
View Full Code Here


            try {
                int count = messageHandlers.size();
                for(int i =0; i < count; i++) {
                    Object rawHandler =  messageHandlers.get(i);
                    session.getLogger().debug("executing message handler " + rawHandler);
                    HookResult hRes = ((MessageHook)rawHandler).onMessage(session, mail);
                   
                    if (rHooks != null) {
                        for (int i2 = 0; i2 < rHooks.size(); i2++) {
                            Object rHook = rHooks.get(i2);
                            session.getLogger().debug("executing hook " + rHook);
                            hRes = ((HookResultHook) rHook).onHookResult(session, hRes, rawHandler);
                        }
                    }
                   
                    SMTPResponse response = AbstractHookableCmdHandler.calcDefaultSMTPResponse(hRes);
                   
                    //if the response is received, stop processing of command handlers
                    if(response != null) {
                        session.writeResponse(response);
                        match = true;
                        break;
                    }
                }
                if (match == false) {
                    // Not queue the message!
                    SMTPResponse response = AbstractHookableCmdHandler.calcDefaultSMTPResponse(new HookResult(HookReturnCode.DENY));
                    session.writeResponse(response);
                   
                }
            } finally {
              
View Full Code Here

        if (hooks != null) {
            int count = hooks.size();
            for (int i = 0; i < count; i++) {
                Hook rawHook = hooks.get(i);
                session.getLogger().debug("executing hook " + rawHook.getClass().getName());
                HookResult hRes = callHook(rawHook, session, parameters);
                if (rHooks != null) {
                    for (int i2 = 0; i2 < rHooks.size(); i2++) {
                        Object rHook = rHooks.get(i2);
                        session.getLogger().debug("executing hook " + rHook);
                        hRes = ((HookResultHook) rHook).onHookResult(session, hRes, rawHook);
                    }
                }
               
                // 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);
                } else {
                  SMTPResponse res = calcDefaultSMTPResponse(hRes);
                  if (res != null) {
                    return res;
View Full Code Here

    /**
     * @see org.apache.james.protocols.smtp.hook.MailParametersHook#doMailParameter(org.apache.james.protocols.smtp.SMTPSession, java.lang.String, java.lang.String)
     */
    public HookResult doMailParameter(SMTPSession session, String paramName,
            String paramValue) {
        HookResult res = doMailSize(session, paramValue,
                (String) session.getState().get(SMTPSession.SENDER));
        return res;
    }
View Full Code Here

            size = Integer.parseInt(mailOptionValue);
        } catch (NumberFormatException pe) {
            session.getLogger().error("Rejected syntactically incorrect value for SIZE parameter.");
           
            // This is a malformed option value. We return an error
            return new HookResult(HookReturnCode.DENY,
                    SMTPRetCode.SYNTAX_ERROR_ARGUMENTS,
                    DSNStatus.getStatus(DSNStatus.PERMANENT,
                            DSNStatus.DELIVERY_INVALID_ARG)
                            + " Syntactically incorrect value for SIZE parameter");
        }
        if (session.getLogger().isDebugEnabled()) {
            StringBuilder debugBuffer = new StringBuilder(128).append(
                    "MAIL command option SIZE received with value ").append(
                    size).append(".");
            session.getLogger().debug(debugBuffer.toString());
        }
        long maxMessageSize = session.getMaxMessageSize();
        if ((maxMessageSize > 0) && (size > maxMessageSize)) {
            // Let the client know that the size limit has been hit.
            StringBuilder errorBuffer = new StringBuilder(256).append(
                    "Rejected message from ").append(
                    tempSender != null ? tempSender : null).append(
                    " from host ").append(session.getRemoteHost()).append(" (")
                    .append(session.getRemoteIPAddress()).append(") of size ")
                    .append(size).append(
                            " exceeding system maximum message size of ")
                    .append(maxMessageSize).append("based on SIZE option.");
            session.getLogger().error(errorBuffer.toString());

            return new HookResult(HookReturnCode.DENY, SMTPRetCode.QUOTA_EXCEEDED, DSNStatus
                    .getStatus(DSNStatus.PERMANENT,
                            DSNStatus.SYSTEM_MSG_TOO_BIG)
                    + " Message size exceeds fixed maximum message size");
        } else {
            // put the message size in the message state so it can be used
View Full Code Here

     * @see org.apache.james.protocols.smtp.hook.MessageHook#onMessage(org.apache.james.protocols.smtp.SMTPSession, org.apache.james.protocols.smtp.MailEnvelopeImpl)
     */
    public HookResult onMessage(SMTPSession session, MailEnvelope mail) {
        Boolean failed = (Boolean) session.getState().get(MESG_FAILED);
        if (failed != null && failed.booleanValue()) {
            HookResult response = new HookResult(HookReturnCode.DENY, SMTPRetCode.QUOTA_EXCEEDED,DSNStatus.getStatus(DSNStatus.PERMANENT,
                    DSNStatus.SYSTEM_MSG_TOO_BIG) + " Maximum message size exceeded");
 
            StringBuilder errorBuffer = new StringBuilder(256).append(
                    "Rejected message from ").append(
                    session.getState().get(SMTPSession.SENDER).toString())
                    .append(" from host ").append(session.getRemoteHost())
                    .append(" (").append(session.getRemoteIPAddress())
                    .append(") exceeding system maximum message size of ")
                    .append(
                            session.getMaxMessageSize());
            session.getLogger().error(errorBuffer.toString());
            return response;
        } else {
            return new HookResult(HookReturnCode.DECLINED);
        }
    }
View Full Code Here

            int count = hooks.size();
            for (int i = 0; i < count; i++) {
                AuthHook rawHook = hooks.get(i);
                session.getLogger().debug("executing  hook " + rawHook);
               
                HookResult hRes = rawHook.doAuth(session, user, pass);
               
                if (rHooks != null) {
                    for (int i2 = 0; i2 < rHooks.size(); i2++) {
                        Object rHook = rHooks.get(i2);
                        session.getLogger().debug("executing  hook " + rHook);
View Full Code Here

     * @see org.apache.james.protocols.smtp.hook.MailParametersHook#doMailParameter(org.apache.james.protocols.smtp.SMTPSession, java.lang.String, java.lang.String)
     */
    public HookResult doMailParameter(SMTPSession session, String paramName, String paramValue) {
        // Ignore the AUTH command.
        // TODO we should at least check for correct syntax and put the result in session
        return new HookResult(HookReturnCode.DECLINED);
    }
View Full Code Here

         * (non-Javadoc)
         * @see org.apache.james.protocols.lmtp.hook.DeliverToRecipientHook#deliver(org.apache.james.protocols.smtp.SMTPSession, org.apache.james.protocols.smtp.MailAddress, org.apache.james.protocols.smtp.MailEnvelope)
         */
        public HookResult deliver(SMTPSession session, MailAddress recipient, MailEnvelope envelope) {
            if (RCPT1.equals(recipient.toString())) {
                return new HookResult(HookReturnCode.DENY);
            } else {
                delivered.add(envelope);
                return new HookResult(HookReturnCode.OK);
            }
        }
View Full Code Here

    @Test
    public void testHeloHookPermanentError() throws Exception {
        HeloHook hook = new HeloHook() {

            public HookResult doHelo(SMTPSession session, String helo) {
                return new HookResult(HookReturnCode.DENY);
            }
        };
       
        InetSocketAddress address = new InetSocketAddress("127.0.0.1", TestUtils.getFreePort());
       
View Full Code Here

TOP

Related Classes of org.apache.james.protocols.smtp.hook.HookResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.