Skip to content

Commit

Permalink
Make sure outer boundaries are always recognized when parsing nested …
Browse files Browse the repository at this point in the history
…content (MIME4J-56)

This introduce double bufferings but at least provide RFC compliant behaviour.
Also updated "missing-inner-boundary.msg" expected output to what Niklas suggested (corresponding to what RFC mandates).

git-svn-id: https://svn.apache.org/repos/asf/james/mime4j/branches/streams-refactoring@676840 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Stefano Bagnara committed Jul 15, 2008
1 parent b1eadf4 commit 8bfe9cf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/main/java/org/apache/james/mime4j/MimeEntity.java
Expand Up @@ -122,6 +122,7 @@ public EntityStateMachine advance() throws IOException, MimeException {
clearMimeStream();
state = EntityStates.T_END_MULTIPART;
} else {
clearMimeStream();
createMimeStream();
state = T_IN_BODYPART;
return nextMimeEntity();
Expand All @@ -133,6 +134,7 @@ public EntityStateMachine advance() throws IOException, MimeException {
monitor(Event.MIME_BODY_PREMATURE_END);
} else {
if (!mimeStream.isLastPart()) {
clearMimeStream();
createMimeStream();
state = T_IN_BODYPART;
return nextMimeEntity();
Expand Down Expand Up @@ -160,7 +162,11 @@ public EntityStateMachine advance() throws IOException, MimeException {
}

private void createMimeStream() throws IOException {
mimeStream = new MimeBoundaryInputStream(inbuffer, body.getBoundary());
if (mimeStream != null) {
mimeStream = new MimeBoundaryInputStream(new InputBuffer(mimeStream, 4 * 1024), body.getBoundary());
} else {
mimeStream = new MimeBoundaryInputStream(inbuffer, body.getBoundary());
}
dataStream = new BufferingInputStreamAdaptor(mimeStream);
// If multipart message is embedded into another multipart message
// make sure to reset parent's mime stream
Expand Down
4 changes: 1 addition & 3 deletions src/test/resources/testmsgs/missing-inner-boundary.xml
Expand Up @@ -24,9 +24,6 @@ Content-Type: multipart/alternative; boundary="inner-boundary"</field>
<multipart>
<preamble>
AAA

--outer-boundary--
Outer epilouge
</preamble>
<body-part>
<header>
Expand All @@ -39,6 +36,7 @@ Outer epilouge
</multipart>
</body-part>
<epilogue>
Outer epilouge
</epilogue>
</multipart>
</message>
Expand Up @@ -22,9 +22,6 @@ Content-Type: multipart/alternative; boundary="inner-boundary"</field>
<multipart>
<preamble>
AAA

--outer-boundary--
Outer epilouge
</preamble>
<body-part>
<header>
Expand All @@ -36,6 +33,7 @@ Outer epilouge
</multipart>
</body-part>
<epilogue>
Outer epilouge
</epilogue>
</multipart>
</message>

0 comments on commit 8bfe9cf

Please sign in to comment.