You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mime4j-dev@james.apache.org by ol...@apache.org on 2013/05/14 12:51:32 UTC
svn commit: r1482294 - in /james/mime4j/trunk:
core/src/main/java/org/apache/james/mime4j/parser/
core/src/main/java/org/apache/james/mime4j/stream/
core/src/test/java/org/apache/james/mime4j/
core/src/test/java/org/apache/james/mime4j/stream/ dom/src/...
Author: olegk
Date: Tue May 14 10:51:32 2013
New Revision: 1482294
URL: http://svn.apache.org/r1482294
Log:
Made MimeConfig immutable
Modified:
james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/MimeStreamParser.java
james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeConfig.java
james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeEntity.java
james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeTokenStream.java
james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/ExampleMessageTestCase.java
james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MimeEntityTest.java
james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/StrictMimeTokenStreamTest.java
james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/DefaultMessageBuilder.java
james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageHeadlessParserTest.java
james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/MaximalBodyDescriptorTest.java
Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/MimeStreamParser.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/MimeStreamParser.java?rev=1482294&r1=1482293&r2=1482294&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/MimeStreamParser.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/parser/MimeStreamParser.java Tue May 14 10:51:32 2013
@@ -69,7 +69,7 @@ public class MimeStreamParser {
final MimeConfig config,
final DecodeMonitor monitor,
final BodyDescriptorBuilder bodyDescBuilder) {
- this(new MimeTokenStream(config != null ? config.clone() : new MimeConfig(),
+ this(new MimeTokenStream(config != null ? config : MimeConfig.DEFAULT,
monitor, bodyDescBuilder));
}
@@ -78,7 +78,7 @@ public class MimeStreamParser {
}
public MimeStreamParser() {
- this(new MimeTokenStream(new MimeConfig(), null, null));
+ this(new MimeTokenStream(MimeConfig.DEFAULT, null, null));
}
/**
Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeConfig.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeConfig.java?rev=1482294&r1=1482293&r2=1482294&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeConfig.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeConfig.java Tue May 14 10:51:32 2013
@@ -24,26 +24,40 @@ import org.apache.james.mime4j.MimeExcep
/**
* Properties used to configure the behavior of MIME stream parsers.
*/
-public final class MimeConfig implements Cloneable {
+public final class MimeConfig {
- private boolean strictParsing;
- private int maxLineLen;
- private int maxHeaderCount;
- private int maxHeaderLen;
- private long maxContentLen;
- private boolean countLineNumbers;
- private String headlessParsing;
- private boolean malformedHeaderStartsBody;
-
- public MimeConfig() {
- this.strictParsing = false;
- this.countLineNumbers = false;
- this.malformedHeaderStartsBody = false;
- this.maxLineLen = 1000;
- this.maxHeaderCount = 1000;
- this.maxHeaderLen = 10000;
- this.maxContentLen = -1;
- this.headlessParsing = null;
+ public static final MimeConfig DEFAULT = new Builder().build();
+ public static final MimeConfig STRICT = new Builder()
+ .setStrictParsing(true)
+ .setMalformedHeaderStartsBody(false)
+ .build();
+
+ private final boolean strictParsing;
+ private final int maxLineLen;
+ private final int maxHeaderCount;
+ private final int maxHeaderLen;
+ private final long maxContentLen;
+ private final boolean countLineNumbers;
+ private final String headlessParsing;
+ private final boolean malformedHeaderStartsBody;
+
+ MimeConfig(
+ boolean strictParsing,
+ int maxLineLen,
+ int maxHeaderCount,
+ int maxHeaderLen,
+ long maxContentLen,
+ boolean countLineNumbers,
+ String headlessParsing,
+ boolean malformedHeaderStartsBody) {
+ this.strictParsing = strictParsing;
+ this.countLineNumbers = countLineNumbers;
+ this.malformedHeaderStartsBody = malformedHeaderStartsBody;
+ this.maxLineLen = maxLineLen;
+ this.maxHeaderCount = maxHeaderCount;
+ this.maxHeaderLen = maxHeaderLen;
+ this.maxContentLen = maxContentLen;
+ this.headlessParsing = headlessParsing;
}
/**
@@ -57,21 +71,6 @@ public final class MimeConfig implements
}
/**
- * Define the behaviour for dealing with malformed headers while in lenient
- * mode
- *
- * @param malformedHeaderStartsBody
- * <code>true</code> to make the parser interpret a malformed
- * header as end of the headers and as part of the body (as if
- * the CRLF separator was missing). <code>false</code> to simply
- * ignore malformed headers and continue parsing headers from the
- * following line.
- */
- public void setMalformedHeaderStartsBody(boolean malformedHeaderStartsBody) {
- this.malformedHeaderStartsBody = malformedHeaderStartsBody;
- }
-
- /**
* Returns the value of the strict parsing mode
*
* @see #setStrictParsing(boolean)
@@ -83,22 +82,6 @@ public final class MimeConfig implements
}
/**
- * Defines whether minor violations of the MIME specification should be
- * tolerated or should result in a {@link MimeException}. If this parameter
- * is set to <code>true</code>, a strict interpretation of the MIME
- * specification will be enforced, If this parameter is set to
- * <code>false</code> minor violations will result in a warning in the log.
- * <p>
- * Default value: <code>false</code>
- *
- * @param strictParsing
- * value of the strict parsing mode
- */
- public void setStrictParsing(boolean strictParsing) {
- this.strictParsing = strictParsing;
- }
-
- /**
* Returns the maximum line length limit
*
* @see #setMaxLineLen(int)
@@ -110,21 +93,6 @@ public final class MimeConfig implements
}
/**
- * Sets the maximum line length limit. Parsing of a MIME entity will be
- * terminated with a {@link MimeException} if a line is encountered that
- * exceeds the maximum length limit. If this parameter is set to a non
- * positive value the line length check will be disabled.
- * <p>
- * Default value: <code>1000</code>
- *
- * @param maxLineLen
- * maximum line length limit
- */
- public void setMaxLineLen(int maxLineLen) {
- this.maxLineLen = maxLineLen;
- }
-
- /**
* Returns the maximum header limit
*
* @see #setMaxHeaderCount(int)
@@ -136,21 +104,6 @@ public final class MimeConfig implements
}
/**
- * Sets the maximum header limit. Parsing of a MIME entity will be
- * terminated with a {@link MimeException} if the number of headers exceeds
- * the maximum limit. If this parameter is set to a non positive value the
- * header limit check will be disabled.
- * <p>
- * Default value: <code>1000</code>
- *
- * @param maxHeaderCount
- * maximum header limit
- */
- public void setMaxHeaderCount(int maxHeaderCount) {
- this.maxHeaderCount = maxHeaderCount;
- }
-
- /**
* Returns the maximum header length limit
*
* @see #setMaxHeaderLen(int)
@@ -162,26 +115,6 @@ public final class MimeConfig implements
}
/**
- * Sets the maximum header length limit. Parsing of a MIME entity will be
- * terminated with a {@link MimeException} if the total length of a header
- * exceeds this limit. If this parameter is set to a non positive value the
- * header length check will be disabled.
- * <p>
- * A message header may be folded across multiple lines. This configuration
- * parameter is used to limit the total length of a header, i.e. the sum of
- * the length of all lines the header spans across (including line
- * terminators).
- * <p>
- * Default value: <code>10000</code>
- *
- * @param maxHeaderLen
- * maximum header length limit
- */
- public void setMaxHeaderLen(int maxHeaderLen) {
- this.maxHeaderLen = maxHeaderLen;
- }
-
- /**
* Returns the maximum content length limit
*
* @see #setMaxContentLen(long)
@@ -193,21 +126,6 @@ public final class MimeConfig implements
}
/**
- * Sets the maximum content length limit. Parsing of a MIME entity will be
- * terminated with a {@link MimeException} if a content body exceeds the
- * maximum length limit. If this parameter is set to a non positive value
- * the content length check will be disabled.
- * <p>
- * Default value: <code>-1</code>
- *
- * @param maxContentLen
- * maximum content length limit
- */
- public void setMaxContentLen(long maxContentLen) {
- this.maxContentLen = maxContentLen;
- }
-
- /**
* Returns the value of the line number counting mode.
*
* @return value of the line number counting mode.
@@ -217,19 +135,6 @@ public final class MimeConfig implements
}
/**
- * Defines whether the parser should count line numbers. If enabled line
- * numbers are included in the debug output.
- * <p>
- * Default value: <code>false</code>
- *
- * @param countLineNumbers
- * value of the line number counting mode.
- */
- public void setCountLineNumbers(boolean countLineNumbers) {
- this.countLineNumbers = countLineNumbers;
- }
-
- /**
* Returns the value of the default content type. When not null, indicates
* that the parsing should be headless.
*
@@ -240,34 +145,206 @@ public final class MimeConfig implements
return headlessParsing;
}
- /**
- * Defines a default content type. When not null, indicates that the parsing
- * should be headless.
- * <p>
- * Default value: <code>null</code>
- *
- * @param contentType
- * value of the default content type when parsing headless, null
- * otherwise
- * @see org.apache.james.mime4j.parser.MimeStreamParser#parse(java.io.InputStream)
- */
- public void setHeadlessParsing(String contentType) {
- this.headlessParsing = contentType;
- }
-
@Override
- public MimeConfig clone() {
- try {
- return (MimeConfig) super.clone();
- } catch (CloneNotSupportedException e) {
- // this shouldn't happen, since we are Cloneable
- throw new InternalError();
+ public String toString() {
+ StringBuilder b = new StringBuilder();
+ b.append("[strictParsing=").append(strictParsing)
+ .append(", maxLineLen=").append(maxLineLen)
+ .append(", maxHeaderCount=").append(maxHeaderCount)
+ .append(", maxHeaderLen=").append(maxHeaderLen)
+ .append(", maxContentLen=").append(maxContentLen)
+ .append(", countLineNumbers=").append(countLineNumbers)
+ .append(", headlessParsing=").append(headlessParsing)
+ .append(", malformedHeaderStartsBody=").append(malformedHeaderStartsBody)
+ .append("]");
+ return b.toString();
+ }
+
+ public static MimeConfig.Builder custom() {
+ return new Builder();
+ }
+
+ public static MimeConfig.Builder copy(final MimeConfig config) {
+ if (config == null) {
+ throw new IllegalArgumentException("Config may not be null");
+ }
+ return new Builder()
+ .setStrictParsing(config.isStrictParsing())
+ .setMaxLineLen(config.getMaxLineLen())
+ .setMaxHeaderCount(config.getMaxHeaderCount())
+ .setMaxHeaderLen(config.getMaxHeaderLen())
+ .setMaxContentLen(config.getMaxContentLen())
+ .setCountLineNumbers(config.isCountLineNumbers())
+ .setHeadlessParsing(config.getHeadlessParsing())
+ .setMalformedHeaderStartsBody(config.isMalformedHeaderStartsBody());
+ }
+
+ public static class Builder {
+
+ private boolean strictParsing;
+ private int maxLineLen;
+ private int maxHeaderCount;
+ private int maxHeaderLen;
+ private long maxContentLen;
+ private boolean countLineNumbers;
+ private String headlessParsing;
+ private boolean malformedHeaderStartsBody;
+
+ public Builder() {
+ this.strictParsing = false;
+ this.countLineNumbers = false;
+ this.malformedHeaderStartsBody = false;
+ this.maxLineLen = 1000;
+ this.maxHeaderCount = 1000;
+ this.maxHeaderLen = 10000;
+ this.maxContentLen = -1;
+ this.headlessParsing = null;
+ }
+
+ /**
+ * Define the behaviour for dealing with malformed headers while in lenient
+ * mode
+ *
+ * @param malformedHeaderStartsBody
+ * <code>true</code> to make the parser interpret a malformed
+ * header as end of the headers and as part of the body (as if
+ * the CRLF separator was missing). <code>false</code> to simply
+ * ignore malformed headers and continue parsing headers from the
+ * following line.
+ */
+ public Builder setMalformedHeaderStartsBody(boolean malformedHeaderStartsBody) {
+ this.malformedHeaderStartsBody = malformedHeaderStartsBody;
+ return this;
+ }
+
+ /**
+ * Defines whether minor violations of the MIME specification should be
+ * tolerated or should result in a {@link MimeException}. If this parameter
+ * is set to <code>true</code>, a strict interpretation of the MIME
+ * specification will be enforced, If this parameter is set to
+ * <code>false</code> minor violations will result in a warning in the log.
+ * <p>
+ * Default value: <code>false</code>
+ *
+ * @param strictParsing
+ * value of the strict parsing mode
+ */
+ public Builder setStrictParsing(boolean strictParsing) {
+ this.strictParsing = strictParsing;
+ return this;
+ }
+
+ /**
+ * Sets the maximum line length limit. Parsing of a MIME entity will be
+ * terminated with a {@link MimeException} if a line is encountered that
+ * exceeds the maximum length limit. If this parameter is set to a non
+ * positive value the line length check will be disabled.
+ * <p>
+ * Default value: <code>1000</code>
+ *
+ * @param maxLineLen
+ * maximum line length limit
+ */
+ public Builder setMaxLineLen(int maxLineLen) {
+ this.maxLineLen = maxLineLen;
+ return this;
+ }
+
+ /**
+ * Sets the maximum header limit. Parsing of a MIME entity will be
+ * terminated with a {@link MimeException} if the number of headers exceeds
+ * the maximum limit. If this parameter is set to a non positive value the
+ * header limit check will be disabled.
+ * <p>
+ * Default value: <code>1000</code>
+ *
+ * @param maxHeaderCount
+ * maximum header limit
+ */
+ public Builder setMaxHeaderCount(int maxHeaderCount) {
+ this.maxHeaderCount = maxHeaderCount;
+ return this;
+ }
+
+ /**
+ * Sets the maximum header length limit. Parsing of a MIME entity will be
+ * terminated with a {@link MimeException} if the total length of a header
+ * exceeds this limit. If this parameter is set to a non positive value the
+ * header length check will be disabled.
+ * <p>
+ * A message header may be folded across multiple lines. This configuration
+ * parameter is used to limit the total length of a header, i.e. the sum of
+ * the length of all lines the header spans across (including line
+ * terminators).
+ * <p>
+ * Default value: <code>10000</code>
+ *
+ * @param maxHeaderLen
+ * maximum header length limit
+ */
+ public Builder setMaxHeaderLen(int maxHeaderLen) {
+ this.maxHeaderLen = maxHeaderLen;
+ return this;
+ }
+
+ /**
+ * Sets the maximum content length limit. Parsing of a MIME entity will be
+ * terminated with a {@link MimeException} if a content body exceeds the
+ * maximum length limit. If this parameter is set to a non positive value
+ * the content length check will be disabled.
+ * <p>
+ * Default value: <code>-1</code>
+ *
+ * @param maxContentLen
+ * maximum content length limit
+ */
+ public Builder setMaxContentLen(long maxContentLen) {
+ this.maxContentLen = maxContentLen;
+ return this;
+ }
+
+ /**
+ * Defines whether the parser should count line numbers. If enabled line
+ * numbers are included in the debug output.
+ * <p>
+ * Default value: <code>false</code>
+ *
+ * @param countLineNumbers
+ * value of the line number counting mode.
+ */
+ public Builder setCountLineNumbers(boolean countLineNumbers) {
+ this.countLineNumbers = countLineNumbers;
+ return this;
+ }
+
+ /**
+ * Defines a default content type. When not null, indicates that the parsing
+ * should be headless.
+ * <p>
+ * Default value: <code>null</code>
+ *
+ * @param contentType
+ * value of the default content type when parsing headless, null
+ * otherwise
+ * @see org.apache.james.mime4j.parser.MimeStreamParser#parse(java.io.InputStream)
+ */
+ public Builder setHeadlessParsing(String contentType) {
+ this.headlessParsing = contentType;
+ return this;
+ }
+
+ public MimeConfig build() {
+ return new MimeConfig(
+ strictParsing,
+ maxLineLen,
+ maxHeaderCount,
+ maxHeaderLen,
+ maxContentLen,
+ countLineNumbers,
+ headlessParsing,
+ malformedHeaderStartsBody);
}
- }
- @Override
- public String toString() {
- return "[strict parsing: " + strictParsing + ", max line length: " + maxLineLen + ", max header count: " + maxHeaderCount + ", max content length: " + maxContentLen + ", count line numbers: " + countLineNumbers + "]";
}
}
Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeEntity.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeEntity.java?rev=1482294&r1=1482293&r2=1482294&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeEntity.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeEntity.java Tue May 14 10:51:32 2013
@@ -123,7 +123,7 @@ class MimeEntity implements EntityStateM
InputStream instream,
FieldBuilder fieldBuilder,
BodyDescriptorBuilder bodyDescBuilder) {
- this(lineSource, instream, new MimeConfig(),
+ this(lineSource, instream, MimeConfig.DEFAULT,
EntityState.T_START_MESSAGE, EntityState.T_END_MESSAGE,
DecodeMonitor.SILENT,
fieldBuilder,
@@ -134,7 +134,7 @@ class MimeEntity implements EntityStateM
LineNumberSource lineSource,
InputStream instream,
BodyDescriptorBuilder bodyDescBuilder) {
- this(lineSource, instream, new MimeConfig(),
+ this(lineSource, instream, MimeConfig.DEFAULT,
EntityState.T_START_MESSAGE, EntityState.T_END_MESSAGE,
DecodeMonitor.SILENT,
new DefaultFieldBuilder(-1),
Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeTokenStream.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeTokenStream.java?rev=1482294&r1=1482293&r2=1482294&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeTokenStream.java (original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/stream/MimeTokenStream.java Tue May 14 10:51:32 2013
@@ -124,7 +124,7 @@ public class MimeTokenStream {
final FieldBuilder fieldBuilder,
final BodyDescriptorBuilder bodyDescBuilder) {
super();
- this.config = config != null ? config : new MimeConfig();
+ this.config = config != null ? config : MimeConfig.DEFAULT;
this.fieldBuilder = fieldBuilder != null ? fieldBuilder :
new DefaultFieldBuilder(this.config.getMaxHeaderLen());
this.monitor = monitor != null ? monitor :
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/ExampleMessageTestCase.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/ExampleMessageTestCase.java?rev=1482294&r1=1482293&r2=1482294&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/ExampleMessageTestCase.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/ExampleMessageTestCase.java Tue May 14 10:51:32 2013
@@ -66,12 +66,12 @@ public abstract class ExampleMessageTest
}
public MimeConfig getConfig() {
- MimeConfig config = new MimeConfig();
+ MimeConfig.Builder b = MimeConfig.custom();
if (file.getName().startsWith("malformedHeaderStartsBody")) {
- config.setMalformedHeaderStartsBody(true);
+ b.setMalformedHeaderStartsBody(true);
}
- config.setMaxLineLen(-1);
- return config;
+ b.setMaxLineLen(-1);
+ return b.build();
}
}
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MimeEntityTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MimeEntityTest.java?rev=1482294&r1=1482293&r2=1482294&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MimeEntityTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/MimeEntityTest.java Tue May 14 10:51:32 2013
@@ -395,8 +395,9 @@ public class MimeEntityTest extends Test
}
public void testMaxLineLimitCheck() throws Exception {
- MimeConfig config = new MimeConfig();
- config.setMaxLineLen(50);
+ MimeConfig config = MimeConfig.custom()
+ .setMaxLineLen(50)
+ .build();
String message =
"To: Road Runner <ru...@example.org>\r\n" +
@@ -461,9 +462,11 @@ public class MimeEntityTest extends Test
LineNumberInputStream lineInput = new LineNumberInputStream(instream);
BufferedLineReaderInputStream rawstream = new BufferedLineReaderInputStream(lineInput, 12);
- MimeConfig config = new MimeConfig();
- config.setMaxLineLen(100);
- config.setMaxHeaderLen(200);
+ MimeConfig config = MimeConfig.custom()
+ .setMaxLineLen(100)
+ .setMaxHeaderLen(200)
+ .build();
+
MimeEntity entity = new MimeEntity(
lineInput,
rawstream,
@@ -489,9 +492,10 @@ public class MimeEntityTest extends Test
}
public void testMaxHeaderLengthMayExceedMaxLineLength() throws Exception {
- MimeConfig config = new MimeConfig();
- config.setMaxLineLen(50);
- config.setMaxHeaderLen(130);
+ MimeConfig config = MimeConfig.custom()
+ .setMaxLineLen(50)
+ .setMaxHeaderLen(130)
+ .build();
String message =
"To: Road Runner <ru...@example.org>\r\n" +
@@ -557,8 +561,9 @@ public class MimeEntityTest extends Test
LineNumberInputStream lineInput = new LineNumberInputStream(instream);
BufferedLineReaderInputStream rawstream = new BufferedLineReaderInputStream(lineInput, 12);
- MimeConfig config = new MimeConfig();
- config.setMaxHeaderCount(20);
+ MimeConfig config = MimeConfig.custom()
+ .setMaxHeaderCount(20)
+ .build();
MimeEntity entity = new MimeEntity(
lineInput,
rawstream,
@@ -603,8 +608,9 @@ public class MimeEntityTest extends Test
LineNumberInputStream lineInput = new LineNumberInputStream(instream);
BufferedLineReaderInputStream rawstream = new BufferedLineReaderInputStream(lineInput, 12);
- MimeConfig config = new MimeConfig();
- config.setMaxContentLen(100);
+ MimeConfig config = MimeConfig.custom()
+ .setMaxContentLen(100)
+ .build();
MimeEntity entity = new MimeEntity(
lineInput,
rawstream,
Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/StrictMimeTokenStreamTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/StrictMimeTokenStreamTest.java?rev=1482294&r1=1482293&r2=1482294&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/StrictMimeTokenStreamTest.java (original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/stream/StrictMimeTokenStreamTest.java Tue May 14 10:51:32 2013
@@ -36,9 +36,7 @@ public class StrictMimeTokenStreamTest {
@Before
public void setUp() throws Exception {
- MimeConfig config = new MimeConfig();
- config.setStrictParsing(true);
- parser = new MimeTokenStream(config);
+ parser = new MimeTokenStream(MimeConfig.STRICT);
}
@Test
Modified: james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/DefaultMessageBuilder.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/DefaultMessageBuilder.java?rev=1482294&r1=1482293&r2=1482294&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/DefaultMessageBuilder.java (original)
+++ james/mime4j/trunk/dom/src/main/java/org/apache/james/mime4j/message/DefaultMessageBuilder.java Tue May 14 10:51:32 2013
@@ -252,7 +252,7 @@ public class DefaultMessageBuilder imple
}
public Header parseHeader(final InputStream is) throws IOException, MimeIOException {
- final MimeConfig cfg = config != null ? config : new MimeConfig();
+ final MimeConfig cfg = config != null ? config : MimeConfig.DEFAULT;
boolean strict = cfg.isStrictParsing();
final DecodeMonitor mon = monitor != null ? monitor :
strict ? DecodeMonitor.STRICT : DecodeMonitor.SILENT;
@@ -295,7 +295,7 @@ public class DefaultMessageBuilder imple
public Message parseMessage(final InputStream is) throws IOException, MimeIOException {
try {
MessageImpl message = newMessageImpl();
- MimeConfig cfg = config != null ? config : new MimeConfig();
+ MimeConfig cfg = config != null ? config : MimeConfig.DEFAULT;
boolean strict = cfg.isStrictParsing();
DecodeMonitor mon = monitor != null ? monitor :
strict ? DecodeMonitor.STRICT : DecodeMonitor.SILENT;
Modified: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageHeadlessParserTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageHeadlessParserTest.java?rev=1482294&r1=1482293&r2=1482294&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageHeadlessParserTest.java (original)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/dom/MessageHeadlessParserTest.java Tue May 14 10:51:32 2013
@@ -19,8 +19,10 @@
package org.apache.james.mime4j.dom;
+import org.apache.james.mime4j.Charsets;
import org.apache.james.mime4j.dom.field.ContentTypeField;
import org.apache.james.mime4j.dom.field.FieldName;
+import org.apache.james.mime4j.io.InputStreams;
import org.apache.james.mime4j.message.DefaultMessageBuilder;
import org.apache.james.mime4j.stream.MimeConfig;
import org.junit.Assert;
@@ -40,8 +42,9 @@ public class MessageHeadlessParserTest {
+ "\r\n"
+ "Instead this should be better parsed as a text/plain body\r\n";
- MimeConfig config = new MimeConfig();
- config.setMalformedHeaderStartsBody(true);
+ MimeConfig config = MimeConfig.custom()
+ .setMalformedHeaderStartsBody(true)
+ .build();
DefaultMessageBuilder builder = new DefaultMessageBuilder();
builder.setMimeEntityConfig(config);
Message message = builder.parseMessage(
@@ -61,8 +64,9 @@ public class MessageHeadlessParserTest {
+ "\r\n"
+ "Instead this should be better parsed as a text/plain body\r\n";
- MimeConfig config = new MimeConfig();
- config.setMalformedHeaderStartsBody(true);
+ MimeConfig config = MimeConfig.custom()
+ .setMalformedHeaderStartsBody(true)
+ .build();
DefaultMessageBuilder builder = new DefaultMessageBuilder();
builder.setMimeEntityConfig(config);
Message message = builder.parseMessage(
@@ -91,13 +95,13 @@ public class MessageHeadlessParserTest {
+ "Content-Type: image/jpeg\r\n" + "\r\n"
+ "all kind of stuff\r\n" + "--foo--\r\n";
- MimeConfig config = new MimeConfig();
- config.setHeadlessParsing(contentType);
+ MimeConfig config = MimeConfig.custom()
+ .setHeadlessParsing(contentType)
+ .build();
DefaultMessageBuilder builder = new DefaultMessageBuilder();
builder.setMimeEntityConfig(config);
- Message message = builder.parseMessage(
- new ByteArrayInputStream(headlessContent.getBytes("UTF-8")));
+ Message message = builder.parseMessage(InputStreams.create(headlessContent, Charsets.UTF_8));
Assert.assertEquals("multipart/form-data", message.getMimeType());
Assert.assertEquals(1, message.getHeader().getFields().size());
ContentTypeField contentTypeField = ((ContentTypeField) message
Modified: james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/MaximalBodyDescriptorTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/MaximalBodyDescriptorTest.java?rev=1482294&r1=1482293&r2=1482294&view=diff
==============================================================================
--- james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/MaximalBodyDescriptorTest.java (original)
+++ james/mime4j/trunk/dom/src/test/java/org/apache/james/mime4j/message/MaximalBodyDescriptorTest.java Tue May 14 10:51:32 2013
@@ -43,9 +43,7 @@ public class MaximalBodyDescriptorTest {
@Before
public void setUp() throws Exception {
- MimeConfig config = new MimeConfig();
- config.setStrictParsing(true);
- parser = new MimeTokenStream(config, new DefaultBodyDescriptorBuilder(null));
+ parser = new MimeTokenStream(MimeConfig.STRICT, new DefaultBodyDescriptorBuilder(null));
}
@Test