Package org.apache.mailet

Examples of org.apache.mailet.Mail


            // current behavior. *BUT*, shouldn't this method return more gracefully?!
        }
    }

    public void testAttributes() {
        Mail mail = createMailImplementation();
        assertFalse("no initial attributes", mail.hasAttributes());
        assertFalse("attributes initially empty", mail.getAttributeNames().hasNext());
        assertNull("not found on emtpy list", mail.getAttribute("test"));
        assertNull("no previous item with key", mail.setAttribute("testKey", "testValue"));
        assertEquals("item found", "testValue", mail.getAttribute("testKey"));
        assertTrue("has attribute", mail.hasAttributes());
        assertEquals("item removed", "testValue", mail.removeAttribute("testKey"));
        assertNull("item no longer found", mail.getAttribute("testKey"));
    }
View Full Code Here


        java.util.Collection processed = new java.util.ArrayList();
        Iterator list = repository.list();
        while (list.hasNext()) {
            String key = (String) list.next();
            try {
                Mail mail =  repository.retrieve(key);
                if (mail != null && mail.getRecipients() != null) {
                    log((new StringBuffer(160).append("Spooling mail ").append(mail.getName()).append(" from ").append(repositoryPath)).toString());

                    /*
                    log("Return-Path: " + mail.getMessage().getHeader(RFC2822Headers.RETURN_PATH, ", "));
                    log("Sender: " + mail.getSender());
                    log("To: " + mail.getMessage().getHeader(RFC2822Headers.TO, ", "));
                    log("Recipients: ");
                    for (Iterator i = mail.getRecipients().iterator(); i.hasNext(); ) {
                        log("    " + ((MailAddress)i.next()).toString());
                    };
                    */

                    mail.setAttribute("FromRepository", Boolean.TRUE);
                    mail.setState(processor);
                    getMailetContext().sendMail(mail);
                    if (delete) processed.add(key);
                    LifecycleUtil.dispose(mail);
                }
            } catch (MessagingException e) {
View Full Code Here

    }
    */

    @Override
    protected MailQueueItem createMailQueueItem(Connection connection, Session session, MessageConsumer consumer, Message message) throws JMSException, MessagingException {
        Mail mail = createMail(message);
        return new ActiveMQMailQueueItem(mail, connection, session, consumer, message, logger);
    }
View Full Code Here

                    // The amount
                    // of time to block is determined by the 'getWaitTime'
                    // method of the
                    // MultipleDelayFilter.
                    MailQueueItem queueItem = queue.deQueue();
                    Mail mail = queueItem.getMail();
                   
                    String key = mail.getName();
                    try {
                        if (isDebug) {
                            String message = Thread.currentThread().getName()
                                    + " will process mail " + key;
                            log(message);
                        }
                       
                        // Deliver message
                        if (deliver(mail, session)) {
                            // Message was successfully delivered/fully failed...
                            // delete it
                            LifecycleUtil.dispose(mail);
                            //workRepository.remove(key);
                        } else {
                            // Something happened that will delay delivery.
                            // Store it back in the retry repository.
                            //workRepository.store(mail);
                            int retries = 0;
                            try {
                                retries = Integer.parseInt(mail.getErrorMessage());
                            } catch (NumberFormatException e) {
                                // Something strange was happen with the errorMessage..
                            }
                           
                            long delay =  getNextDelay (retries);
View Full Code Here

    protected void setRemoteAddr(String remoteAddr) {
        this.remoteAddr = remoteAddr;
    }

    protected void setupMockedMail() {
        mockedMail = new Mail() {

            private static final long serialVersionUID = 1L;

            public String getName() {
                throw new UnsupportedOperationException(
View Full Code Here

       
    }


    public void testAddressMapping() throws Exception {
        Mail mail = createMail(new String[] {"test@localhost", "apache@localhost"});
        table.service(mail);
       
        assertEquals(3,mail.getRecipients().size());
        Iterator<MailAddress> it = mail.getRecipients().iterator();
        assertEquals("whatever@localhost", ((MailAddress)it.next()).toString());
        assertEquals("blah@localhost", ((MailAddress)it.next()).toString());
        assertEquals("apache@localhost", ((MailAddress)it.next()).toString());

    }
View Full Code Here

    /**
     * @return
     * @throws MessagingException
     */
    private Mail createMail(String[] recipients) throws MessagingException {
        Mail mail = new FakeMail();
        ArrayList<MailAddress> a = new ArrayList<MailAddress>(recipients.length);
        for (int i = 0; i < recipients.length; i++) {
            a.add(new MailAddress(recipients[i]));
        }
        mail.setRecipients(a);
        mail.setMessage(new FakeMimeMessage());
        return mail;
    }
View Full Code Here

    public Mail retrieve(String key) throws MessagingException {
        if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) {
            getLogger().debug("Retrieving mail: " + key);
        }
        try {
            Mail mc = null;
            try {
                mc = new MailImpl((Mail) spool.get(key),key);
                mc.setState(((Mail) spool.get(key)).getState());
                mc.setErrorMessage(((Mail) spool.get(key)).getErrorMessage());
                mc.setLastUpdated(((Mail) spool.get(key)).getLastUpdated());
            }
            catch (RuntimeException re){
                StringBuffer exceptionBuffer = new StringBuffer(128);
                if(re.getCause() instanceof Error){
                    exceptionBuffer.append("Error when retrieving mail, not deleting: ")
View Full Code Here

                if (lock(s)) {
                    if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) {
                        getLogger().debug("accept(Filter) has locked: " + s);
                    }
                    try {
                        Mail mail = retrieve(s);
                        // Retrieve can return null if the mail is no longer on the spool
                        // (i.e. another thread has gotten to it first).
                        // In this case we simply continue to the next key
                        if (mail == null || !filter.accept (mail.getName(),
                                                            mail.getState(),
                                                            mail.getLastUpdated().getTime(),
                                                            mail.getErrorMessage())) {
                            unlock(s);
                            continue;
                        }
                        return mail;
                    } catch (javax.mail.MessagingException e) {
View Full Code Here

    public void service(Mail originalMail) throws MessagingException {

        boolean keepMessageId = false;

        // duplicates the Mail object, to be able to modify the new mail keeping the original untouched
        Mail newMail = ((MailImpl) originalMail).duplicate(newName((MailImpl) originalMail));
        // We don't need to use the original Remote Address and Host,
        // and doing so would likely cause a loop with spam detecting
        // matchers.
        try {
            ((MailImpl) newMail).setRemoteAddr(java.net.InetAddress.getLocalHost().getHostAddress());
            ((MailImpl) newMail).setRemoteHost(java.net.InetAddress.getLocalHost().getHostName());
        } catch (java.net.UnknownHostException _) {
            ((MailImpl) newMail).setRemoteAddr("127.0.0.1");
            ((MailImpl) newMail).setRemoteHost("localhost");
        }

        if (isDebug) {
            MailImpl newMailImpl = (MailImpl) newMail;
            log("New mail - sender: " + newMailImpl.getSender()
                       + ", recipients: " + arrayToString(newMailImpl.getRecipients().toArray())
                       + ", name: " + newMailImpl.getName()
                       + ", remoteHost: " + newMailImpl.getRemoteHost()
                       + ", remoteAddr: " + newMailImpl.getRemoteAddr()
                       + ", state: " + newMailImpl.getState()
                       + ", lastUpdated: " + newMailImpl.getLastUpdated()
                       + ", errorMessage: " + newMailImpl.getErrorMessage());
        }

        //Create the message
        if(getInLineType(originalMail) != UNALTERED) {
            if (isDebug) {
                log("Alter message");
            }
            newMail.setMessage(new MimeMessage(Session.getDefaultInstance(System.getProperties(),
                                                               null)));

            // handle the new message if altered
            buildAlteredMessage(newMail, originalMail);

        } else {
            // if we need the original, create a copy of this message to redirect
            if (getPassThrough(originalMail)) {
                newMail.setMessage(new MimeMessage(originalMail.getMessage()) {
                    protected void updateHeaders() throws MessagingException {
                        if (getMessageID() == null) super.updateHeaders();
                        else {
                            modified = false;
                        }
                    }
                });
            }
            if (isDebug) {
                log("Message resent unaltered.");
            }
            keepMessageId = true;
        }

        //Set additional headers

        setRecipients(newMail, getRecipients(originalMail), originalMail);

        setTo(newMail, getTo(originalMail), originalMail);

        setSubjectPrefix(newMail, getSubjectPrefix(originalMail), originalMail);

        if(newMail.getMessage().getHeader(RFC2822Headers.DATE) == null) {
            newMail.getMessage().setHeader(RFC2822Headers.DATE, rfc822DateFormat.format(new Date()));
        }

        setReplyTo(newMail, getReplyTo(originalMail), originalMail);

        setReversePath(newMail, getReversePath(originalMail), originalMail);

        setSender(newMail, getSender(originalMail), originalMail);

        setIsReply(newMail, isReply(originalMail), originalMail);

        newMail.getMessage().saveChanges();

        if (keepMessageId) {
            setMessageId(newMail, originalMail);
        }

        if (senderDomainIsValid(newMail)) {
            //Send it off...
            getMailetContext().sendMail(newMail);
        } else {
            StringBuffer logBuffer = new StringBuffer(256)
                                    .append(getMailetName())
                                    .append(" mailet cannot forward ")
                                    .append(((MailImpl) originalMail).getName())
                                    .append(". Invalid sender domain for ")
                                    .append(newMail.getSender())
                                    .append(". Consider using the Resend mailet ")
                                    .append("using a different sender.");
            throw new MessagingException(logBuffer.toString());
        }
View Full Code Here

TOP

Related Classes of org.apache.mailet.Mail

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.