Package org.apache.mailet

Examples of org.apache.mailet.Mail


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


                + "=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

        mockedMimeMessage.saveChanges();
        return mockedMimeMessage;
    }
   
    private Mail getMockedMail(MimeMessage message) {
        Mail m = new FakeMail();
        m.setMessage(message);
        return m;
    }
View Full Code Here

        return m;
    }
   
    public void testOneHeaderRemoved() throws MessagingException {
        GenericMailet mailet = setupMockedMailet(HEADER1,null);
        Mail mail = getMockedMail(getMockedMimeMessage());
   
        // Get sure both headers are present
        assertNotNull("Header present",mail.getMessage().getHeader(HEADER1));
        assertNotNull("Header present",mail.getMessage().getHeader(HEADER2));
   
        mailet.service(mail);
   
        // The first header should be removed
        assertNull("Header removed",mail.getMessage().getHeader(HEADER1));
        assertNotNull("Header present",mail.getMessage().getHeader(HEADER2));
    }
View Full Code Here

    protected void setSender(MailAddress sender) {
        this.sender = sender;
    }

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

            private static final long serialVersionUID = 1L;

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

        FakeMailetConfig mci = new FakeMailetConfig("Test",new FakeMailContext());
        mci.setProperty("text",footer);

        mailet.init(mci);

        Mail mail = new FakeMail();
        mail.setMessage(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" });
        return rawMessage.toString();
    }
View Full Code Here

        mailet.init(mci);
    }

    // test if the Header was add
    public void testMailAttributeAdded() throws MessagingException {
        Mail mockedMail = MailUtil.createMockMail2Recipients(null);
        setupMailet();

        assertNull(mockedMail.getAttribute(ATTRIBUTE_NAME1));
        assertNull(mockedMail.getAttribute(ATTRIBUTE_NAME2));
        mailet.service(mockedMail);

        assertEquals("true", mockedMail.getAttribute(ATTRIBUTE_NAME1));
        assertEquals("true", mockedMail.getAttribute(ATTRIBUTE_NAME2));
    }
View Full Code Here

     *
     * @throws MessagingException
     */
    public void testExecuteActionKeep() throws MessagingException {
        boolean isTestPassed = false;
        Mail aMail = new MailImpl();
        aMail.setRecipients(Arrays.asList(new MailAddress[] { new MailAddress(
                "a", "a.com") }));
        MimeMessage mimeMessage = new MimeMessage(Session
                .getDefaultInstance(new Properties()));
        mimeMessage.setText("TEST");
        aMail.setMessage(mimeMessage);
        MailetContext aMailetContext = new MockMailetContext();
        Action action = new ActionKeep();
        try {
            ActionDispatcher.getInstance().execute(action, aMail,
                    aMailetContext);
View Full Code Here

    /**
     * Test execute of ActionAbsent. Should throw a NoSuchMethodException.
     */
    public void testExecuteActionAbsent() {
        boolean isTestPassed = false;
        Mail aMail = new MailImpl();
        MailetContext aMailetContext = new MockMailetContext();
        Action action = new ActionAbsent();
        try {
            ActionDispatcher.getInstance().execute(action, aMail,
                    aMailetContext);
View Full Code Here

    public String toString() {
        return "MailQueue:" + queuename;
    }

    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

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.