Package org.apache.james.mime4j.dom.field

Examples of org.apache.james.mime4j.dom.field.ContentTypeField


            } else if (o instanceof ContentTypeField) {
                /*
                 * Content-Type field.
                 */
                ContentTypeField field = (ContentTypeField) o;
                StringBuilder sb = new StringBuilder();
                sb.append("MIME type: " + field.getMimeType() + "\n");
                for (Map.Entry<String, String> entry : field.getParameters().entrySet()) {
                    sb.append(entry.getKey() + " = " + entry.getValue() + "\n");
                }
                textView.setText(sb.toString());

            } else if (o instanceof AddressListField) {
                /*
                 * An address field (From, To, Cc, etc)
                 */
                AddressListField field = (AddressListField) o;
                MailboxList list = field.getAddressList().flatten();
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < list.size(); i++) {
                    Mailbox mb = list.get(i);
                    sb.append(AddressFormatter.DEFAULT.format(mb, false) + "\n");
                }
View Full Code Here


        RawField rawField = RawFieldParser.DEFAULT.parseField(raw);
        return ContentTypeFieldImpl.PARSER.parse(rawField, null);
    }

    public void testMimeTypeWithSemiColonNoParams() throws Exception  {
        ContentTypeField f = parse("Content-Type: text/html;");
        assertEquals("text/html", f.getMimeType());
    }
View Full Code Here

        ContentTypeField f = parse("Content-Type: text/html;");
        assertEquals("text/html", f.getMimeType());
    }

    public void testGetMimeType() throws Exception {
        ContentTypeField f = parse("Content-Type: text/PLAIN");
        assertEquals("text/plain", f.getMimeType());

        f = parse("content-type:   TeXt / html   ");
        assertEquals("text/html", f.getMimeType());

        f = parse("CONTENT-TYPE:   x-app/yada ;"
                                                    + "  param = yada");
        assertEquals("x-app/yada", f.getMimeType());

        f = parse("CONTENT-TYPE:   yada");
        assertEquals(null, f.getMimeType());
    }
View Full Code Here

        f = parse("CONTENT-TYPE:   yada");
        assertEquals(null, f.getMimeType());
    }

    public void testGetMimeTypeStatic() throws Exception {
        ContentTypeField child = parse("Content-Type: child/type");;
        ContentTypeField parent = parse("Content-Type: parent/type");

        assertEquals("child/type", ContentTypeFieldImpl.getMimeType(child, parent));

        child = null;
        parent = parse("Content-Type: parent/type");
View Full Code Here

        parent = parse("Content-Type: multipart/digest");
        assertEquals("message/rfc822", ContentTypeFieldImpl.getMimeType(child, parent));
    }

    public void testGetCharsetStatic() throws Exception {
        ContentTypeField f = parse("Content-Type: some/type; charset=iso8859-1");
        assertEquals("iso8859-1", ContentTypeFieldImpl.getCharset(f));

        f = parse("Content-Type: some/type;");
        assertEquals("us-ascii", ContentTypeFieldImpl.getCharset(f));
    }
View Full Code Here

        f = parse("Content-Type: some/type;");
        assertEquals("us-ascii", ContentTypeFieldImpl.getCharset(f));
    }

    public void testGetParameter() throws Exception {
        ContentTypeField f = parse("CONTENT-TYPE:   text / html ;"
                                                + "  boundary=yada yada");
        assertEquals("yada", f.getParameter("boundary"));

        f = parse("Content-Type: x-app/yada;"
                                                + "  boUNdarY= \"ya:\\\"*da\"; "
                                                + "\tcharset\t =  us-ascii");
        assertEquals("ya:\"*da", f.getParameter("boundary"));
        assertEquals("us-ascii", f.getParameter("charset"));

        f = parse("Content-Type: x-app/yada;  "
                            + "boUNdarY= \"ya \\\"\\\"\tda \\\"\"; "
                            + "\tcharset\t =  \"\\\"hepp\\\"  =us\t-ascii\"");
        assertEquals("ya \"\"\tda \"", f.getParameter("boundary"));
        assertEquals("\"hepp\"  =us\t-ascii", f.getParameter("charset"));
    }
View Full Code Here

        String actualMimeType = null;
        String actualMediaType = null;
        String actualSubType = null;
        String actualCharset = null;
        String actualBoundary = null;
        ContentTypeField contentTypeField = (ContentTypeField) fields.get(CONTENT_TYPE);
        if (contentTypeField != null) {
            actualMimeType = contentTypeField.getMimeType();
            actualMediaType = contentTypeField.getMediaType();
            actualSubType = contentTypeField.getSubType();
            actualCharset = contentTypeField.getCharset();
            actualBoundary = contentTypeField.getBoundary();
        }
        if (actualMimeType == null) {
            if (MimeUtil.isSameMimeType("multipart/digest", parentMimeType)) {
                actualMimeType = EMAIL_MESSAGE_MIME_TYPE;
                actualMediaType = MEDIA_TYPE_MESSAGE;
View Full Code Here

                fields);
    }

    public BodyDescriptorBuilder newChild() {
        String actualMimeType;
        ContentTypeField contentTypeField = (ContentTypeField) fields.get(CONTENT_TYPE);
        if (contentTypeField != null) {
            actualMimeType = contentTypeField.getMimeType();
        } else {
            if (MimeUtil.isSameMimeType("multipart/digest", parentMimeType)) {
                actualMimeType = EMAIL_MESSAGE_MIME_TYPE;
            } else {
                actualMimeType = DEFAULT_MIME_TYPE;
View Full Code Here

     * @throws IOException
     *             if an I/O error occurs.
     */
    public void writeMultipart(Multipart multipart, OutputStream out)
            throws IOException {
        ContentTypeField contentType = getContentType(multipart);

        ByteSequence boundary = getBoundary(contentType);

        ByteSequence preamble;
        ByteSequence epilogue;
View Full Code Here

        Header header = parent.getHeader();
        if (header == null)
            throw new IllegalArgumentException(
                    "Missing header in parent entity");

        ContentTypeField contentType = (ContentTypeField) header
                .getField(FieldName.CONTENT_TYPE);
        if (contentType == null)
            throw new IllegalArgumentException(
                    "Content-Type field not specified");
View Full Code Here

TOP

Related Classes of org.apache.james.mime4j.dom.field.ContentTypeField

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.