james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r674241 - in /james/mime4j/trunk/src: main/java/org/apache/james/mime4j/ main/java/org/apache/james/mime4j/util/ test/java/org/apache/james/mime4j/
Date Sat, 05 Jul 2008 20:56:26 GMT
Author: rdonkin
Date: Sat Jul  5 13:56:25 2008
New Revision: 674241

URL: http://svn.apache.org/viewvc?rev=674241&view=rev
Log:
Added support for Content-MD5

Added:
    james/mime4j/trunk/src/main/java/org/apache/james/mime4j/RFC1864ContentMD5Descriptor.java
Modified:
    james/mime4j/trunk/src/main/java/org/apache/james/mime4j/MaximalBodyDescriptor.java
    james/mime4j/trunk/src/main/java/org/apache/james/mime4j/RFC2557ContentLocationDescriptor.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=674241&r1=674240&r2=674241&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
Jul  5 13:56:25 2008
@@ -37,7 +37,7 @@
  * 
  */
 public class MaximalBodyDescriptor extends DefaultBodyDescriptor implements RFC2045MimeDescriptor,

-        RFC2183ContentDispositionDescriptor, RFC3066ContentLanguageDescriptor, RFC2557ContentLocationDescriptor
{
+        RFC2183ContentDispositionDescriptor, RFC3066ContentLanguageDescriptor, RFC2557ContentLocationDescriptor,
RFC1864ContentMD5Descriptor {
 
     private static final int DEFAULT_MINOR_VERSION = 0;
     private static final int DEFAULT_MAJOR_VERSION = 1;
@@ -66,6 +66,8 @@
     private MimeException contentLocationParseException;
     private String contentLocation;
     private boolean isContentLocationSet;
+    private String contentMD5Raw;
+    private boolean isContentMD5Set;
     
     protected MaximalBodyDescriptor() {
         this(null);
@@ -97,6 +99,8 @@
         this.contentLocation = null;
         this.contentLocationParseException = null;
         this.isContentLocationSet = false;
+        this.contentMD5Raw = null;
+        this.isContentMD5Set = false;
     }
     
     public void addField(String name, String value) {
@@ -113,11 +117,20 @@
             parseLanguage(value);
         } else if (MimeUtil.MIME_HEADER_LOCATION.equals(name) && !isContentLocationSet)
{
             parseLocation(value);
+        } else if (MimeUtil.MIME_HEADER_MD5.equals(name) && !isContentMD5Set) {
+            parseMD5(value);
         } else {
             super.addField(name, value);
         }
     }
     
+    private void parseMD5(String value) {
+        isContentMD5Set = true;
+        if (value != null) {
+            contentMD5Raw = value.trim();
+        }
+    }
+
     private void parseLocation(final String value) {
         isContentLocationSet = true;
         if (value != null) {
@@ -373,4 +386,13 @@
     public MimeException getContentLocationParseException() {
         return contentLocationParseException;
     }
+    
+    /**
+     * @see org.apache.james.mime4j.RFC1864ContentMD5Descriptor#getContentMD5Raw()
+     */
+    public String getContentMD5Raw() {
+        return contentMD5Raw;
+    }
+    
+    
 } 

Added: james/mime4j/trunk/src/main/java/org/apache/james/mime4j/RFC1864ContentMD5Descriptor.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/main/java/org/apache/james/mime4j/RFC1864ContentMD5Descriptor.java?rev=674241&view=auto
==============================================================================
--- james/mime4j/trunk/src/main/java/org/apache/james/mime4j/RFC1864ContentMD5Descriptor.java
(added)
+++ james/mime4j/trunk/src/main/java/org/apache/james/mime4j/RFC1864ContentMD5Descriptor.java
Sat Jul  5 13:56:25 2008
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+/**
+ * Describes <a href='http://tools.ietf.org/html/rfc1864'>RFC1864</a>  
+ * <code>Content-MD5</code>.
+ */
+public interface RFC1864ContentMD5Descriptor {
+
+    /**
+     * Gets the raw, Base64 encoded value of the
+     * <code>Content-MD5</code> field.
+     * See <a href='http://tools.ietf.org/html/rfc1864'>RFC1864</a>.
+     * @return raw encoded content-md5
+     * or null if no header exists
+     */
+    public abstract String getContentMD5Raw();
+
+}
\ No newline at end of file

Modified: 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=674241&r1=674240&r2=674241&view=diff
==============================================================================
--- james/mime4j/trunk/src/main/java/org/apache/james/mime4j/RFC2557ContentLocationDescriptor.java
(original)
+++ james/mime4j/trunk/src/main/java/org/apache/james/mime4j/RFC2557ContentLocationDescriptor.java
Sat Jul  5 13:56:25 2008
@@ -18,6 +18,10 @@
  */
 package org.apache.james.mime4j;
 
+/**
+ * Describes <a href='http://tools.ietf.org/html/rfc2557'>RFC2557</a>  
+ * <code>Content-Location</code>.
+ */
 public interface RFC2557ContentLocationDescriptor {
 
     /**

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=674241&r1=674240&r2=674241&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 Jul  5
13:56:25 2008
@@ -101,6 +101,11 @@
      * See <a href='http://www.faqs.org/rfcs/rfc2557.html'>RFC2557</a>.
      */
     public static final String MIME_HEADER_LOCATION = "content-location";
+    /**
+     * <code>Content-MD5</code> header (lower case).
+     * See <a href='http://www.faqs.org/rfcs/rfc1864.html'>RFC1864</a>.
+     */
+    public static final String MIME_HEADER_MD5 = "content-md5";
     
     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=674241&r1=674240&r2=674241&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 Jul  5 13:56:25
2008
@@ -23,6 +23,7 @@
 
 public class ExampleMail {
     
+    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");
@@ -253,6 +254,7 @@
         "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" +
+        "Content-MD5: " + MD5_CONTENT + "\r\n" +
         "Delivered-To: robertburrelldonkin@gmail.com\r\n" +
         "\r\n" +
         ONE_PART_MIME_ASCII_BODY;

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=674241&r1=674240&r2=674241&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 Jul  5 13:56:25 2008
@@ -135,6 +135,11 @@
         assertEquals("http://www.example.org/this/is/a/very/long/url/split/over/two/lines/",
descriptor.getContentLocation());
     }
     
+    public void testContentMD5Url() throws Exception {
+        RFC1864ContentMD5Descriptor descriptor = describe(ExampleMail.ONE_PART_MIME_WITH_CONTENT_DISPOSITION_PARAMETERS_BYTES);
+        assertEquals(ExampleMail.MD5_CONTENT, descriptor.getContentMD5Raw());
+    }
+    
     private MaximalBodyDescriptor describe(byte[] mail, int zeroBasedPart) throws Exception
{
         ByteArrayInputStream bias = new ByteArrayInputStream(mail);
         parser.parse(bias);



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message