Author: rdonkin
Date: Sat Jun 21 09:17:35 2008
New Revision: 670218
URL: http://svn.apache.org/viewvc?rev=670218&view=rev
Log:
RFC2183 Content Disposition parsing
Added:
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/RFC2183ContentDispositionDescriptor.java
Modified:
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/MaximalBodyDescriptor.java
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/datetime/DateTime.java
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/util/MimeUtil.java
james/mime4j/trunk/src/test/java/org/apache/james/mime4j/ExampleMail.java
james/mime4j/trunk/src/test/java/org/apache/james/mime4j/MaximalBodyDescriptorTest.java
Modified:
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/MaximalBodyDescriptor.java
URL:
http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/MaximalBodyDescriptor.java?rev=670218&r1=670217&r2=670218&view=diff
==============================================================================
---
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/MaximalBodyDescriptor.java
(original)
+++
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/MaximalBodyDescriptor.java
Sat Jun 21 09:17:35 2008
@@ -19,7 +19,12 @@
package org.apache.james.mime4j;
import java.io.StringReader;
+import java.util.Collections;
+import java.util.Map;
+import org.apache.james.mime4j.field.datetime.DateTime;
+import org.apache.james.mime4j.field.datetime.parser.DateTimeParser;
+import org.apache.james.mime4j.field.datetime.parser.ParseException;
import org.apache.james.mime4j.field.mimeversion.MimeVersionParser;
import org.apache.james.mime4j.util.MimeUtil;
@@ -28,7 +33,7 @@
* Parses and stores values for standard MIME header values.
*
*/
-public class MaximalBodyDescriptor extends DefaultBodyDescriptor implements
RFC2045MimeDescriptor {
+public class MaximalBodyDescriptor extends DefaultBodyDescriptor implements
RFC2045MimeDescriptor, RFC2183ContentDispositionDescriptor {
private static final int DEFAULT_MINOR_VERSION = 0;
private static final int DEFAULT_MAJOR_VERSION = 1;
@@ -40,6 +45,17 @@
private boolean isContentIdSet;
private String contentDescription;
private boolean isContentDescriptionSet;
+ private String contentDispositionType;
+ private Map contentDispositionParameters;
+ private DateTime contentDispositionModificationDate;
+ private MimeException contentDispositionModificationDateParseException;
+ private DateTime contentDispositionCreationDate;
+ private MimeException contentDispositionCreationDateParseException;
+ private DateTime contentDispositionReadDate;
+ private MimeException contentDispositionReadDateParseException;
+ private long contentDispositionSize;
+ private MimeException contentDispositionSizeParseException;
+ private boolean isContentDispositionSet;
protected MaximalBodyDescriptor() {
this(null);
@@ -54,6 +70,17 @@
this.isContentIdSet = false;
this.contentDescription = null;
this.isContentDescriptionSet = false;
+ this.contentDispositionType = null;
+ this.contentDispositionParameters = Collections.EMPTY_MAP;
+ this.contentDispositionModificationDate = null;
+ this.contentDispositionModificationDateParseException = null;
+ this.contentDispositionCreationDate = null;
+ this.contentDispositionCreationDateParseException = null;
+ this.contentDispositionReadDate = null;
+ this.contentDispositionReadDateParseException = null;
+ this.contentDispositionSize = -1;
+ this.contentDispositionSizeParseException = null;
+ this.isContentDispositionSet = false;
}
public void addField(String name, String value) {
@@ -64,11 +91,66 @@
parseContentId(value);
} else if (MimeUtil.MIME_HEADER_CONTENT_DESCRIPTION.equals(name) &&
!isContentDescriptionSet) {
parseContentDescription(value);
+ } else if (MimeUtil.MIME_HEADER_CONTENT_DISPOSITION.equals(name) &&
!isContentDispositionSet) {
+ parseContentDisposition(value);
} else {
super.addField(name, value);
}
}
+ private void parseContentDisposition(final String value) {
+ isContentDispositionSet = true;
+ contentDispositionParameters = MimeUtil.getHeaderParams(value);
+ contentDispositionType = (String) contentDispositionParameters.get("");
+
+ final String contentDispositionModificationDate
+ = (String)
contentDispositionParameters.get(MimeUtil.PARAM_MODIFICATION_DATE);
+ if (contentDispositionModificationDate != null) {
+ try {
+ this.contentDispositionModificationDate =
parseDate(contentDispositionModificationDate);
+ } catch (ParseException e) {
+ this.contentDispositionModificationDateParseException = e;
+ }
+ }
+
+ final String contentDispositionCreationDate
+ = (String)
contentDispositionParameters.get(MimeUtil.PARAM_CREATION_DATE);
+ if (contentDispositionCreationDate != null) {
+ try {
+ this.contentDispositionCreationDate =
parseDate(contentDispositionCreationDate);
+ } catch (ParseException e) {
+ this.contentDispositionCreationDateParseException = e;
+ }
+ }
+
+ final String contentDispositionReadDate
+ = (String)
contentDispositionParameters.get(MimeUtil.PARAM_READ_DATE);
+ if (contentDispositionReadDate != null) {
+ try {
+ this.contentDispositionReadDate =
parseDate(contentDispositionReadDate);
+ } catch (ParseException e) {
+ this.contentDispositionReadDateParseException = e;
+ }
+ }
+
+ final String size = (String)
contentDispositionParameters.get(MimeUtil.PARAM_SIZE);
+ if (size != null) {
+ try {
+ contentDispositionSize = Long.parseLong(size);
+ } catch (NumberFormatException e) {
+ this.contentDispositionSizeParseException = (MimeException)
new MimeException(e.getMessage(), e).fillInStackTrace();
+ }
+ }
+ contentDispositionParameters.remove("");
+ }
+
+ private DateTime parseDate(final String date) throws ParseException {
+ final StringReader stringReader = new StringReader(date);
+ final DateTimeParser parser = new DateTimeParser(stringReader);
+ DateTime result = parser.date_time();
+ return result;
+ }
+
private void parseContentDescription(String value) {
if (value == null) {
contentDescription = "";
@@ -140,4 +222,83 @@
public String getContentId() {
return contentId;
}
+
+ /**
+ * @see
org.apache.james.mime4j.RFC2183ContentDispositionDescriptor#getContentDispositionType()
+ */
+ public String getContentDispositionType() {
+ return contentDispositionType;
+ }
+
+ /**
+ * @see
org.apache.james.mime4j.RFC2183ContentDispositionDescriptor#getContentDispositionParameters()
+ */
+ public Map getContentDispositionParameters() {
+ return contentDispositionParameters;
+ }
+
+ /**
+ * @see
org.apache.james.mime4j.RFC2183ContentDispositionDescriptor#getContentDispositionFilename()
+ */
+ public String getContentDispositionFilename() {
+ return (String)
contentDispositionParameters.get(MimeUtil.PARAM_FILENAME);
+ }
+
+ /**
+ * @see
org.apache.james.mime4j.RFC2183ContentDispositionDescriptor#getContentDispositionModificationDate()
+ */
+ public DateTime getContentDispositionModificationDate() {
+ return contentDispositionModificationDate;
+ }
+
+ /**
+ * @see
org.apache.james.mime4j.RFC2183ContentDispositionDescriptor#getContentDispositionModificationDateParseException()
+ */
+ public MimeException getContentDispositionModificationDateParseException()
{
+ return contentDispositionModificationDateParseException;
+ }
+
+ /**
+ * @see
org.apache.james.mime4j.RFC2183ContentDispositionDescriptor#getContentDispositionCreationDate()
+ */
+ public DateTime getContentDispositionCreationDate() {
+ return contentDispositionCreationDate;
+ }
+
+ /**
+ * @see
org.apache.james.mime4j.RFC2183ContentDispositionDescriptor#getContentDispositionCreationDateParseException()
+ */
+ public MimeException getContentDispositionCreationDateParseException() {
+ return contentDispositionCreationDateParseException;
+ }
+
+ /**
+ * @see
org.apache.james.mime4j.RFC2183ContentDispositionDescriptor#getContentDispositionReadDate()
+ */
+ public DateTime getContentDispositionReadDate() {
+ return contentDispositionReadDate;
+ }
+
+ /**
+ * @see
org.apache.james.mime4j.RFC2183ContentDispositionDescriptor#getContentDispositionReadDateParseException()
+ */
+ public MimeException getContentDispositionReadDateParseException() {
+ return contentDispositionReadDateParseException;
+ }
+
+ /**
+ * @see
org.apache.james.mime4j.RFC2183ContentDispositionDescriptor#getContentDispositionSize()
+ */
+ public long getContentDispositionSize() {
+ return contentDispositionSize;
+ }
+
+ /**
+ * @see
org.apache.james.mime4j.RFC2183ContentDispositionDescriptor#getContentDispositionSizeParseException()
+ */
+ public MimeException getContentDispositionSizeParseException() {
+ return contentDispositionSizeParseException;
+ }
+
+
}
Added:
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/RFC2183ContentDispositionDescriptor.java
URL:
http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/RFC2183ContentDispositionDescriptor.java?rev=670218&view=auto
==============================================================================
---
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/RFC2183ContentDispositionDescriptor.java
(added)
+++
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/RFC2183ContentDispositionDescriptor.java
Sat Jun 21 09:17:35 2008
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.james.mime4j;
+
+import java.util.Map;
+
+import org.apache.james.mime4j.field.datetime.DateTime;
+
+/**
+ * Describes <a href='http://www.faqs.org/rfcs/rfc2183.html'>RFC2183</a>
+ * content disposition.
+ */
+public interface RFC2183ContentDispositionDescriptor {
+
+ /**
+ * Gets the disposition type of the <code>content-disposition</code> field.
+ * The value is case insensitive and will be converted to lower case.
+ * See <a href='http://www.faqs.org/rfcs/rfc2183.html'>RFC2183</a>.
+ * @return content disposition type,
+ * or null when this has not been set
+ */
+ public abstract String getContentDispositionType();
+
+ /**
+ * Gets the parameters of the <code>content-disposition</code> field.
+ * See <a href='http://www.faqs.org/rfcs/rfc2183.html'>RFC2183</a>.
+ * @return parameter value strings indexed by parameter name strings,
+ * not null
+ */
+ public abstract Map getContentDispositionParameters();
+
+ /**
+ * Gets the <code>filename</code> parameter value of the
<code>content-disposition</code> field.
+ * See <a href='http://www.faqs.org/rfcs/rfc2183.html'>RFC2183</a>.
+ * @return filename parameter value,
+ * or null when it is not present
+ */
+ public abstract String getContentDispositionFilename();
+
+ /**
+ * Gets the <code>modification-date</code> parameter value of the
<code>content-disposition</code> field.
+ * See <a href='http://www.faqs.org/rfcs/rfc2183.html'>RFC2183</a>.
+ * @return modification-date parameter value,
+ * or null when this is not present
+ */
+ public abstract DateTime getContentDispositionModificationDate();
+
+ /**
+ * Gets any exception thrown during the parsing of [EMAIL PROTECTED]
#getContentDispositionModificationDate()}
+ * @return <code>ParseException</code> when the modification-date parse
fails,
+ * null otherwise
+ */
+ public abstract MimeException
getContentDispositionModificationDateParseException();
+
+ /**
+ * Gets the <code>creation-date</code> parameter value of the
<code>content-disposition</code> field.
+ * See <a href='http://www.faqs.org/rfcs/rfc2183.html'>RFC2183</a>.
+ * @return creation-date parameter value,
+ * or null when this is not present
+ */
+ public abstract DateTime getContentDispositionCreationDate();
+
+ /**
+ * Gets any exception thrown during the parsing of [EMAIL PROTECTED]
#getContentCreationModificationDate()}
+ * @return <code>ParseException</code> when the creation-date parse fails,
+ * null otherwise
+ */
+ public abstract MimeException
getContentDispositionCreationDateParseException();
+
+ /**
+ * Gets the <code>read-date</code> parameter value of the
<code>content-disposition</code> field.
+ * See <a href='http://www.faqs.org/rfcs/rfc2183.html'>RFC2183</a>.
+ * @return read-date parameter value,
+ * or null when this is not present
+ */
+ public abstract DateTime getContentDispositionReadDate();
+
+ /**
+ * Gets any exception thrown during the parsing of [EMAIL PROTECTED]
#getContentReadModificationDate()}
+ * @return <code>ParseException</code> when the read-date parse fails,
+ * null otherwise
+ */
+ public abstract MimeException
getContentDispositionReadDateParseException();
+
+ /**
+ * Gets the <code>size</code> parameter value of the
<code>content-disposition</code> field.
+ * See <a href='http://www.faqs.org/rfcs/rfc2183.html'>RFC2183</a>.
+ * @return size parameter value,
+ * or -1 if this size has not been set
+ */
+ public abstract long getContentDispositionSize();
+
+ /**
+ * Gets any exception thrown during the parsing of [EMAIL PROTECTED]
#getContentReadModificationDate()}
+ * @return <code>ParseException</code> when the read-date parse fails,
+ * null otherwise
+ */
+ public abstract MimeException getContentDispositionSizeParseException();
+
+}
\ No newline at end of file
Modified:
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/datetime/DateTime.java
URL:
http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/datetime/DateTime.java?rev=670218&r1=670217&r2=670218&view=diff
==============================================================================
---
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/datetime/DateTime.java
(original)
+++
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/field/datetime/DateTime.java
Sat Jun 21 09:17:35 2008
@@ -107,7 +107,56 @@
}
public void print() {
- System.out.println(getYear() + " " + getMonth() + " " + getDay() + ";
" + getHour() + " " + getMinute() + " " + getSecond() + " " + getTimeZone());
+ System.out.println(toString());
}
+ public String toString() {
+ return getYear() + " " + getMonth() + " " + getDay() + "; " +
getHour() + " " + getMinute() + " " + getSecond() + " " + getTimeZone();
+ }
+
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ result = PRIME * result + ((date == null) ? 0 : date.hashCode());
+ result = PRIME * result + day;
+ result = PRIME * result + hour;
+ result = PRIME * result + minute;
+ result = PRIME * result + month;
+ result = PRIME * result + second;
+ result = PRIME * result + timeZone;
+ result = PRIME * result + year;
+ return result;
+ }
+
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final DateTime other = (DateTime) obj;
+ if (date == null) {
+ if (other.date != null)
+ return false;
+ } else if (!date.equals(other.date))
+ return false;
+ if (day != other.day)
+ return false;
+ if (hour != other.hour)
+ return false;
+ if (minute != other.minute)
+ return false;
+ if (month != other.month)
+ return false;
+ if (second != other.second)
+ return false;
+ if (timeZone != other.timeZone)
+ return false;
+ if (year != other.year)
+ return false;
+ return true;
+ }
+
+
}
Modified:
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/util/MimeUtil.java
URL:
http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/util/MimeUtil.java?rev=670218&r1=670217&r2=670218&view=diff
==============================================================================
--- james/mime4j/trunk/src/main/java/org/apache/james/mime4j/util/MimeUtil.java
(original)
+++ james/mime4j/trunk/src/main/java/org/apache/james/mime4j/util/MimeUtil.java
Sat Jun 21 09:17:35 2008
@@ -60,6 +60,36 @@
public static final String MIME_HEADER_CONTENT_ID = "content-id";
/** <code>Content-Description</code> header name (lowercase) */
public static final String MIME_HEADER_CONTENT_DESCRIPTION =
"content-description";
+ /**
+ * <code>Content-Disposition</code> header name (lowercase).
+ * See <a href='http://www.faqs.org/rfcs/rfc2183.html'>RFC2183</a>.
+ */
+ public static final String MIME_HEADER_CONTENT_DISPOSITION =
"content-disposition";
+ /**
+ * <code>Content-Disposition</code> filename parameter (lowercase).
+ * See <a href='http://www.faqs.org/rfcs/rfc2183.html'>RFC2183</a>.
+ */
+ public static final String PARAM_FILENAME = "filename";
+ /**
+ * <code>Content-Disposition</code> modification-date parameter
(lowercase).
+ * See <a href='http://www.faqs.org/rfcs/rfc2183.html'>RFC2183</a>.
+ */
+ public static final String PARAM_MODIFICATION_DATE = "modification-date";
+ /**
+ * <code>Content-Disposition</code> creation-date parameter (lowercase).
+ * See <a href='http://www.faqs.org/rfcs/rfc2183.html'>RFC2183</a>.
+ */
+ public static final String PARAM_CREATION_DATE = "creation-date";
+ /**
+ * <code>Content-Disposition</code> read-date parameter (lowercase).
+ * See <a href='http://www.faqs.org/rfcs/rfc2183.html'>RFC2183</a>.
+ */
+ public static final String PARAM_READ_DATE = "read-date";
+ /**
+ * <code>Content-Disposition</code> size parameter (lowercase).
+ * See <a href='http://www.faqs.org/rfcs/rfc2183.html'>RFC2183</a>.
+ */
+ public static final String PARAM_SIZE = "size";
private MimeUtil() {
// this is an utility class to be used statically.
Modified:
james/mime4j/trunk/src/test/java/org/apache/james/mime4j/ExampleMail.java
URL:
http://svn.apache.org/viewvc/james/mime4j/trunk/src/test/java/org/apache/james/mime4j/ExampleMail.java?rev=670218&r1=670217&r2=670218&view=diff
==============================================================================
--- james/mime4j/trunk/src/test/java/org/apache/james/mime4j/ExampleMail.java
(original)
+++ james/mime4j/trunk/src/test/java/org/apache/james/mime4j/ExampleMail.java
Sat Jun 21 09:17:35 2008
@@ -19,6 +19,7 @@
package org.apache.james.mime4j;
import java.nio.charset.Charset;
+import java.util.Locale;
public class ExampleMail {
@@ -102,7 +103,8 @@
" \r\n" +
"\r\n" +
"--=-tIdGYVstQJghyEDATnJ+\r\n" +
- "Content-Disposition: attachment; filename=blob.png\r\n" +
+ "Content-Disposition: attachment; filename=blob.png;\r\n
modification-date=\"Sun, 21 Jun 2008 15:32:18 +0000\"; " +
+ "creation-date=\"Sat, 20 Jun 2008 10:15:09 +0000\"; read-date=\"Mon,
22 Jun 2008 12:08:56 +0000\";size=10234;\r\n" +
"Content-Type: image/png; name=blob.png\r\n" +
"Content-Transfer-Encoding: base64\r\n" +
"\r\n" +
@@ -205,6 +207,20 @@
private static final byte[] ONE_PART_MIME_BASE64_LATIN1_ENCODED =
EncodeUtils.toBase64(latin1(ONE_PART_MIME_BASE64_LATIN1_BODY));
public static final String ONE_PART_MIME_BASE64_ASCII_BODY = "Hello,
World!\r\n";
+
+ public static final String
ONE_PART_MIME_WITH_CONTENT_DISPOSITION_PARAMETERS =
+ "Message-ID: <[EMAIL PROTECTED]>\r\n" +
+ "Date: Thu, 6 Mar 2008 18:02:03 +0000\r\n" +
+ "From: \"Robert Burrell Donkin\" <[EMAIL PROTECTED]>\r\n" +
+ "To: \"James Developers List\" <[email protected]>\r\n" +
+ "Subject: [Mime4J] getReader\r\n" +
+ "MIME-Version: 1.0\r\n" +
+ "Content-Type: text/plain; charset=US-ASCII\r\n" +
+ "Content-Transfer-Encoding: 7bit\r\n" +
+ "Content-Disposition: inline; foo=bar; one=1; param=value;\r\n" +
+ "Delivered-To: [EMAIL PROTECTED]" +
+ "\r\n" +
+ ONE_PART_MIME_ASCII_BODY;
private static final byte[] ONE_PART_MIME_BASE64_ASCII_ENCODED =
EncodeUtils.toBase64(ascii(ONE_PART_MIME_BASE64_ASCII_BODY));
@@ -422,9 +438,12 @@
EncodeUtils.toBase64(ascii(MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_BASE64)),
ascii(MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_END),
};
+
+ public static final byte[]
ONE_PART_MIME_WITH_CONTENT_DISPOSITION_PARAMETERS_BYTES =
ascii(ONE_PART_MIME_WITH_CONTENT_DISPOSITION_PARAMETERS);
public static final byte[] MIME_MULTIPART_ALTERNATIVE_BYTES =
ascii(MIME_MULTIPART_ALTERNATIVE);
public static final byte[] MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_BYTES =
join(MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_BYTE_ARRAYS);
public static final byte[] ONE_PART_MIME_QUOTED_PRINTABLE_ASCII_BYTES =
ascii(ONE_PART_MIME_QUOTED_PRINTABLE_ASCII);
+ public static final byte[] ONE_PART_MIME_BASE64_LATIN1_UPPERCASE_BYTES =
join(ascii(ONE_PART_MIME_BASE64_LATIN1_HEADERS.toUpperCase(Locale.UK)),
ONE_PART_MIME_BASE64_LATIN1_ENCODED);
public static final byte[] ONE_PART_MIME_BASE64_LATIN1_BYTES =
join(ascii(ONE_PART_MIME_BASE64_LATIN1_HEADERS),
ONE_PART_MIME_BASE64_LATIN1_ENCODED);
public static final byte[] ONE_PART_MIME_BASE64_ASCII_BYTES =
join(ascii(ONE_PART_MIME_BASE64_ASCII_HEADERS),
ONE_PART_MIME_BASE64_ASCII_ENCODED);
public static final byte[] RFC822_SIMPLE_BYTES =
US_ASCII.encode(RFC_SIMPLE).array();
Modified:
james/mime4j/trunk/src/test/java/org/apache/james/mime4j/MaximalBodyDescriptorTest.java
URL:
http://svn.apache.org/viewvc/james/mime4j/trunk/src/test/java/org/apache/james/mime4j/MaximalBodyDescriptorTest.java?rev=670218&r1=670217&r2=670218&view=diff
==============================================================================
---
james/mime4j/trunk/src/test/java/org/apache/james/mime4j/MaximalBodyDescriptorTest.java
(original)
+++
james/mime4j/trunk/src/test/java/org/apache/james/mime4j/MaximalBodyDescriptorTest.java
Sat Jun 21 09:17:35 2008
@@ -20,7 +20,7 @@
import java.io.ByteArrayInputStream;
-import junit.framework.TestCase;
+import org.apache.james.mime4j.field.datetime.DateTime;
public class MaximalBodyDescriptorTest extends BaseTestForBodyDescriptors {
@@ -72,6 +72,57 @@
assertNull(descriptor.getMimeVersionParseException());
}
+ public void testContentDispositionType() throws Exception {
+ RFC2183ContentDispositionDescriptor descriptor =
describe(ExampleMail.ONE_PART_MIME_BASE64_LATIN1_BYTES);
+ assertEquals("inline", descriptor.getContentDispositionType());
+ }
+
+ public void testContentDispositionTypeCaseConversion() throws Exception {
+ RFC2183ContentDispositionDescriptor descriptor =
describe(ExampleMail.ONE_PART_MIME_BASE64_LATIN1_BYTES);
+ assertEquals("Should be converted to lower case", "inline",
descriptor.getContentDispositionType());
+ assertNotNull(descriptor.getContentDispositionParameters());
+ assertEquals(0, descriptor.getContentDispositionParameters().size());
+ }
+
+ public void testContentDispositionParameters() throws Exception {
+ RFC2183ContentDispositionDescriptor descriptor =
describe(ExampleMail.ONE_PART_MIME_WITH_CONTENT_DISPOSITION_PARAMETERS_BYTES);
+ assertEquals("inline", descriptor.getContentDispositionType());
+ assertNotNull(descriptor.getContentDispositionParameters());
+ assertEquals(3, descriptor.getContentDispositionParameters().size());
+ assertEquals("value",
descriptor.getContentDispositionParameters().get("param"));
+ assertEquals("1",
descriptor.getContentDispositionParameters().get("one"));
+ assertEquals("bar",
descriptor.getContentDispositionParameters().get("foo"));
+ }
+
+ public void testContentDispositionStandardParameters() throws Exception {
+ RFC2183ContentDispositionDescriptor descriptor =
describe(ExampleMail.MULTIPART_WITH_BINARY_ATTACHMENTS_BYTES, 1);
+ assertEquals("attachment", descriptor.getContentDispositionType());
+ assertNotNull(descriptor.getContentDispositionParameters());
+ assertEquals(5, descriptor.getContentDispositionParameters().size());
+ assertEquals("blob.png", descriptor.getContentDispositionFilename());
+ assertEquals(new DateTime("2008", 6, 21, 15, 32, 18, 0),
descriptor.getContentDispositionModificationDate());
+ assertEquals(new DateTime("2008", 6, 20, 10, 15, 9, 0),
descriptor.getContentDispositionCreationDate());
+ assertEquals(new DateTime("2008", 6, 22, 12, 8, 56, 0),
descriptor.getContentDispositionReadDate());
+ assertEquals(10234, descriptor.getContentDispositionSize());
+ }
+
+ private RFC2183ContentDispositionDescriptor describe(byte[] mail, int
zeroBasedPart) throws Exception {
+ ByteArrayInputStream bias = new ByteArrayInputStream(mail);
+ parser.parse(bias);
+ int state = parser.next();
+ while (state != MimeTokenStream.T_END_OF_STREAM && zeroBasedPart>=0) {
+ state = parser.next();
+ if (state == MimeTokenStream.T_BODY) {
+ --zeroBasedPart;
+ }
+ }
+ assertEquals(MimeTokenStream.T_BODY, state);
+ BodyDescriptor descriptor = parser.getBodyDescriptor();
+ assertNotNull(descriptor);
+ assertTrue("Parser is maximal so body descriptor should be maximal",
descriptor instanceof MaximalBodyDescriptor);
+ return (RFC2183ContentDispositionDescriptor) descriptor;
+ }
+
private MaximalBodyDescriptor describe(byte[] mail) throws Exception {
ByteArrayInputStream bias = new ByteArrayInputStream(mail);
parser.parse(bias);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]