Package org.apache.james.mime4j.message

Examples of org.apache.james.mime4j.message.Message$MessageBuilder


        this.contentType = new BasicHeader(
                HTTP.CONTENT_TYPE,
                generateContentType(boundary, charset));
        this.dirty = true;
       
        Message message = new Message();
        org.apache.james.mime4j.message.Header header = new RFC822Header();
        header.addField(
                Field.parse("Content-Type: " + this.contentType.getValue()));
        message.setHeader(header);
        this.multipart.setParent(message);
        if (mode == null) {
            mode = HttpMultipartMode.STRICT;
        }
        this.multipart.setMode(mode);
View Full Code Here


    public static Test suite() {
        return new TestSuite(TestMultipartForm.class);
    }

    public void testMultipartFormLowLevel() throws Exception {
        Message message = new Message();
        Header header = new Header();
        header.addField(
                Field.parse("Content-Type: multipart/form-data; boundary=foo"));
        message.setHeader(header);
       
        HttpMultipart multipart = new HttpMultipart();
        multipart.setParent(message);
        BodyPart p1 = new BodyPart();
        Header h1 = new Header();
View Full Code Here

        assertEquals(expected, s);
        assertEquals(s.length(), multipart.getTotalLength());
    }
   
    public void testMultipartFormStringParts() throws Exception {
        Message message = new Message();
        Header header = new Header();
        header.addField(
                Field.parse("Content-Type: multipart/form-data; boundary=foo"));
        message.setHeader(header);
       
        HttpMultipart multipart = new HttpMultipart();
        multipart.setParent(message);
        FormBodyPart p1 = new FormBodyPart(
                "field1",
View Full Code Here

        assertEquals(expected, s);
        assertEquals(s.length(), multipart.getTotalLength());
    }

    public void testMultipartFormBinaryParts() throws Exception {
        Message message = new Message();
        Header header = new Header();
        header.addField(
                Field.parse("Content-Type: multipart/form-data; boundary=foo"));
        message.setHeader(header);

        File tmpfile = File.createTempFile("tmp", ".bin");
        tmpfile.deleteOnExit();
        Writer writer = new FileWriter(tmpfile);
        try {
View Full Code Here

       
        tmpfile.delete();
    }

    public void testMultipartFormBrowserCompatible() throws Exception {
        Message message = new Message();
        Header header = new Header();
        header.addField(
                Field.parse("Content-Type: multipart/form-data; boundary=foo"));
        message.setHeader(header);

        File tmpfile = File.createTempFile("tmp", ".bin");
        tmpfile.deleteOnExit();
        Writer writer = new FileWriter(tmpfile);
        try {
View Full Code Here

    public void testMultipartFormBrowserCompatibleNonASCIIHeaders() throws Exception {
        String s1 = constructString(SWISS_GERMAN_HELLO);
        String s2 = constructString(RUSSIAN_HELLO);

        Message message = new Message();
        Header header = new Header();
        header.addField(
                Field.parse("Content-Type: multipart/form-data; charset=UTF-8; boundary=foo"));
        message.setHeader(header);

        File tmpfile = File.createTempFile("tmp", ".bin");
        tmpfile.deleteOnExit();
        Writer writer = new FileWriter(tmpfile);
        try {
View Full Code Here

    public void testMultipartFormStringPartsMultiCharsets() throws Exception {
        String s1 = constructString(SWISS_GERMAN_HELLO);
        String s2 = constructString(RUSSIAN_HELLO);
       
        Message message = new Message();
        Header header = new Header();
        header.addField(
                Field.parse("Content-Type: multipart/form-data; boundary=foo"));
        message.setHeader(header);
       
        HttpMultipart multipart = new HttpMultipart();
        multipart.setParent(message);
        FormBodyPart p1 = new FormBodyPart(
                "field1",
View Full Code Here

        this.contentType = new BasicHeader(
                HTTP.CONTENT_TYPE,
                generateContentType(boundary, charset));
        this.dirty = true;
       
        this.message = new Message();
        org.apache.james.mime4j.message.Header header =
          new org.apache.james.mime4j.message.Header();
        this.message.setHeader(header);
        this.multipart.setParent(message);
        if (mode == null) {
View Full Code Here

    }
   
    public static void main(String[] args) {
        try {
           
            final Message message = new Message(new FileInputStream(args[0]));
           
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI(message);
                }
View Full Code Here

        BasicConfigurator.resetConfiguration();
        BasicConfigurator.configure();
    }
  
    protected void runTest() throws Throwable {
        Message inputMessage = new Message(new FileInputStream(file));
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        inputMessage.writeTo(out, MessageUtils.LENIENT);
       
        String msgoutFile = file.getAbsolutePath().substring(0, file.getAbsolutePath().lastIndexOf('.')) + ".out";
        String msgoutFileMime4j = file.getAbsolutePath().substring(0, file.getAbsolutePath().lastIndexOf('.')) + ".mime4j.out";
       
        try {
            ByteArrayOutputStream expectedstream = new ByteArrayOutputStream();
            CodecUtil.copy(new FileInputStream(msgoutFile), expectedstream);
            assertEquals("Wrong Expected result", new String(expectedstream.toByteArray()), new String(out.toByteArray()));
           
            Message roundtripMessage = new Message(new FileInputStream(msgoutFile));
            ByteArrayOutputStream outRoundtrip = new ByteArrayOutputStream();
            roundtripMessage.writeTo(outRoundtrip, MessageUtils.LENIENT);
            assertEquals("Failed LENIENT roundtrip", new String(out.toByteArray()), new String(outRoundtrip.toByteArray()));

            roundtripMessage = new Message(new FileInputStream(msgoutFile));
            outRoundtrip = new ByteArrayOutputStream();
            roundtripMessage.writeTo(outRoundtrip, MessageUtils.STRICT_ERROR);
            assertEquals("Failed STRICT roundtrip", new String(out.toByteArray()), new String(outRoundtrip.toByteArray()));

        } catch (FileNotFoundException e) {
            FileOutputStream fos = new FileOutputStream(msgoutFileMime4j);
            fos.write(out.toByteArray());
View Full Code Here

TOP

Related Classes of org.apache.james.mime4j.message.Message$MessageBuilder

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.