Package org.apache.mailet

Examples of org.apache.mailet.Mailet


        Iterator<List<MailetManagement>> it = mailets.values().iterator();
        while (it.hasNext()) {
            List<MailetManagement> mList = it.next();
            for (int i = 0; i < mList.size(); i++) {
                Mailet m = mList.get(i).getMailet();
                if (debugEnabled) {
                    logger.debug("Shutdown mailet " + m.getMailetInfo());
                }
                m.destroy();
            }
          
        }
       
        Iterator<List<MatcherManagement>> mit = matchers.values().iterator();    
        while (mit.hasNext()) {
            List<MatcherManagement> mList = mit.next();
            for (int i = 0; i < mList.size(); i++) {
                Matcher m = mList.get(i);
                if (debugEnabled) {
                    logger.debug("Shutdown matcher " + m.getMatcherInfo());
                }
                m.destroy();
            }
          
        }     
    }
View Full Code Here


                    // We need to set this because of correctly parsing comma
                    String mailetClassName = c.getString("[@class]");
                    String matcherName = c.getString("[@match]", null);
                    String invertedMatcherName = c.getString("[@notmatch]", null);
               
                    Mailet mailet = null;
                    Matcher matcher = null;
                    try {

                        if (matcherName != null && invertedMatcherName != null) {
                            // if no matcher is configured throw an Exception
View Full Code Here

            List<Mailet> mailets =  container.getMailets();
        
            for (int i = 0; i < mailets.size(); i++) {
                MailetManagement mailetManagement;

                Mailet mailet = mailets.get(i);
               
                // check if the mailet is an instance of MailetManagement. If not create a wrapper around it. This will give us not all
                // statistics but at least a few of them
                if (mailet instanceof MailetManagement) {
                    mailetManagement = (MailetManagement) mailet;
View Full Code Here

     *
     * @throws MessagingException
     * @throws IOException
     */
    public void testService() throws MessagingException, IOException {
        Mailet mailet;
        FakeMailetConfig mci;
        MimeMessage message;
        Mail mail;

        mailet = new OnlyText();
        mci = new FakeMailetConfig("Test", new FakeMailContext());
        mailet.init(mci);

        // ----------------

        message = new MimeMessage(Session.getDefaultInstance(new Properties()));
        message.setSubject("prova");
        message.setText("Questa \u00E8 una prova");
        message.saveChanges();

        mail = new FakeMail(message);
        mailet.service(mail);

        assertEquals("prova", mail.getMessage().getSubject());
        assertEquals("Questa \u00E8 una prova", mail.getMessage().getContent());

        // -----------------

        message = new MimeMessage(Session.getDefaultInstance(new Properties()));
        message.setSubject("prova");
        MimeMultipart mp = new MimeMultipart();
        MimeBodyPart bp = new MimeBodyPart();
        bp.setText("Questo \u00E8 un part interno1");
        mp.addBodyPart(bp);
        bp = new MimeBodyPart();
        bp.setText("Questo \u00E8 un part interno2");
        mp.addBodyPart(bp);
        bp = new MimeBodyPart();
        MimeMessage message2 = new MimeMessage(Session
                .getDefaultInstance(new Properties()));
        bp.setContent(message2, "message/rfc822");
        mp.addBodyPart(bp);
        message.setContent(mp);
        message.saveChanges();

        mail = new FakeMail(message);
        mailet.service(mail);

        assertEquals("prova", mail.getMessage().getSubject());
        assertEquals("Questo \u00E8 un part interno1", mail.getMessage()
                .getContent());

        // -----------------

        message = new MimeMessage(Session.getDefaultInstance(new Properties()));
        message.setSubject("prova");
        mp = new MimeMultipart();
        bp = new MimeBodyPart();
        bp.setText("Questo \u00E8 un part interno1");
        mp.addBodyPart(bp);
        bp = new MimeBodyPart();
        bp.setText("Questo \u00E8 un part interno2");
        mp.addBodyPart(bp);
        bp = new MimeBodyPart();
        message2 = new MimeMessage(Session.getDefaultInstance(new Properties()));
        bp.setContent(message2, "message/rfc822");
        mp.addBodyPart(bp);

        MimeMultipart mpext = new MimeMultipart();
        bp = new MimeBodyPart();
        bp.setContent(mp);
        mpext.addBodyPart(bp);

        message.setContent(mpext);
        message.saveChanges();

        mail = new FakeMail(message);
        mailet.service(mail);

        assertEquals("prova", mail.getMessage().getSubject());
        assertEquals("Questo \u00E8 un part interno1", mail.getMessage()
                .getContent());

        // ---------------------

        message = new MimeMessage(Session.getDefaultInstance(new Properties()));
        message.setSubject("prova");
        message.setContent("<p>Questa \u00E8 una prova<br />di html</p>",
                "text/html");
        message.saveChanges();

        mail = new FakeMail(message);
        mailet.service(mail);

        assertEquals("prova", mail.getMessage().getSubject());
        assertEquals("Questa \u00E8 una prova\ndi html\n", mail.getMessage()
                .getContent());
        assertTrue(mail.getMessage().isMimeType("text/plain"));

        // -----------------

        message = new MimeMessage(Session.getDefaultInstance(new Properties()));
        message.setSubject("prova");
        mp = new MimeMultipart();
        bp = new MimeBodyPart();
        message2 = new MimeMessage(Session.getDefaultInstance(new Properties()));
        bp.setContent(message2, "message/rfc822");
        mp.addBodyPart(bp);
        bp = new MimeBodyPart();
        bp.setContent("<p>Questa \u00E8 una prova<br />di html</p>", "text/html");
        mp.addBodyPart(bp);
        message.setContent(mp);
        message.saveChanges();

        mail = new FakeMail(message);
        mailet.service(mail);

        assertEquals("prova", mail.getMessage().getSubject());
        assertEquals("Questa \u00E8 una prova\ndi html\n", mail.getMessage()
                .getContent());
        assertTrue(mail.getMessage().isMimeType("text/plain"));
View Full Code Here

        mockedMail.setAttribute(MAIL_ATTRIBUTE_NAME2, "true");
        return mockedMail;
    }

    private Mailet setupMailet(String attribute) throws MessagingException {
        Mailet mailet = new RemoveMailAttribute();
        FakeMailetConfig mci = new FakeMailetConfig("Test",
                new FakeMailContext());
        if (attribute != null) {
            mci.setProperty("name", attribute);
        }

        mailet.init(mci);
        return mailet;
    }
View Full Code Here

    }


    public void testRemoveMailAttribute() throws MessagingException {
        Mail m = setupMockedMail();
        Mailet mailet = setupMailet(MAIL_ATTRIBUTE_NAME1);

        // check if the mail has a attribute
        assertNotNull("Attribute exists",m.getAttribute(MAIL_ATTRIBUTE_NAME1));
        assertNotNull("Attribute exists",m.getAttribute(MAIL_ATTRIBUTE_NAME2));

        mailet.service(m);

        // Check if the attribute was removed
        assertNull("Attribute exists",m.getAttribute(MAIL_ATTRIBUTE_NAME1));
        assertNotNull("Attribute deleted",m.getAttribute(MAIL_ATTRIBUTE_NAME2));
    }
View Full Code Here

import junit.framework.TestCase;

public class ReplaceContentTest extends TestCase {

    public void testService() throws MessagingException, IOException {
        Mailet mailet;
        FakeMailetConfig mci;
        MimeMessage message;
        Mail mail;

        mailet = new ReplaceContent();
        mci = new FakeMailetConfig("Test", new FakeMailContext());
        mci.setProperty("subjectPattern", "/prova/PROVA/i/,/a/e//,/o/o/i/");
        mci.setProperty("bodyPattern", "/prova/PROVA/i/," + "/a/e//,"
                + "/o/o/i/,/\\u00E8/e'//," + "/prova([^\\/]*?)ble/X$1Y/im/,"
                + "/X(.\\n)Y/P$1Q//," + "/\\/\\/,//");
        mailet.init(mci);

        message = new MimeMessage(Session.getDefaultInstance(new Properties()));
        message.setSubject("una prova");
        message
                .setText("Sto facendo una prova di scrittura/ \u00E8 solo una prova.\n"
                        + "Bla bla bla bla.\n");

        mail = new FakeMail(message);
        mailet.service(mail);

        assertEquals("une PRoVA", mail.getMessage().getSubject());
        assertEquals("Sto fecendo une PRoVA di scritture, e' solo une P.\n"
                + "Q ble ble ble.\n", mail.getMessage().getContent());

        // ------------------

        mailet = new ReplaceContent();
        mci = new FakeMailetConfig("Test", new FakeMailContext());
        mci
                .setProperty("subjectPatternFile",
                        "#/org/apache/james/transport/mailets/replaceSubject.patterns");
        mailet.init(mci);

        message = new MimeMessage(Session.getDefaultInstance(new Properties()));
        message.setSubject("re: r:ri:una prova");
        message
                .setText("Sto facendo una prova di scrittura/ \u00E8 solo una prova.\n"
                        + "Bla bla bla bla.\n");

        mail = new FakeMail(message);
        mailet.service(mail);

        assertEquals("Re: Re: Re: una prova", mail.getMessage()
                .getSubject());

        // ------------------

        mailet = new ReplaceContent();
        mci = new FakeMailetConfig("Test", new FakeMailContext());
        mci.setProperty("bodyPattern", "/--messaggio originale--/<quote>/i/,"
                +
                // "/<quote>([^\\0]*)(\\r\\n)([^>]+)/<quote>$1$2>$3/imr/,"+
                "/<quote>(.*)(\\r\\n)([^>]+)/<quote>$1$2>$3/imrs/,"
                + "/<quote>\\r\\n//im/");
        mailet.init(mci);

        message = new MimeMessage(Session.getDefaultInstance(new Properties()));
        message.setSubject("una prova");
        message.setText("Prova.\r\n" + "\r\n" + "--messaggio originale--\r\n"
                + "parte del\r\n" + "messaggio\\ che\\0 deve0 essere\r\n"
                + "quotato. Vediamo se\r\n" + "ce la fa.");

        mail = new FakeMail(message);
        mailet.service(mail);

        assertEquals("una prova", mail.getMessage().getSubject());
        assertEquals("Prova.\r\n" + "\r\n" + ">parte del\r\n"
                + ">messaggio\\ che\\0 deve0 essere\r\n"
                + ">quotato. Vediamo se\r\n" + ">ce la fa.", mail.getMessage()
                .getContent());

        // ------------------

        mailet = new ReplaceContent();
        mci = new FakeMailetConfig("Test", new FakeMailContext());
        mci.setProperty("bodyPattern", "/\\u2026/...//");
        mailet.init(mci);

        message = new MimeMessage(Session.getDefaultInstance(new Properties()));
        message.setSubject("una prova");
        message.setText("Prova \u2026 di replace \u2026");

        mail = new FakeMail(message);
        mailet.service(mail);

        assertEquals("una prova", mail.getMessage().getSubject());
        assertEquals("Prova ... di replace ...", mail.getMessage().getContent());
    }
View Full Code Here

        String messageSource = "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"
                + "Content-Transfer-Encoding: quoted-printable\r\n"
                + "\r\n"
                + "=93prova=94 con l=92apice";

        Mailet mailet;
        FakeMailetConfig mci;
        MimeMessage message;
        Mail mail;

        mailet = new ReplaceContent();
        mci = new FakeMailetConfig("Test", new FakeMailContext());
        mci.setProperty("bodyPattern", "/[\\u2018\\u2019\\u201A]/'//,"
                + "/[\\u201C\\u201D\\u201E]/\"//," + "/[\\x91\\x92\\x82]/'//,"
                + "/[\\x93\\x94\\x84]/\"//," + "/\\x85/...//," + "/\\x8B/<//,"
                + "/\\x9B/>//," + "/\\x96/-//," + "/\\x97/--//,");
        mailet.init(mci);

        message = new MimeMessage(Session.getDefaultInstance(new Properties()),
                new ByteArrayInputStream(messageSource.getBytes()));

        mail = new FakeMail(message);
        mailet.service(mail);

        assertEquals("\"prova\" con l'apice", mail.getMessage().getContent());

    }
View Full Code Here

    public void testNoAttachment() {

    }

    public void testSimpleAttachment() throws MessagingException, IOException {
        Mailet mailet = initMailet();

        MimeMessage message = new MimeMessage(Session
                .getDefaultInstance(new Properties()));

        MimeMultipart mm = new MimeMultipart();
        MimeBodyPart mp = new MimeBodyPart();
        mp.setText("simple text");
        mm.addBodyPart(mp);
        String body = "\u0023\u00A4\u00E3\u00E0\u00E9";
        MimeBodyPart mp2 = new MimeBodyPart(new ByteArrayInputStream(
                ("Content-Transfer-Encoding: 8bit\r\nContent-Type: application/octet-stream; charset=utf-8\r\n\r\n" + body).getBytes("UTF-8")));
        mp2.setDisposition("attachment");
        mp2.setFileName("10.tmp");
        mm.addBodyPart(mp2);
        String body2 = "\u0014\u00A3\u00E1\u00E2\u00E4";
        MimeBodyPart mp3 = new MimeBodyPart(new ByteArrayInputStream(
                ("Content-Transfer-Encoding: 8bit\r\nContent-Type: application/octet-stream; charset=utf-8\r\n\r\n" + body2).getBytes("UTF-8")));
        mp3.setDisposition("attachment");
        mp3.setFileName("temp.zip");
        mm.addBodyPart(mp3);
        message.setSubject("test");
        message.setContent(mm);
        message.saveChanges();

        Mail mail = new FakeMail();
        mail.setMessage(message);

        mailet.service(mail);

        ByteArrayOutputStream rawMessage = new ByteArrayOutputStream();
        mail.getMessage().writeTo(rawMessage,
                new String[] { "Bcc", "Content-Length", "Message-ID" });
View Full Code Here

        }
        return sw.toString("UTF-8");
    }

    public void testSimpleAttachment2() throws MessagingException, IOException {
        Mailet mailet = new StripAttachment();

        FakeMailetConfig mci = new FakeMailetConfig("Test",
                new FakeMailContext());
        mci.setProperty("directory", "./");
        mci.setProperty("remove", "all");
        mci.setProperty("notpattern", "^(winmail\\.dat$)");
        mailet.init(mci);

        MimeMessage message = new MimeMessage(Session
                .getDefaultInstance(new Properties()));

        MimeMultipart mm = new MimeMultipart();
        MimeBodyPart mp = new MimeBodyPart();
        mp.setText("simple text");
        mm.addBodyPart(mp);
        String body = "\u0023\u00A4\u00E3\u00E0\u00E9";
        MimeBodyPart mp2 = new MimeBodyPart(new ByteArrayInputStream(
                ("Content-Transfer-Encoding: 8bit\r\n\r\n" + body).getBytes("UTF-8")));
        mp2.setDisposition("attachment");
        mp2.setFileName("temp.tmp");
        mm.addBodyPart(mp2);
        String body2 = "\u0014\u00A3\u00E1\u00E2\u00E4";
        MimeBodyPart mp3 = new MimeBodyPart(new ByteArrayInputStream(
                ("Content-Transfer-Encoding: 8bit\r\n\r\n" + body2).getBytes("UTF-8")));
        mp3.setDisposition("attachment");
        mp3.setFileName("winmail.dat");
        mm.addBodyPart(mp3);
        message.setSubject("test");
        message.setContent(mm);
        message.saveChanges();

        Mail mail = new FakeMail();
        mail.setMessage(message);

        mailet.service(mail);

        ByteArrayOutputStream rawMessage = new ByteArrayOutputStream();
        mail.getMessage().writeTo(rawMessage,
                new String[] { "Bcc", "Content-Length", "Message-ID" });
        // String res = rawMessage.toString();
View Full Code Here

TOP

Related Classes of org.apache.mailet.Mailet

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.