Examples of SMTPResponse


Examples of org.apache.james.protocols.smtp.SMTPResponse

                .append(" Sender <");
        if (sender != null) {
            responseBuffer.append(sender);
        }
        responseBuffer.append("> OK");
        return new SMTPResponse(SMTPRetCode.MAIL_OK, responseBuffer);
    }
View Full Code Here

Examples of org.apache.james.protocols.smtp.SMTPResponse

                    // Handle the SIZE extension keyword

                    if (paramHooks.containsKey(mailOptionName)) {
                        MailParametersHook hook = paramHooks.get(mailOptionName);
                        SMTPResponse res = calcDefaultSMTPResponse(hook.doMailParameter(session, mailOptionName, mailOptionValue));
                        if (res != null) {
                            return res;
                        }
                    } else {
                        // Unexpected option attached to the Mail command
View Full Code Here

Examples of org.apache.james.protocols.smtp.SMTPResponse

                    session.resetState();
                   
                } catch (MessagingException e) {
                    // TODO probably return a temporary problem
                    session.getLogger().info("Unexpected error handling DATA stream",e);
                    session.writeResponse(new SMTPResponse(SMTPRetCode.LOCAL_ERROR, "Unexpected error handling DATA stream."));
                } finally {
                    LifecycleUtil.dispose(mimeMessageCopyOnWriteProxy);
                    LifecycleUtil.dispose(mmiss);
                    LifecycleUtil.dispose(mail);
                }
   
               
            // DotStuffing.
            } else if (line[0] == 46 && line[1] == 46) {
                out.write(line,1,line.length-1);
            // Standard write
            } else {
                // TODO: maybe we should handle the Header/Body recognition here
                // and if needed let a filter to cache the headers to apply some
                // transformation before writing them to output.
                out.write(line);
            }
            out.flush();
        } catch (IOException e) {
            LifecycleUtil.dispose(mmiss);

            SMTPResponse response = new SMTPResponse(SMTPRetCode.LOCAL_ERROR,DSNStatus.getStatus(DSNStatus.TRANSIENT,
                            DSNStatus.UNDEFINED_STATUS) + " Error processing message: " + e.getMessage());
           
            session.getLogger().error(
                    "Unknown error occurred while processing DATA.", e);
            session.writeResponse(response);
View Full Code Here

Examples of org.apache.james.protocols.smtp.SMTPResponse

                username = recipient.toString();
            } else {
                username = recipient.getLocalPart();
            }

            SMTPResponse response;
           
            try {
               
                MailboxSession mailboxSession = mailboxManager.createSystemSession(username, session.getLogger());
                MailboxPath inbox = MailboxPath.inbox(username);
               
                mailboxManager.startProcessingRequest(mailboxSession);
               
                // create inbox if not exist
                if (mailboxManager.mailboxExists(inbox, mailboxSession) == false) {
                    mailboxManager.createMailbox(inbox, mailboxSession);
                }
                mailboxManager.getMailbox(MailboxPath.inbox(username), mailboxSession).appendMessage(new MimeMessageInputStream(mail.getMessage()), new Date(), mailboxSession, true, null);
                mailboxManager.endProcessingRequest(mailboxSession);
                response = new SMTPResponse(SMTPRetCode.MAIL_OK, DSNStatus.getStatus(DSNStatus.SUCCESS,DSNStatus.CONTENT_OTHER)+" Message received");
            } catch (IOException e) {
                session.getLogger().info("Unexpected error handling DATA stream",e);

                response = new SMTPResponse(SMTPRetCode.LOCAL_ERROR,DSNStatus.getStatus(DSNStatus.TRANSIENT,
                        DSNStatus.UNDEFINED_STATUS) + " Temporary error deliver message to " + recipient);
           
            } catch (MessagingException e) {
                session.getLogger().info("Unexpected error handling DATA stream",e);

                response = new SMTPResponse(SMTPRetCode.LOCAL_ERROR,DSNStatus.getStatus(DSNStatus.TRANSIENT,
                        DSNStatus.UNDEFINED_STATUS) + " Temporary error deliver message to " + recipient);
            }
            session.writeResponse(response);
        }
       
View Full Code Here

Examples of org.apache.james.protocols.smtp.SMTPResponse

        StringBuilder response = new StringBuilder();
        response.append(session.getHelloName()).append(
                " Hello ").append(parameters).append(" (").append(
                session.getRemoteHost()).append(" [").append(
                session.getRemoteIPAddress()).append("])");
        return new SMTPResponse(SMTPRetCode.MAIL_OK, response);
    }
View Full Code Here

