Skip to content

Commit

Permalink
Added new recursion mode.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/james/mime4j/trunk@674620 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
itstechupnorth committed Jul 7, 2008
1 parent 810d150 commit 94f24e2
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/main/java/org/apache/james/mime4j/MimeEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ public EntityStateMachine advance() throws IOException, MimeException {
break;
case EntityStates.T_END_HEADER:
String mimeType = body.getMimeType();
if (MimeUtil.isMultipart(mimeType)) {
if (recursionMode == RecursionMode.M_FLAT) {
state = EntityStates.T_BODY;
} else if (MimeUtil.isMultipart(mimeType)) {
state = EntityStates.T_START_MULTIPART;
clearMimeStream();
} else if (recursionMode != RecursionMode.M_NO_RECURSE
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/apache/james/mime4j/MimeTokenStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ private void doParse(InputStream stream, String contentType) {
currentStateMachine = rawentity;
break;
case M_NO_RECURSE:
case M_FLAT:
// expected to be called only at start of paring
case M_RECURSE:
MimeEntity mimeentity = new MimeEntity(
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/apache/james/mime4j/RecursionMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,11 @@ public interface RecursionMode {
* @see #getRecursionMode()
*/
public static final int M_RAW = 2;
/**
* Do not recurse <code>message/rfc822</code> parts
* and treat multiparts as a single flat body.
* @see #getRecursionMode()
*/
public static final int M_FLAT = 3;

}
103 changes: 102 additions & 1 deletion src/test/java/org/apache/james/mime4j/ExampleMail.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,112 @@

public class ExampleMail {

public static final String MIME_MULTIPART_EMBEDDED_MESSAGES_INNER_MULTIPART_MIXED = "--4.66920160910299\r\n" +
"Content-Type: image/gif\r\n" +
"Content-Transfer-Encoding: base64\r\n" +
"MIME-Version: 1.0\r\n" +
"Content-ID: 238478934723847238947892374\r\n" +
"Content-Description: Bogus Image Data\r\n" +
"\r\n" +
"ABCDFEGHIJKLMNO\r\n" +
"\r\n" +
"--4.66920160910299\r\n" +
"Content-Type: message/rfc822\r\n" +
"\r\n" +
"From: Timothy Tayler <timothy@example.org>\r\n" +
"To: John Smith <john@example.org>\r\n" +
"Date: Sat, 16 Feb 2008 12:00:00 +0000 (GMT)\r\n" +
"Subject: Another Example Email\r\n" +
"Content-Type: multipart/mixed;boundary=2.50290787509\r\n" +
"\r\n" +
"Yet another preamble\r\n" +
"\r\n" +
"--2.50290787509\r\n" +
"Content-Type: text/plain\r\n" +
"\r\n" +
"Rhubard AND Custard!\r\n" +
"\r\n" +
"--2.50290787509\r\n" +
"Content-Type: multipart/alternative;boundary=3.243F6A8885A308D3\r\n" +
"\r\n" +
"--3.243F6A8885A308D3\r\n" +
"Content-Type: text/plain\r\n" +
"\r\n" +
"Rhubard?Custard?\r\n" +
"\r\n" +
"--3.243F6A8885A308D3\r\n" +
"\r\n" +
"Content-Type: text/richtext\r\n" +
"\r\n" +
"Rhubard?Custard?\r\n" +
"\r\n" +
"--3.243F6A8885A308D3--\r\n" +
"\r\n" +
"--2.50290787509--\r\n" +
"\r\n" +
"--4.66920160910299--";

public static final String MIME_MULTIPART_EMBEDDED_MESSAGES_INNER_MAIL = "From: Timothy Tayler <timothy@example.org>\r\n" +
"To: Samual Smith <samual@example.org>\r\n" +
"Date: Thu, 14 Feb 2008 12:00:00 +0000 (GMT)\r\n" +
"Subject: A Multipart Alternative Email\r\n" +
"Content-Type: multipart/alternative;boundary=42\r\n" +
"\r\n" +
"This message has a premable\r\n" +
"\r\n" +
"--42\r\n" +
"Content-Type: text/plain; charset=US-ASCII\r\n" +
"\r\n" +
"Custard!\r\n" +
"\r\n" +
"--42\r\n" +
"Content-Type: application/octet-stream\r\n" +
"\r\n" +
"CUSTARDCUSTARDCUSTARD\r\n" +
"\r\n" +
"--42--\r\n";

public static final String MIME_MULTIPART_EMBEDDED_MESSAGES_BODY = "Start with a preamble\r\n" +
"\r\n" +
"--1729\r\n" +
"Content-Type: text/plain; charset=US-ASCII\r\n" +
"\r\n" +
"Rhubarb!\r\n" +
"\r\n" +
"--1729\r\n" +
"Content-Type: application/octet-stream\r\n" +
"Content-Transfer-Encoding: base64\r\n" +
"\r\n" +
"987654321AHPLA\r\n" +
"\r\n" +
"--1729\r\n" +
"Content-Type: message/rfc822\r\n" +
"\r\n" +
MIME_MULTIPART_EMBEDDED_MESSAGES_INNER_MAIL +
"\r\n" +
"--1729\r\n" +
"Content-Type: multipart/mixed; boundary=4.66920160910299\r\n" +
"\r\n" +
MIME_MULTIPART_EMBEDDED_MESSAGES_INNER_MULTIPART_MIXED + "\r\n" +
"--1729--\r\n" +
"\r\n";

public static final String MD5_CONTENT = "Q2hlY2sgSW50ZWdyaXR5IQ==";
public static final String CONTENT_DESCRIPTION = "Blah blah blah";
public static final String CONTENT_ID = "<f470f68e0803061002n22bc4124he14015a4b6d6327f@mail.gmail.com>";
public static final Charset US_ASCII = Charset.forName("US-ASCII");
public static final Charset LATIN1 = Charset.forName("ISO-8859-1");

public static final String MIME_MULTIPART_EMBEDDED_MESSAGES =
"From: Timothy Tayler <timothy@example.org>\r\n" +
"To: Samual Smith <samual@example.org>\r\n" +
"Date: Thu, 14 Feb 2008 12:00:00 +0000 (GMT)\r\n" +
"Subject: A Multipart Email\r\n" +
"Content-Type: multipart/mixed;boundary=1729\r\n" +
"\r\n" +
MIME_MULTIPART_EMBEDDED_MESSAGES_BODY;


public static final String MULTIPART_WITH_CONTENT_LOCATION =
"From: Timothy Tayler <timothy@example.org>\r\n" +
"To: Samual Smith <samual@example.org>\r\n" +
Expand Down Expand Up @@ -524,7 +624,8 @@ public class ExampleMail {
public static final byte[] ONE_PART_MIME_ASCII_COMMENT_IN_MIME_VERSION_BYTES = US_ASCII.encode(ONE_PART_MIME_ASCII_COMMENT_IN_MIME_VERSION).array();
public static final byte[] ONE_PART_MIME_ASCII_MIME_VERSION_SPANS_TWO_LINES_BYTES = US_ASCII.encode(ONE_PART_MIME_ASCII_MIME_VERSION_SPANS_TWO_LINES).array();
public static final byte[] MAIL_WITH_RFC822_PART_BYTES = ascii(MAIL_WITH_RFC822_PART);

public static final byte[] MIME_MULTIPART_EMBEDDED_MESSAGES_BYTES = ascii(MIME_MULTIPART_EMBEDDED_MESSAGES);

public static final byte[] ascii(String text) {

return US_ASCII.encode(text).array();
Expand Down

0 comments on commit 94f24e2

Please sign in to comment.