Package org.apache.mailet

Examples of org.apache.mailet.Mail


    /**
     * Call the wrapped mailet for the exchange
     */
    @SuppressWarnings("unchecked")
    public void process(Exchange exchange) throws Exception {
        Mail mail = exchange.getIn().getBody(Mail.class);
        try {
            mailet.service(mail);
        } catch (MessagingException me) {
            String onMailetException = null;
           
            MailetConfig mailetConfig = mailet.getMailetConfig();
            if (mailetConfig instanceof MailetConfigImpl) {
                onMailetException = ((MailetConfigImpl) mailetConfig).getInitAttribute("onMailetException");
            }
            if (onMailetException == null) {
                onMailetException = Mail.ERROR;
            } else {
                onMailetException = onMailetException.trim().toLowerCase(Locale.US);
            }
            if (onMailetException.compareTo("ignore") == 0) {
                // ignore the exception and continue
                // this option should not be used if the mail object can be
                // changed by the mailet
                ProcessorUtil.verifyMailAddresses(mail.getRecipients());
            } else {
                ProcessorUtil.handleException(me, mail, mailet.getMailetConfig().getMailetName(), onMailetException, logger);
            }
        }
    }
View Full Code Here


                // all recipients matched
                fullMatch = true;
            } else {
                mail.setRecipients(rcpts);
               
                Mail newMail = new MailImpl(mail);
                newMail.setRecipients(matchedRcpts);
               
             
                // Set a header because the matcher matched. This can be used later when processing the route
                newMail.setAttribute(MATCHER_MATCHED_ATTRIBUTE, true);
               
                // add the new generated mail to the mails list
                mails.add(newMail);
            }
        }
View Full Code Here

    /*
     * (non-Javadoc)
     * @see org.apache.camel.Predicate#matches(org.apache.camel.Exchange)
     */
    public boolean matches(Exchange ex) {
        Mail m = ex.getIn().getBody(Mail.class);
        if (state.equals(m.getState())) {
            return true;
        }
        return false;
    }
View Full Code Here

        queue.clear();
        super.tearDown();
    }

    public void verifyLastMail(String sender, String recipient, MimeMessage msg) throws IOException, MessagingException {
        Mail mailData = queue.getLastMail();
        assertNotNull("mail received by mail server", mailData);

        if (sender == null && recipient == null && msg == null)
            fail("no verification can be done with all arguments null");

        if (sender != null)
            assertEquals("sender verfication", sender, mailData.getSender().toString());
        if (recipient != null)
            assertTrue("recipient verfication", mailData.getRecipients().contains(new MailAddress(recipient)));
        if (msg != null) {
            ByteArrayOutputStream bo1 = new ByteArrayOutputStream();
            msg.writeTo(bo1);
            ByteArrayOutputStream bo2 = new ByteArrayOutputStream();
            mailData.getMessage().writeTo(bo2);
            assertEquals(bo1.toString(), bo2.toString());
            assertEquals("message verification", msg, mailData.getMessage());
        }
    }
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) objectRepository.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);
                }
                final String errorMessage = exceptionBuffer.toString();
                getLogger().warn(errorMessage);
                getLogger().debug(errorMessage, re);
                return null;
            }
            MimeMessageStreamRepositorySource source = new MimeMessageStreamRepositorySource(streamRepository, 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(), me);
View Full Code Here

        // If the IP address and host name for the remote domain cannot
        // be found, we will get an UnknownHostException.
        // In both cases, we log the problem and
        // return. The message disposition is defined by the
        // <undeliverable> attributes.
        Mail mail = null;
        try
        {
            mail = createMail(createMessage(), intendedRecipient);
        }
        catch (ParseException ex)
View Full Code Here

        if (throwException) {
            throwException = false;
            throw new MailQueueException("Mock");
        }
        try {
          final Mail mail = queue.take();
          if (queue.isEmpty()) lastMail = null;
            return new MailQueueItem() {
       
        public Mail getMail() {
          return mail;
View Full Code Here

        while(active.get()) {
            numActive.incrementAndGet();

            try {
                MailQueueItem queueItem = queue.deQueue();
                Mail mail = queueItem.getMail();
                if (logger.isDebugEnabled()) {
                    StringBuffer debugBuffer =
                        new StringBuffer(64)
                                .append("==== Begin processing mail ")
                                .append(mail.getName())
                                .append("====");
                    logger.debug(debugBuffer.toString());
                }

                try {
View Full Code Here

    /*
     * (non-Javadoc)
     * @see org.apache.camel.Predicate#matches(org.apache.camel.Exchange)
     */
    public boolean matches(Exchange arg0) {
        Mail m = arg0.getIn().getBody(Mail.class);
        if (m.removeAttribute(MatcherSplitter.MATCHER_MATCHED_ATTRIBUTE) != null) {
           return true;
        }
        return false;
    }
View Full Code Here

        assertTrue(!isSameMimeMessage(m2.getMessage(),mail.getMessage()));
        // check that the subjects are correct on both mails!
        assertEquals(m2.getMessage().getSubject(),"new Subject");
        assertEquals(mail.getMessage().getSubject(),"foo");
        // cloning again the messages
        Mail m2clone = m2.duplicate();
        assertTrue(isSameMimeMessage(m2clone.getMessage(),m2.getMessage()));
        MimeMessage mm = getWrappedMessage(m2.getMessage());
        assertNotSame(m2.getMessage(),m2clone.getMessage());
        // test that m2clone has a valid wrapped message
        MimeMessage mm3 = getWrappedMessage(m2clone.getMessage());
        assertNotNull(mm3);
        // dispose m2 and check that the clone has still a valid message and it is the same!
        ((MailImpl) m2).dispose();
        assertEquals(mm3,getWrappedMessage(m2clone.getMessage()));
        // change the message that should be not referenced by m2 that has
        // been disposed, so it should not clone it!
        m2clone.getMessage().setSubject("new Subject 2");
        m2clone.getMessage().setText("new Body 3");
        assertTrue(isSameMimeMessage(m2clone.getMessage(),mm));
        ContainerUtil.dispose(mail);
        ContainerUtil.dispose(messageFromSources);
    }
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.