Author: rdonkin
Date: Wed Jun 25 14:08:13 2008
New Revision: 671658
URL: http://svn.apache.org/viewvc?rev=671658&view=rev
Log:
Support for Content-Location
Added:
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/RFC2557ContentLocationDescriptor.java
Modified:
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/MaximalBodyDescriptor.java
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/util/MimeUtil.java
james/mime4j/trunk/src/main/javacc/org/apache/james/mime4j/field/structured/StructuredFieldParser.jj
james/mime4j/trunk/src/test/java/org/apache/james/mime4j/ExampleMail.java
james/mime4j/trunk/src/test/java/org/apache/james/mime4j/MaximalBodyDescriptorTest.java
james/mime4j/trunk/src/test/java/org/apache/james/mime4j/field/structured/StructuredFieldParserTest.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=671658&r1=671657&r2=671658&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
Wed Jun 25 14:08:13 2008
@@ -28,6 +28,7 @@
import org.apache.james.mime4j.field.datetime.parser.ParseException;
import org.apache.james.mime4j.field.language.ContentLanguageParser;
import org.apache.james.mime4j.field.mimeversion.MimeVersionParser;
+import org.apache.james.mime4j.field.structured.StructuredFieldParser;
import org.apache.james.mime4j.util.MimeUtil;
@@ -36,7 +37,7 @@
*
*/
public class MaximalBodyDescriptor extends DefaultBodyDescriptor implements
RFC2045MimeDescriptor,
- RFC2183ContentDispositionDescriptor, RFC3066ContentLanguageDescriptor {
+ RFC2183ContentDispositionDescriptor, RFC3066ContentLanguageDescriptor,
RFC2557ContentLocationDescriptor {
private static final int DEFAULT_MINOR_VERSION = 0;
private static final int DEFAULT_MAJOR_VERSION = 1;
@@ -62,6 +63,9 @@
private List contentLanguage;
private MimeException contentLanguageParseException;
private boolean isContentLanguageSet;
+ private MimeException contentLocationParseException;
+ private String contentLocation;
+ private boolean isContentLocationSet;
protected MaximalBodyDescriptor() {
this(null);
@@ -90,6 +94,9 @@
this.contentLanguage = null;
this.contentLanguageParseException = null;
this.isContentIdSet = false;
+ this.contentLocation = null;
+ this.contentLocationParseException = null;
+ this.isContentLocationSet = false;
}
public void addField(String name, String value) {
@@ -103,13 +110,29 @@
} else if (MimeUtil.MIME_HEADER_CONTENT_DISPOSITION.equals(name) &&
!isContentDispositionSet) {
parseContentDisposition(value);
} else if (MimeUtil.MIME_HEADER_LANGAUGE.equals(name) &&
!isContentLanguageSet) {
- parseLanguageTag(value);
+ parseLanguage(value);
+ } else if (MimeUtil.MIME_HEADER_LOCATION.equals(name) &&
!isContentLocationSet) {
+ parseLocation(value);
} else {
super.addField(name, value);
}
}
- private void parseLanguageTag(final String value) {
+ private void parseLocation(final String value) {
+ isContentLocationSet = true;
+ if (value != null) {
+ final StringReader stringReader = new StringReader(value);
+ final StructuredFieldParser parser = new
StructuredFieldParser(stringReader);
+ parser.setFoldingPreserved(false);
+ try {
+ contentLocation = parser.parse();
+ } catch (MimeException e) {
+ contentLocationParseException = e;
+ }
+ }
+ }
+
+ private void parseLanguage(final String value) {
isContentLanguageSet = true;
if (value != null) {
try {
@@ -336,4 +359,18 @@
public MimeException getContentLanguageParseException() {
return contentLanguageParseException;
}
+
+ /**
+ * @see
org.apache.james.mime4j.RFC2557ContentLocationDescriptor#getContentLocation()
+ */
+ public String getContentLocation() {
+ return contentLocation;
+ }
+
+ /**
+ * @see
org.apache.james.mime4j.RFC2557ContentLocationDescriptor#getContentLocationParseException()
+ */
+ public MimeException getContentLocationParseException() {
+ return contentLocationParseException;
+ }
}
Added:
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/RFC2557ContentLocationDescriptor.java
URL:
http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/RFC2557ContentLocationDescriptor.java?rev=671658&view=auto
==============================================================================
---
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/RFC2557ContentLocationDescriptor.java
(added)
+++
james/mime4j/trunk/src/main/java/org/apache/james/mime4j/RFC2557ContentLocationDescriptor.java
Wed Jun 25 14:08:13 2008
@@ -0,0 +1,38 @@
+/*
+ * 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;
+
+public interface RFC2557ContentLocationDescriptor {
+
+ /**
+ * Get the <code>content-location</code> header value.
+ * See <a href='http://tools.ietf.org/html/rfc2557'>RFC2557</a>
+ * @return the URL content-location
+ * or null if no header exists
+ */
+ public abstract String getContentLocation();
+
+ /**
+ * Gets any exception thrown during the parsing of [EMAIL PROTECTED]
#getContentLanguage()}
+ * @return <code>ParseException</code> when the content-language parse
fails,
+ * null otherwise
+ */
+ public abstract MimeException getContentLocationParseException();
+
+}
\ No newline at end of file
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=671658&r1=671657&r2=671658&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
Wed Jun 25 14:08:13 2008
@@ -92,10 +92,15 @@
*/
public static final String PARAM_SIZE = "size";
/**
- * <code>Langauge-Tag</code> header (lower case).
+ * <code>Content-Langauge</code> header (lower case).
* See <a href='http://www.faqs.org/rfcs/rfc4646.html'>RFC4646</a>.
*/
public static final String MIME_HEADER_LANGAUGE = "content-language";
+ /**
+ * <code>Content-Location</code> header (lower case).
+ * See <a href='http://www.faqs.org/rfcs/rfc2557.html'>RFC2557</a>.
+ */
+ public static final String MIME_HEADER_LOCATION = "content-location";
private MimeUtil() {
// this is an utility class to be used statically.
Modified:
james/mime4j/trunk/src/main/javacc/org/apache/james/mime4j/field/structured/StructuredFieldParser.jj
URL:
http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/javacc/org/apache/james/mime4j/field/structured/StructuredFieldParser.jj?rev=671658&r1=671657&r2=671658&view=diff
==============================================================================
---
james/mime4j/trunk/src/main/javacc/org/apache/james/mime4j/field/structured/StructuredFieldParser.jj
(original)
+++
james/mime4j/trunk/src/main/javacc/org/apache/james/mime4j/field/structured/StructuredFieldParser.jj
Wed Jun 25 14:08:13 2008
@@ -52,6 +52,22 @@
*/
public class StructuredFieldParser {
+ private boolean preserveFolding = false;
+
+ /**
+ * Should the \r\n folding sequence be preserved?
+ */
+ public boolean isFoldingPreserved() {
+ return preserveFolding;
+ }
+
+ /**
+ * Sets whether the \r\n folding sequence should be preserved.
+ */
+ public void setFoldingPreserved(boolean preserveFolding) {
+ this.preserveFolding = preserveFolding;
+ }
+
/**
* Unfolds the input and removes comments.
* @return unfolded header value with comments removed
@@ -107,7 +123,7 @@
|
t = <FOLD>
{
- buffer.append("\r\n");
+ if (preserveFolding) buffer.append("\r\n");
}
|
t = <WS>
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=671658&r1=671657&r2=671658&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
Wed Jun 25 14:08:13 2008
@@ -28,6 +28,40 @@
public static final Charset US_ASCII = Charset.forName("US-ASCII");
public static final Charset LATIN1 = Charset.forName("ISO-8859-1");
+ public static final String MULTIPART_WITH_CONTENT_LOCATION =
+ "From: Timothy Tayler <[EMAIL PROTECTED]>\r\n" +
+ "To: Samual Smith <[EMAIL PROTECTED]>\r\n" +
+ "Date: Thu, 14 Feb 2008 12:00:00 +0000 (GMT)\r\n" +
+ "Subject: A Multipart Email With Content-Location\r\n" +
+ "Content-Type: multipart/mixed;boundary=1729\r\n\r\n" +
+ "Start with a preamble\r\n" +
+ "\r\n--1729\r\n" +
+ "Content-Type: application/xhtml+xml\r\n" +
+ "Content-Location: relative/url\r\n\r\n" +
+ "<!DOCTYPE html\r\n" +
+ "PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\r\n" +
+ "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\r\n" +
+
"<html><head><title>Rhubarb</title></head><body>Rhubarb!</body></html>\r\n" +
+ "\r\n--1729\r\n" +
+ "Content-Type: text/plain; charset=US-ASCII\r\n" +
+ "Content-Location:
http://www.example.org/absolute/rhubard.txt\r\n\r\n" +
+ "Rhubarb!\r\n" +
+ "\r\n--1729\r\n" +
+ "Content-Type: text/html; charset=US-ASCII\r\n\r\n" +
+
"<html><head><title>Rhubarb</title></head><body>Rhubarb!</body></html>\r\n" +
+ "\r\n--1729\r\n" +
+ "Content-Type: text/plain; charset=US-ASCII\r\n" +
+ "Content-Location: (Some comment)
\"http://www.example.org/absolute/comments/rhubard.txt\"(Another
comment)\r\n\r\n" +
+ "Rhubarb!\r\n" +
+ "\r\n--1729\r\n" +
+ "Content-Type: text/html; charset=US-ASCII\r\n" +
+ "Content-Location:\"http://www.example.org/this/\r\n" +
+ " is/a/very/long/url/split/\r\n" +
+ " over/two/lines/\"\r\n\r\n" +
+
"<html><head><title>Rhubarb</title></head><body>Rhubarb!</body></html>\r\n" +
+ "\r\n--1729--\r\n" +
+ "This is the epilogue\r\n";
+
public static final String MULTIPART_WITH_BINARY_ATTACHMENTS =
"Return-Path: <[EMAIL PROTECTED]>\r\n" +
"Received: (qmail 18554 invoked from network); 25 May 2008 14:38:53
-0000\r\n" +
@@ -415,7 +449,7 @@
"Content-Type: multipart/alternative;boundary=1729\r\n\r\n" +
"Start with a preamble\r\n" +
"\r\n--1729\r\n" +
- "Content-Type: applcation/xhtml+xml\r\n\r\n" +
+ "Content-Type: application/xhtml+xml\r\n\r\n" +
"<!DOCTYPE html\r\n" +
"PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\r\n" +
"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\r\n" +
@@ -440,6 +474,7 @@
ascii(MIME_MIXED_MULTIPART_VARIOUS_ENCODINGS_END),
};
+ public static final byte[] MULTIPART_WITH_CONTENT_LOCATION_BYTES =
ascii(MULTIPART_WITH_CONTENT_LOCATION);
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);
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=671658&r1=671657&r2=671658&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
Wed Jun 25 14:08:13 2008
@@ -106,7 +106,7 @@
assertEquals(10234, descriptor.getContentDispositionSize());
}
- public void testLanguageTagParameters() throws Exception {
+ public void testLanguageParameters() throws Exception {
RFC3066ContentLanguageDescriptor descriptor =
describe(ExampleMail.MULTIPART_WITH_BINARY_ATTACHMENTS_BYTES, 3);
assertNotNull(descriptor.getContentLanguage());
assertEquals(3, descriptor.getContentLanguage().size());
@@ -115,6 +115,26 @@
assertEquals("en-CA", descriptor.getContentLanguage().get(2));
}
+ public void testContentLocationRelativeUrl() throws Exception {
+ RFC2557ContentLocationDescriptor descriptor =
describe(ExampleMail.MULTIPART_WITH_CONTENT_LOCATION_BYTES, 0);
+ assertEquals("relative/url", descriptor.getContentLocation());
+ }
+
+ public void testContentLocationAbsoluteUrl() throws Exception {
+ RFC2557ContentLocationDescriptor descriptor =
describe(ExampleMail.MULTIPART_WITH_CONTENT_LOCATION_BYTES, 1);
+ assertEquals("http://www.example.org/absolute/rhubard.txt",
descriptor.getContentLocation());
+ }
+
+ public void testContentLocationWithComment() throws Exception {
+ RFC2557ContentLocationDescriptor descriptor =
describe(ExampleMail.MULTIPART_WITH_CONTENT_LOCATION_BYTES, 3);
+ assertEquals("http://www.example.org/absolute/comments/rhubard.txt",
descriptor.getContentLocation());
+ }
+
+ public void testContentLocationFoldedUrl() throws Exception {
+ RFC2557ContentLocationDescriptor descriptor =
describe(ExampleMail.MULTIPART_WITH_CONTENT_LOCATION_BYTES, 4);
+
assertEquals("http://www.example.org/this/is/a/very/long/url/split/over/two/lines/",
descriptor.getContentLocation());
+ }
+
private MaximalBodyDescriptor describe(byte[] mail, int zeroBasedPart)
throws Exception {
ByteArrayInputStream bias = new ByteArrayInputStream(mail);
parser.parse(bias);
Modified:
james/mime4j/trunk/src/test/java/org/apache/james/mime4j/field/structured/StructuredFieldParserTest.java
URL:
http://svn.apache.org/viewvc/james/mime4j/trunk/src/test/java/org/apache/james/mime4j/field/structured/StructuredFieldParserTest.java?rev=671658&r1=671657&r2=671658&view=diff
==============================================================================
---
james/mime4j/trunk/src/test/java/org/apache/james/mime4j/field/structured/StructuredFieldParserTest.java
(original)
+++
james/mime4j/trunk/src/test/java/org/apache/james/mime4j/field/structured/StructuredFieldParserTest.java
Wed Jun 25 14:08:13 2008
@@ -64,6 +64,7 @@
private String parse(String in) throws Exception {
StructuredFieldParser parser = new StructuredFieldParser(new
StringReader(in));
+ parser.setFoldingPreserved(true);
return parser.parse();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]