Examples of org.apache.james.protocols.smtp.SMTPResponse

    protected SMTPResponse doFilterChecks(SMTPSession session, String command,
            String parameters) {
        session.resetState();

        if (parameters == null) {
            return new SMTPResponse(SMTPRetCode.SYNTAX_ERROR_ARGUMENTS,
                    DSNStatus.getStatus(DSNStatus.PERMANENT,
                            DSNStatus.DELIVERY_INVALID_ARG)
                            + " Domain address required: " + COMMAND_NAME);
        } else {
            // store provided name
View Full Code Here

Examples of org.apache.james.protocols.smtp.SMTPResponse

        response
                .append(
                        DSNStatus.getStatus(DSNStatus.SUCCESS,
                                DSNStatus.ADDRESS_VALID))
                .append(" Recipient <").append(recipientAddress).append("> OK");
        return new SMTPResponse(SMTPRetCode.MAIL_OK, response);

    }
View Full Code Here

Examples of org.apache.james.protocols.smtp.SMTPResponse

            int colonIndex = argument.indexOf(":");
            recipient = argument.substring(colonIndex + 1);
            argument = argument.substring(0, colonIndex);
        }
        if (!session.getState().containsKey(SMTPSession.SENDER)) {
            return new SMTPResponse(SMTPRetCode.BAD_SEQUENCE, DSNStatus
                    .getStatus(DSNStatus.PERMANENT, DSNStatus.DELIVERY_OTHER)
                    + " Need MAIL before RCPT");
        } else if (argument == null
                || !argument.toUpperCase(Locale.US).equals("TO")
                || recipient == null) {
            return new SMTPResponse(SMTPRetCode.SYNTAX_ERROR_ARGUMENTS,
                    DSNStatus.getStatus(DSNStatus.PERMANENT,
                            DSNStatus.DELIVERY_SYNTAX)
                            + " Usage: RCPT TO:<recipient>");
        }

        recipient = recipient.trim();
        int lastChar = recipient.lastIndexOf('>');
        // Check to see if any options are present and, if so, whether they
        // are correctly formatted
        // (separated from the closing angle bracket by a ' ').
        String rcptOptionString = null;
        if ((lastChar > 0) && (recipient.length() > lastChar + 2)
                && (recipient.charAt(lastChar + 1) == ' ')) {
            rcptOptionString = recipient.substring(lastChar + 2);

            // Remove the options from the recipient
            recipient = recipient.substring(0, lastChar + 1);
        }
        if (session.useAddressBracketsEnforcement()
                && (!recipient.startsWith("<") || !recipient.endsWith(">"))) {
            if (session.getLogger().isInfoEnabled()) {
                StringBuilder errorBuffer = new StringBuilder(192).append(
                        "Error parsing recipient address: ").append(
                        "Address did not start and end with < >").append(
                        getContext(session, null, recipient));
                session.getLogger().info(errorBuffer.toString());
            }
            return new SMTPResponse(SMTPRetCode.SYNTAX_ERROR_ARGUMENTS,
                    DSNStatus.getStatus(DSNStatus.PERMANENT,
                            DSNStatus.DELIVERY_SYNTAX)
                            + " Syntax error in parameters or arguments");
        }
        MailAddress recipientAddress = null;
        // Remove < and >
        if (session.useAddressBracketsEnforcement()
                || (recipient.startsWith("<") && recipient.endsWith(">"))) {
            recipient = recipient.substring(1, recipient.length() - 1);
        }

        if (recipient.indexOf("@") < 0) {
            // set the default domain
            recipient = recipient
                    + "@"
                    + getDefaultDomain();
        }

        try {
            recipientAddress = new MailAddress(recipient);
        } catch (Exception pe) {
            if (session.getLogger().isInfoEnabled()) {
                StringBuilder errorBuffer = new StringBuilder(192).append(
                        "Error parsing recipient address: ").append(
                        getContext(session, recipientAddress, recipient))
                        .append(pe.getMessage());
                session.getLogger().info(errorBuffer.toString());
            }
            /*
             * from RFC2822; 553 Requested action not taken: mailbox name
             * not allowed (e.g., mailbox syntax incorrect)
             */
            return new SMTPResponse(SMTPRetCode.SYNTAX_ERROR_MAILBOX,
                    DSNStatus.getStatus(DSNStatus.PERMANENT,
                            DSNStatus.ADDRESS_SYNTAX)
                            + " Syntax error in recipient address");
        }

        if (rcptOptionString != null) {

            StringTokenizer optionTokenizer = new StringTokenizer(
                    rcptOptionString, " ");
            while (optionTokenizer.hasMoreElements()) {
                String rcptOption = optionTokenizer.nextToken();
                int equalIndex = rcptOption.indexOf('=');
                String rcptOptionName = rcptOption;
                String rcptOptionValue = "";
                if (equalIndex > 0) {
                    rcptOptionName = rcptOption.substring(0, equalIndex)
                            .toUpperCase(Locale.US);
                    rcptOptionValue = rcptOption.substring(equalIndex + 1);
                }
                // Unexpected option attached to the RCPT command
                if (session.getLogger().isDebugEnabled()) {
                    StringBuilder debugBuffer = new StringBuilder(128)
                            .append(
                                    "RCPT command had unrecognized/unexpected option ")
                            .append(rcptOptionName).append(" with value ")
                            .append(rcptOptionValue).append(
                                    getContext(session, recipientAddress,
                                            recipient));
                    session.getLogger().debug(debugBuffer.toString());
                }

                return new SMTPResponse(
                        SMTPRetCode.PARAMETER_NOT_IMPLEMENTED,
                        "Unrecognized or unsupported option: "
                                + rcptOptionName);
            }
            optionTokenizer = null;
View Full Code Here

Examples of org.apache.james.protocols.smtp.SMTPResponse

                // transformation before writing them to output.
                out.write(line);
            }
            out.flush();
        } catch (IOException e) {
            SMTPResponse response;
            response = new SMTPResponse(SMTPRetCode.LOCAL_ERROR,DSNStatus.getStatus(DSNStatus.TRANSIENT,
                            DSNStatus.UNDEFINED_STATUS) + " Error processing message: " + e.getMessage());
           
            session.getLogger().error(
                    "Unknown error occurred while processing DATA.", e);
            session.writeResponse(response);
View Full Code Here

Examples of org.apache.james.protocols.smtp.SMTPResponse

                           
                            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.