Package org.apache.mailet

Examples of org.apache.mailet.Mailet


        f.delete();

    }

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

        // System.setProperty("mail.mime.decodefilename", "true");

        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("=?iso-8859-15?Q?=E9_++++Pubblicit=E0_=E9_vietata____Milano9052.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("temp.zip");
        mm.addBodyPart(mp3);
        message.setSubject("test");
        message.setContent(mm);
        message.saveChanges();

        // message.writeTo(System.out);
        // System.out.println("--------------------------\n\n\n");

        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


    }

    public void testToAndFromAttributes() throws MessagingException,
            IOException {
        Mailet strip = new StripAttachment();
        FakeMailetConfig mci = new FakeMailetConfig("Test",
                new FakeMailContext());
        mci.setProperty("attribute", "my.attribute");
        mci.setProperty("remove", "all");
        mci.setProperty("notpattern", ".*\\.tmp.*");
        strip.init(mci);

        Mailet recover = new RecoverAttachment();
        FakeMailetConfig mci2 = new FakeMailetConfig("Test",
                new FakeMailContext());
        mci2.setProperty("attribute", "my.attribute");
        recover.init(mci2);

        Mailet onlyText = new OnlyText();
        onlyText.init(new FakeMailetConfig("Test", new FakeMailContext()));

        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("=?iso-8859-15?Q?=E9_++++Pubblicit=E0_=E9_vietata____Milano9052.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);

        assertTrue(mail.getMessage().getContent() instanceof MimeMultipart);
        assertEquals(3, ((MimeMultipart) mail.getMessage().getContent())
                .getCount());

        strip.service(mail);

        assertTrue(mail.getMessage().getContent() instanceof MimeMultipart);
        assertEquals(1, ((MimeMultipart) mail.getMessage().getContent())
                .getCount());

        onlyText.service(mail);

        assertFalse(mail.getMessage().getContent() instanceof MimeMultipart);
       
        assertEquals("simple text", mail.getMessage().getContent());

View Full Code Here

        }

    }

    private Mailet initMailet() throws MessagingException {
        Mailet mailet = new StripAttachment();

        FakeMailetConfig mci = new FakeMailetConfig("Test",
                new FakeMailContext());
        mci.setProperty("directory", "./");
        mci.setProperty("remove", "all");
        mci.setProperty("pattern", ".*\\.tmp");
        mci.setProperty("decodeFilename", "true");
        mci.setProperty("replaceFilenamePattern",
                "/[\u00C0\u00C1\u00C2\u00C3\u00C4\u00C5]/A//,"
                        + "/[\u00C6]/AE//,"
                        + "/[\u00C8\u00C9\u00CA\u00CB]/E//,"
                        + "/[\u00CC\u00CD\u00CE\u00CF]/I//,"
                        + "/[\u00D2\u00D3\u00D4\u00D5\u00D6]/O//,"
                        + "/[\u00D7]/x//," + "/[\u00D9\u00DA\u00DB\u00DC]/U//,"
                        + "/[\u00E0\u00E1\u00E2\u00E3\u00E4\u00E5]/a//,"
                        + "/[\u00E6]/ae//,"
                        + "/[\u00E8\u00E9\u00EA\u00EB]/e//,"
                        + "/[\u00EC\u00ED\u00EE\u00EF]/i//,"
                        + "/[\u00F2\u00F3\u00F4\u00F5\u00F6]/o//,"
                        + "/[\u00F9\u00FA\u00FB\u00FC]/u//,"
                        + "/[^A-Za-z0-9._-]+/_//");

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

    }

    private String processAddFooter(String asciisource, String footer)
            throws MessagingException, IOException {
        Mailet mailet = new AddFooter();

        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" });
View Full Code Here

                    if (theClassLoader == null) {
                        theClassLoader = this.getClass().getClassLoader();
                    }

                    Mailet mailet = (Mailet) theClassLoader.loadClass(className).newInstance();
                    mailet.init(configImpl);
                    return mailet;
                } catch (ClassNotFoundException cnfe) {
                    //do this so we loop through all the packages
                }
            }
View Full Code Here

                for ( int j = 0; j < mailetConfs.length; j++ )
                {
                    Configuration c = mailetConfs[j];
                    String mailetClassName = c.getAttribute("class");
                    String matcherName = c.getAttribute("match");
                    Mailet mailet = null;
                    Matcher matcher = null;
                    try {
                        matcher = matchLoader.getMatcher(matcherName);
                        //The matcher itself should log that it's been inited.
                        if (getLogger().isInfoEnabled()) {
View Full Code Here

                try {
                    MailetConfigImpl configImpl = new MailetConfigImpl();
                    configImpl.setMailetName(mailetName);
                    configImpl.setConfiguration(configuration);
                    configImpl.setMailetContext(context);
                    Mailet mailet = (Mailet) mailetClassLoader.loadClass(className).newInstance();
                    mailet.init(configImpl);
                    return mailet;
                } catch (ClassNotFoundException cnfe) {
                    //do this so we loop through all the packages
                }
            }
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

        int i = 0;
        while(mailets.hasNext()) {
           
            MailetManagement mailetManagement;

            Mailet mailet = mailets.next();
           
            // 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

    public Mailet getMailet(final String mailetName, final Configuration configuration) throws MessagingException {
        try {
            for (final String packageName:packages) {
                final String className = packageName + mailetName;
                try {
                    final Mailet mailet = (Mailet)factory.newInstance(Thread.currentThread().getContextClassLoader().loadClass(className));
                   
                    final MailetConfigImpl configImpl = new MailetConfigImpl();
                    configImpl.setMailetName(mailetName);
                    configImpl.setConfiguration(configuration);
                    configImpl.setMailetContext(mailetContext);
                    mailet.init(configImpl);
                   
                    return mailet;
                } catch (ClassNotFoundException cnfe) {
                    //do this so we loop through all the packages
                }
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.