Package org.apache.james.mime4j.parser

Examples of org.apache.james.mime4j.parser.Field


  }

  @Override
  protected InputPart extractPart(BodyPart bodyPart) throws IOException {
    InputPart currPart = super.extractPart(bodyPart);
    Field disposition = bodyPart.getHeader().getField(
        FieldName.CONTENT_DISPOSITION);
    if (disposition == null)
      throw new RuntimeException(
          "Could find no Content-Disposition header within part");
    if (disposition instanceof ContentDispositionField) {
View Full Code Here


                    part.baseMediaType = stream.getBodyDescriptor().getMimeType();

                    break;
                case MimeTokenStream.T_FIELD:
                    if (multiPartNesting == 0) {
                        Field field = stream.getField();
                        ParsedField parsedField = new DefaultFieldParser().parse(field.getName(), MimeUtil.unfold(field.getBody()), null);
                        if (parsedField.getParseException() != null) {
                            // TODO print error
                        } else if (parsedField.getName().equals(FieldName.TO)) {
                            message.to = ((AddressListField)parsedField).getAddressList();
                        } else if (parsedField.getName().equals(FieldName.CC)) {
View Full Code Here

                writeBytes(TWO_DASHES, out);
                writeBytes(boundary, out);
                writeBytes(CR_LF, out);
                BodyPart part = bodyParts.get(i);
               
                Field cd = part.getHeader().getField(MIME.CONTENT_DISPOSITION);
               
                StringBuilder s = new StringBuilder();
                s.append(cd.getName());
                s.append(": ");
                s.append(cd.getBody());
                writeBytes(encode(charset, s.toString()), out);
                writeBytes(CR_LF, out);
                writeBytes(CR_LF, out);
                if (writeContent) {
                    MessageWriter.DEFAULT.writeBody(part.getBody(), out);
View Full Code Here

                writeBytes(TWO_DASHES, out);
                writeBytes(boundary, out);
                writeBytes(CR_LF, out);
                BodyPart part = bodyParts.get(i);
               
                Field cd = part.getHeader().getField(MIME.CONTENT_DISPOSITION);
               
                StringBuilder s = new StringBuilder();
                s.append(cd.getName());
                s.append(": ");
                s.append(cd.getBody());
                writeBytes(encode(charset, s.toString()), out);
                writeBytes(CR_LF, out);
                writeBytes(CR_LF, out);
                if (writeContent) {
                    MessageWriter.DEFAULT.writeBody(part.getBody(), out);
View Full Code Here

    public void testWriteSpecialCharacters() throws Exception {
        String hello = SWISS_GERMAN_HELLO;
        Header header = new Header();
        header.addField(AbstractField.parse("Hello: " + hello));
       
        Field field = header.getField("Hello");
        assertNotNull(field);
        assertEquals(hello, field.getBody());
       
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
       
        MessageWriter.DEFAULT.writeHeader(header, buffer);
        String s = buffer.toString(CharsetUtil.US_ASCII.name());
View Full Code Here

        assertEquals(original, bodyPart2.getParent());
        assertEquals(copy, bodyPartCopy2.getParent());
    }

    public void testCopyHeader() throws Exception {
        Field f1 = AbstractField.parse("name1: value1");
        Field f2 = AbstractField.parse("name2: value");
        Field f3 = AbstractField.parse("name1: value2");

        Header original = new Header();
        original.addField(f1);
        original.addField(f2);
        original.addField(f3);
View Full Code Here

                .getRaw()));
        assertEquals(new Date(millis), field.getDate());
    }

    public void testMessageId() throws Exception {
        Field messageId = Fields.messageId("acme.org");

        String raw = ContentUtil.decode(messageId.getRaw());
        assertTrue(raw.startsWith("Message-ID: <Mime4j."));
        assertTrue(raw.endsWith("@acme.org>"));
    }
View Full Code Here

import junit.framework.TestCase;

public class FieldTest extends TestCase {

    public void testGetName() throws Exception {
        Field f = null;
       
        f = AbstractField.parse("Subject: Yada yada yada");
        assertEquals("Testing simple field", "Subject", f.getName());
       
        f = AbstractField.parse("X-yada-yada: Yada yada yada");
        assertEquals("Testing an X- field", "X-yada-yada", f.getName());
       
        try {
            f = AbstractField.parse("Yada yada yada");
            fail("MimeException not thrown when using an invalid field");
        } catch (MimeException e) {
View Full Code Here

        } catch (MimeException e) {
        }
    }

    public void testParse() throws Exception {
        Field f = null;
       
        f = AbstractField.parse("Subject: Yada yada yada");
        assertTrue("Field should be UnstructuredField",
                        f instanceof UnstructuredField);
        f = AbstractField.parse("Content-Type: text/plain");
View Full Code Here

        List<Field> removed = fieldMap.remove(lowerCaseName);
        if (removed == null || removed.isEmpty())
            return 0;

        for (Iterator<Field> iterator = fields.iterator(); iterator.hasNext();) {
            Field field = iterator.next();
            if (field.getName().equalsIgnoreCase(name))
                iterator.remove();
        }

        return removed.size();
    }
View Full Code Here

TOP

Related Classes of org.apache.james.mime4j.parser.Field

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.