Package org.apache.james.protocols.smtp

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


     * @param argument
     *            the argument passed in with the command by the SMTP client
     */
    private Response doMAIL(SMTPSession session, String argument) {
        StringBuilder responseBuffer = new StringBuilder();
        MailAddress sender = (MailAddress) session.getAttachment(
                SMTPSession.SENDER, State.Transaction);
        responseBuffer.append(
                DSNStatus.getStatus(DSNStatus.SUCCESS, DSNStatus.ADDRESS_OTHER))
                .append(" Sender <");
        if (sender != null) {
View Full Code Here


                            .append(": did not start and end with < >");
                    session.getLogger().info(errorBuffer.toString());
                }
                return SYNTAX_ERROR;
            }
            MailAddress senderAddress = null;

            if (session.getConfiguration().useAddressBracketsEnforcement()
                    || (sender.startsWith("<") && sender.endsWith(">"))) {
                // Remove < and >
                sender = sender.substring(1, sender.length() - 1);
            }

            if (sender.length() == 0) {
                // This is the <> case. Let senderAddress == null
            } else {

                if (sender.indexOf("@") < 0) {
                    sender = sender
                            + "@"
                            + getDefaultDomain();
                }

                try {
                    senderAddress = new MailAddress(sender);
                } catch (Exception pe) {
                    if (session.getLogger().isInfoEnabled()) {
                        StringBuilder errorBuffer = new StringBuilder(256)
                                .append("Error parsing sender address: ")
                                .append(sender).append(": ").append(
                                        pe.getMessage());
                        session.getLogger().info(errorBuffer.toString());
                    }
                    return SYNTAX_ERROR_ADDRESS;
                }
            }
            if ((senderAddress == null) ||
                    ((senderAddress.getLocalPart().length() == 0) && (senderAddress.getDomain().length() == 0))) {
                senderAddress = MailAddress.nullSender();
            }
            // Store the senderAddress in session map
            session.setAttachment(SMTPSession.SENDER, senderAddress, State.Transaction);
        }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    protected HookResult callHook(MailHook rawHook, SMTPSession session, String parameters) {
        MailAddress sender = (MailAddress) session.getAttachment(SMTPSession.SENDER, State.Transaction);
        if (sender.isNullSender()) {
            sender = null;
        }
        return rawHook.doMail(session, sender);
    }
View Full Code Here

     * @param argument
     *            the argument passed in with the command by the SMTP client
     */
    private Response doMAIL(SMTPSession session, String argument) {
        StringBuilder responseBuffer = new StringBuilder();
        MailAddress sender = (MailAddress) session.getState().get(
                SMTPSession.SENDER);
        responseBuffer.append(
                DSNStatus.getStatus(DSNStatus.SUCCESS, DSNStatus.ADDRESS_OTHER))
                .append(" Sender <");
        if (sender != null) {
View Full Code Here

                return new SMTPResponse(SMTPRetCode.SYNTAX_ERROR_ARGUMENTS,
                        DSNStatus.getStatus(DSNStatus.PERMANENT,
                                DSNStatus.ADDRESS_SYNTAX_SENDER)
                                + " Syntax error in MAIL command");
            }
            MailAddress senderAddress = null;

            if (session.getConfiguration().useAddressBracketsEnforcement()
                    || (sender.startsWith("<") && sender.endsWith(">"))) {
                // Remove < and >
                sender = sender.substring(1, sender.length() - 1);
            }

            if (sender.length() == 0) {
                // This is the <> case. Let senderAddress == null
            } else {

                if (sender.indexOf("@") < 0) {
                    sender = sender
                            + "@"
                            + getDefaultDomain();
                }

                try {
                    senderAddress = new MailAddress(sender);
                } catch (Exception pe) {
                    if (session.getLogger().isInfoEnabled()) {
                        StringBuilder errorBuffer = new StringBuilder(256)
                                .append("Error parsing sender address: ")
                                .append(sender).append(": ").append(
View Full Code Here

       
        return dns;
    }
   
    public void testRejectInvalidHelo() throws MailAddressException {
        MailAddress mailAddress = new MailAddress("test@localhost");
        SMTPSession session = setupMockSession(INVALID_HOST,false,false,null,mailAddress);
        ResolvableEhloHeloHandler handler = new ResolvableEhloHeloHandler();
        handler.setDNSService(setupMockDNSServer());
       
        handler.doHelo(session, INVALID_HOST);
View Full Code Here

        assertEquals("Reject", result,HookReturnCode.DENY);
    }
   
   
    public void testNotRejectValidHelo() throws MailAddressException {
        MailAddress mailAddress = new MailAddress("test@localhost");
        SMTPSession session = setupMockSession(VALID_HOST,false,false,null,mailAddress);
        ResolvableEhloHeloHandler handler = new ResolvableEhloHeloHandler();
               
        handler.setDNSService(setupMockDNSServer());
 
View Full Code Here

        assertEquals("Not reject", result,HookReturnCode.DECLINED);
    }
  
   
    public void testRejectInvalidHeloAuthUser() throws MailAddressException {
        MailAddress mailAddress = new MailAddress("test@localhost");
        SMTPSession session = setupMockSession(INVALID_HOST,false,true,"valid@user",mailAddress);
        ResolvableEhloHeloHandler handler = new ResolvableEhloHeloHandler();
               
        handler.setDNSService(setupMockDNSServer());
View Full Code Here

    }
   
  
   
    public void testRejectRelay() throws MailAddressException {
        MailAddress mailAddress = new MailAddress("test@localhost");
        SMTPSession session = setupMockSession(INVALID_HOST,true,false,null,mailAddress);
        ResolvableEhloHeloHandler handler = new ResolvableEhloHeloHandler();
       
       
        handler.setDNSService(setupMockDNSServer());
View Full Code Here

    // ip is blacklisted and has txt details
    public void testBlackListedTextPresent() throws MailAddressException {
        DNSRBLHandler rbl = new DNSRBLHandler();
      
        setupMockedSMTPSession(new MailAddress("any@domain"));
        rbl.setDNSService(mockedDnsServer);

        rbl.setBlacklist(new String[] { "bl.spamcop.net." });
        rbl.setGetDetail(true);
        rbl.doRcpt(mockedSMTPSession, null, new MailAddress("test@localhost"));
        assertEquals("Details","Blocked - see http://www.spamcop.net/bl.shtml?127.0.0.2",
               mockedSMTPSession.getConnectionState().get(RBL_DETAIL_MAIL_ATTRIBUTE_NAME));
        assertNotNull("Blocked",mockedSMTPSession.getConnectionState().get(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME));
    }
View Full Code Here

TOP

Related Classes of org.apache.james.protocols.smtp.MailAddress

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.