Package org.apache.mailet

Examples of org.apache.mailet.Mail


        ArrayList r = new ArrayList();
        r.add(new MailAddress("recipient@test.com"));
        MimeMessageCopyOnWriteProxy messageFromSources = (MimeMessageCopyOnWriteProxy) getMessageFromSources(content+sep+body);
        MailImpl mail = new MailImpl("test",new MailAddress("test@test.com"),r,messageFromSources);
        // cloning the message
        Mail mailClone = mail.duplicate();
        assertTrue(isSameMimeMessage(mailClone.getMessage(),mail.getMessage()));
        MimeMessage mm = getWrappedMessage(mail.getMessage());
        assertNotSame(mail.getMessage(),mailClone.getMessage());
        // dispose mail and check that the clone has still a valid message and it is the same!
        ((MailImpl) mail).dispose();
        ContainerUtil.dispose(messageFromSources);
        // need to add a gc and a wait, because the original mimemessage should be finalized before the test.
        System.gc();
        Thread.sleep(1000);
        // dumb test
        assertTrue(isSameMimeMessage(mailClone.getMessage(),mailClone.getMessage()));
        // change the message that should be not referenced by mail that has
        // been disposed, so it should not clone it!
        mailClone.getMessage().setSubject("new Subject 2");
        mailClone.getMessage().setText("new Body 3");
        assertTrue(isSameMimeMessage(mailClone.getMessage(),mm));
        ContainerUtil.dispose(mailClone);
        ContainerUtil.dispose(mm);
    }
View Full Code Here


    public Iterator list() throws MessagingException {
        return messages.keySet().iterator()// trivial implementation
    }

    public Mail retrieve(String key) throws MessagingException {
        Mail m2 = new MailImpl((Mail) messages.get(key),key);
        m2.setState(((Mail) messages.get(key)).getState());
        return m2;  // trivial implementation
    }
View Full Code Here

        messages.remove(mail.getName());
    }

    public void remove(Collection mails) throws MessagingException {
        for (Iterator i = mails.iterator(); i.hasNext(); ) {
            Mail m = (Mail) i.next();
            messages.remove(m.getName());
        }
    }
View Full Code Here

    private class CheckerMailet extends GenericMailet {
       
        public ArrayList receivedMails = new ArrayList();

        public void service(Mail mail) throws MessagingException {
            Mail m2 = new MailImpl(mail,mail.getName());
            m2.setState(mail.getState());
            receivedMails.add(m2);
        }
View Full Code Here

        MockMailetConfig mci = new MockMailetConfig("Test",new MockMailContext());
        mci.setProperty("text",footer);

        mailet.init(mci);

        Mail mail = new MailImpl(new MimeMessage(Session
                .getDefaultInstance(new Properties()),
                new ByteArrayInputStream(asciisource.getBytes())));

        mailet.service(mail);

        ByteArrayOutputStream rawMessage = new ByteArrayOutputStream();
        mail.getMessage().writeTo(
                rawMessage,
                new String[] { "Bcc", "Content-Length", "Message-ID" });
        String res = rawMessage.toString();
        return res;
    }
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 = (Mail) spool.get(key);
            }
            catch (RuntimeException re){
                StringBuffer exceptionBuffer = new StringBuffer(128);
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

            // 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

    public Mail retrieve(String key) throws MessagingException {
        if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) {
            getLogger().debug("Retrieving mail: " + key);
        }
        try {
            Mail mc = null;
            try {
                mc = (Mail) or.get(key);
            }
            catch (RuntimeException re){
                StringBuffer exceptionBuffer = new StringBuffer(128);
                if(re.getCause() instanceof Error){
                    exceptionBuffer.append("Error when retrieving mail, not deleting: ")
                            .append(re.toString());
                }else{
                    exceptionBuffer.append("Exception retrieving mail: ")
                            .append(re.toString())
                            .append(", so we're deleting it.");
                    remove(key);
                }
                getLogger().warn(exceptionBuffer.toString());
                return null;
            }
            MimeMessageAvalonSource source = new MimeMessageAvalonSource(sr, destination, key);
            mc.setMessage(new MimeMessageCopyOnWriteProxy(source));

            return mc;
        } catch (Exception me) {
            getLogger().error("Exception retrieving mail: " + me);
            throw new MessagingException("Exception while retrieving mail: " + me.getMessage());
View Full Code Here

            // 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

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.