Package org.apache.mailet

Examples of org.apache.mailet.Mail


     */
    public void service(Mail originalMail) throws MessagingException {


        // 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");
        }
        MailAddress returnAddress = getExistingReturnPath(originalMail);
        Collection newRecipients = new HashSet();
        if (returnAddress == SpecialAddress.NULL) {
            if (isDebug)
                log("Processing a bounce request for a message with an empty reverse-path.  No bounce will be sent.");
            if(!getPassThrough(originalMail)) {
                originalMail.setState(Mail.GHOST);
            }
            return;
        } else if (returnAddress == null) {
            log("WARNING: Mail to be bounced does not contain a reverse-path.");
        } else {
            if (isDebug)
                log("Processing a bounce request for a message with a return path header.  The bounce will be sent to " + returnAddress);
        }

        newRecipients.add(returnAddress);
        ((MailImpl)newMail).setRecipients(newRecipients);

        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 bounce message
        MimeMessage newMessage =
            new MimeMessage(Session.getDefaultInstance(System.getProperties(),
                                                       null));

        MimeMultipartReport multipart = new MimeMultipartReport ();
        multipart.setReportType ("delivery-status");
       
        // part 1: descripive text message
        MimeBodyPart part1 = createTextMsg(originalMail);
        multipart.addBodyPart(part1);

        // part 2: DSN
        MimeBodyPart part2 = createDSN(originalMail);
        multipart.addBodyPart(part2);


        // part 3: original mail (optional)
        if (getAttachmentType() != NONE) {
            MimeBodyPart part3 = createAttachedOriginal(originalMail);
            multipart.addBodyPart(part3);
        }


        // stuffing all together
        newMessage.setContent(multipart);
        newMessage.setHeader(RFC2822Headers.CONTENT_TYPE, multipart.getContentType());
        newMail.setMessage(newMessage);

        //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();
        getMailetContext().sendMail(newMail);

        // ghosting the original mail
        if(!getPassThrough(originalMail)) {
            originalMail.setState(Mail.GHOST);
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

        userMailbox = new ArrayList();
        userMailbox.add(DELETED);
        try {
            for (Iterator it = userInbox.list(); it.hasNext(); ) {
                String key = (String) it.next();
                Mail mc = userInbox.retrieve(key);
                // Retrieve can return null if the mail is no longer in the store.
                // In this case we simply continue to the next key
                if (mc == null) {
                    continue;
                }
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

     * @return item
     * @throws JMSException
     * @throws MessagingException
     */
    protected MailQueueItem createMailQueueItem(Connection connection, Session session, MessageConsumer consumer, Message message) throws JMSException, MessagingException {
        final Mail mail = createMail(message);
        return new JMSMailQueueItem(mail, connection, session, consumer);
    }
View Full Code Here

        try {
            mailRepository.store(mail);
        } catch (Exception e) {
            fail("Failed to store mail");
        }
        Mail m2 = mailRepository.retrieve((String) mailRepository.list().next());
       
        assertEquals("stored and retrieved messages do not match", mail.getMessage().getContent().toString(),m2.getMessage().getContent().toString());
        assertEquals("stored and retrieved message sizes do not match", mail.getMessageSize(), m2.getMessageSize());
        assertEquals("stored and retrieved keys do not match", mail.getName(), m2.getName());
        assertEquals("stored and retrieved states do not match", mail.getState(), m2.getState());
        assertEquals("stored and retrieved attributes do not match", mail.getAttribute("testAttribute"), m2.getAttribute("testAttribute"));
        LifecycleUtil.dispose(m2);
    }
View Full Code Here

     * http://issues.apache.org/jira/browse/JAMES-559
     */
    public void testJames559() throws Exception {
        mailRepository.store(mail);
       
        Mail m2 = mailRepository.retrieve("mail1");
        m2.getMessage().setHeader("X-Header", "foobar");
        m2.getMessage().saveChanges();
       
        mailRepository.store(m2);
        // ALWAYS remember to dispose mails!
        LifecycleUtil.dispose(m2);
       
        m2 = mailRepository.retrieve("mail1");
        assertEquals(mail.getMessage().getContent().toString(),m2.getMessage().getContent().toString());
       
        LifecycleUtil.dispose(mail);
        mail = null;
        LifecycleUtil.dispose(m2);
       
View Full Code Here

     * http://issues.apache.org/jira/browse/JAMES-559
     */
    public void testJames559WithoutSaveChanges() throws Exception {
        mailRepository.store(mail);
       
        Mail m2 = mailRepository.retrieve("mail1");
        m2.getMessage().setHeader("X-Header", "foobar");
       
        mailRepository.store(m2);
        // ALWAYS remember to dispose mails!
        LifecycleUtil.dispose(m2);
       
        m2 = mailRepository.retrieve("mail1");
        assertEquals(mail.getMessage().getContent().toString(),m2.getMessage().getContent().toString());
       
        LifecycleUtil.dispose(mail);
        mail = null;
       
        LifecycleUtil.dispose(m2);
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 false;
        }
        return true;
    }
View Full Code Here

    /*
     * (non-Javadoc)
     * @see org.apache.camel.Processor#process(org.apache.camel.Exchange)
     */
    public void process(Exchange arg0) throws Exception {
        Mail mail = arg0.getIn().getBody(Mail.class);
        LifecycleUtil.dispose(mail.getMessage());
        LifecycleUtil.dispose(mail);
       
        // stop routing
        arg0.setProperty(Exchange.ROUTE_STOP, true);

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.