Examples of HookResult


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

            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

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

     * @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

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

        if (!session.isRelayingAllowed()) {
            String blocklisted = (String) session.getConnectionState().get(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME);
   
            if (blocklisted != null) { // was found in the RBL
                if (blocklistedDetail == null) {
                    return new HookResult(HookReturnCode.DENY,DSNStatus.getStatus(DSNStatus.PERMANENT,
                            DSNStatus.SECURITY_AUTH+ " Rejected: unauthenticated e-mail from " + session.getRemoteIPAddress()
                            + " is restricted.  Contact the postmaster for details.");
                } else {
                    return new HookResult(HookReturnCode.DENY,DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SECURITY_AUTH) + " " + blocklistedDetail);
                }
              
            }
        }
        return new HookResult(HookReturnCode.DECLINED);
    }
View Full Code Here

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

            for (int i = 0; i < count; i++) {
                Hook rawHook = hooks.get(i);
                session.getLogger().debug("executing hook " + rawHook.getClass().getName());
                long start = System.currentTimeMillis();
               
                HookResult hRes = callHook(rawHook, session, parameters);
                long executionTime = System.currentTimeMillis() - start;

                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, executionTime, 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) == HookReturnCode.OK) {
                    final Response response = doCoreCmd(session, command, parameters);
                    if ((hRes.getResult() & HookReturnCode.DISCONNECT) == HookReturnCode.DISCONNECT) {
                        return new Response() {
                           
                            /*
                             * (non-Javadoc)
                             * @see org.apache.james.protocols.api.Response#isEndSession()
View Full Code Here

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

        if (!session.isRelayingAllowed()) {
            String blocklisted = (String) session.getAttachment(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME, State.Connection);
   
            if (blocklisted != null) { // was found in the RBL
                if (blocklistedDetail == null) {
                    return new HookResult(HookReturnCode.DENY,DSNStatus.getStatus(DSNStatus.PERMANENT,
                            DSNStatus.SECURITY_AUTH+ " Rejected: unauthenticated e-mail from " + session.getRemoteAddress().getAddress()
                            + " is restricted.  Contact the postmaster for details.");
                } else {
                    return new HookResult(HookReturnCode.DENY,DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SECURITY_AUTH) + " " + blocklistedDetail);
                }
              
            }
        }
        return HookResult.declined();
View Full Code Here

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

            MailAddress rcpt) {
        SMTPNettySession nSession =(SMTPNettySession) session;
        if (nSession.verifyIdentity()) {
            return super.doRcpt(session, sender, rcpt);
        } else {
            return new HookResult(HookReturnCode.DECLINED);
        }
    }
View Full Code Here

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

                         .append(recipientString);
                session.getLogger().info(infoBuffer.toString());
            }
        } catch (MessagingException me) {
            session.getLogger().error("Unknown error occurred while processing DATA.", me);
            return new HookResult(HookReturnCode.DENYSOFT,DSNStatus.getStatus(DSNStatus.TRANSIENT,DSNStatus.UNDEFINED_STATUS)+" Error processing message.");
        }
        return new HookResult(HookReturnCode.OK, DSNStatus.getStatus(DSNStatus.SUCCESS,DSNStatus.CONTENT_OTHER)+" Message received");
    }
View Full Code Here

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

    /**
     * @see org.apache.james.protocols.smtp.hook.RcptHook#doRcpt(org.apache.james.protocols.smtp.SMTPSession, org.apache.mailet.MailAddress, org.apache.mailet.MailAddress)
     */
    public HookResult doRcpt(SMTPSession session, MailAddress sender, MailAddress rcpt) {
        if (isBlocked(session.getRemoteIPAddress(), session)) {
            return new HookResult(HookReturnCode.DENY);
        } else {
        
            if (spamTrapRecips.contains(rcpt.toString().toLowerCase())){
       
                addIp(session.getRemoteIPAddress(), session);
           
                return new HookResult(HookReturnCode.DENY);
            }
        }
        return new HookResult(HookReturnCode.DECLINED);
    }
View Full Code Here

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

     */
    public HookResult doRcpt(SMTPSession session, MailAddress sender, MailAddress rcpt) {
        if ((session.getRcptCount() + 1) > maxRcpt) {
            session.getLogger().info("Maximum recipients of " + maxRcpt + " reached");
           
            return new HookResult(HookReturnCode.DENY, SMTPRetCode.SYSTEM_STORAGE_ERROR, DSNStatus.getStatus(DSNStatus.NETWORK, DSNStatus.DELIVERY_TOO_MANY_REC)
                    + " Requested action not taken: max recipients reached");
        } else {
            return new HookResult(HookReturnCode.DECLINED);
        }
    }
View Full Code Here

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

                for(int i =0; i < count; i++) {
                    MessageHook rawHandler =  (MessageHook) messageHandlers.get(i);
                    session.getLogger().debug("executing message handler " + rawHandler);

                    long start = System.currentTimeMillis();
                    HookResult hRes = rawHandler.onMessage(session, mail);
                    long executionTime = System.currentTimeMillis() - start;

                    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, executionTime, 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
TOP
Copyright © 2018 www.massapi.com. 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.