Package org.apache.james.protocols.smtp

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


            if (line.length == 3 && line[0] == 46) {
                out.flush();
                out.close();

                List<MailAddress> recipientCollection = (List<MailAddress>) session.getAttachment(SMTPSession.RCPT_LIST, State.Transaction);
                MailAddress mailAddress = (MailAddress) session.getAttachment(SMTPSession.SENDER, State.Transaction);

                List<org.apache.mailet.MailAddress> rcpts = new ArrayList<org.apache.mailet.MailAddress>();
                for (MailAddress address : recipientCollection) {
                    rcpts.add(new MailetMailAddressAdapter(address));
                }
View Full Code Here


        public List<MailAddress> getRecipients() {
            //TODO: not sure this MailAddress transformation code does the right thing
            List<MailAddress> mailAddressList = new ArrayList<MailAddress>();
            for (org.apache.mailet.MailAddress address : mail.getRecipients()) {
                try {
                    mailAddressList.add(new MailAddress(address.getLocalPart(), address.getDomain()));
                } catch (MailAddressException ex) {
                    throw new RuntimeException(ex);
                }
            }
            return mailAddressList;
View Full Code Here

        // build a wrapper around the Mail
        final ReadOnlyMailEnvelope env = new ReadOnlyMailEnvelope(mail);

        for (org.apache.mailet.MailAddress recipient : mail.getRecipients()) {
            // TODO: the transformation code between MailAddress is purely to compile. No idea if it does what it's supposed
            MailAddress recipientAddress;
            try {
                recipientAddress = new MailAddress(recipient.getLocalPart(), recipient.getDomain());
            } catch (MailAddressException e) {
                throw new RuntimeException(e);
            }
            Response response = null;
            for (DeliverToRecipientHook handler : handlers) {
View Full Code Here

        LMTPMultiResponse mResponse = null;

        Iterator<MailAddress> recipients = mail.getRecipients().iterator();
       
        while (recipients.hasNext()) {
            MailAddress recipient = recipients.next();
            Response response = null;
            for (DeliverToRecipientHook handler: handlers) {
                response = AbstractHookableCmdHandler.calcDefaultSMTPResponse(handler.deliver(session, recipient, mail));
                if (response != null) {
                    break;
View Full Code Here

     */
    public HookResult doRcpt(SMTPSession session, MailAddress sender,
            MailAddress rcpt) {
        if (session.getUser() != null) {
            String authUser = (session.getUser()).toLowerCase(Locale.US);
            MailAddress senderAddress = (MailAddress) session.getAttachment(
                    SMTPSession.SENDER, ProtocolSession.State.Transaction);
            String username= null;

            if (senderAddress != null) {
                if (useVirtualHosting()) {
                    username = senderAddress.toString();
                } else {
                    username = senderAddress.getLocalPart();
                }
            }
           
            // Check if the sender address is the same as the user which was used to authenticate.
            // Its important to ignore case here to fix JAMES-837. This is save todo because if the handler is called
            // the user was already authenticated
            if ((senderAddress == null)
                    || (!authUser.equalsIgnoreCase(username))
                    || (!isLocalDomain(senderAddress.getDomain()))) {
                return INVALID_AUTH;
            }
        }
        return HookResult.declined();
    }
View Full Code Here

        Collection<MailAddress> rcptColl = (Collection<MailAddress>) session.getAttachment(
                SMTPSession.RCPT_LIST, State.Transaction);
        if (rcptColl == null) {
            rcptColl = new ArrayList<MailAddress>();
        }
        MailAddress recipientAddress = (MailAddress) session.getAttachment(
                CURRENT_RECIPIENT, State.Transaction);
        rcptColl.add(recipientAddress);
        session.setAttachment(SMTPSession.RCPT_LIST, rcptColl, State.Transaction);
        StringBuilder response = new StringBuilder();
        response
View Full Code Here

                        getContext(session, null, recipient));
                session.getLogger().info(errorBuffer.toString());
            }
            return SYNTAX_ERROR_DELIVERY;
        }
        MailAddress recipientAddress = null;
        // Remove < and >
        if (session.getConfiguration().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))
View Full Code Here

        SpamTrapHandler handler = new SpamTrapHandler();
   
        handler.setBlockTime(blockTime);
        handler.setSpamTrapRecipients(rcpts);
   
        int result = handler.doRcpt(setUpSMTPSession(ip),null,new MailAddress(SPAM_TRAP_RECIP1)).getResult();
   
        assertEquals("Blocked on first connect",HookReturnCode.DENY,result);
   

        result = handler.doRcpt(setUpSMTPSession(ip),null,new MailAddress(RECIP1)).getResult();
   
        assertEquals("Blocked on second connect", HookReturnCode.DENY,result);
   
       
        result = handler.doRcpt(setUpSMTPSession(ip2),null,new MailAddress(RECIP1)).getResult();
   
        assertEquals("Not Blocked", HookReturnCode.DECLINED,result);
   
        try {
            // Wait for the blockTime to exceed
            Thread.sleep(blockTime);
        } catch (InterruptedException e) {
            fail("Failed to sleep for " + blockTime +" ms");
        }
   
        result = handler.doRcpt(setUpSMTPSession(ip),null,new MailAddress(RECIP1)).getResult();
   
        assertEquals("Not blocked. BlockTime exceeded", HookReturnCode.DECLINED,result);
    }
View Full Code Here

    }

    @Test
    public void testInvalidSenderDomainReject() throws MailAddressException {
        ValidSenderDomainHandler handler = createHandler();
        SMTPSession session = setupMockedSession(new MailAddress("invalid@invalid"));
        int response = handler.doMail(session,(MailAddress) session.getAttachment(SMTPSession.SENDER, State.Transaction)).getResult();
       
        assertEquals("Blocked cause we use reject action", response,HookReturnCode.DENY);
    }
View Full Code Here

    public void testRejectMaxRcpt() throws MailAddressException {
        SMTPSession session = setupMockedSession(3);
        MaxRcptHandler handler = new MaxRcptHandler();
       
        handler.setMaxRcpt(2);
        int resp = handler.doRcpt(session,null,new MailAddress("test@test")).getResult();
   
        assertEquals("Rejected.. To many recipients", resp, HookReturnCode.DENY);
    }
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.