Hi all!

I have a MIME base64 decoded message in which the header
Content-Transfer-Encoding is almost correct except for the fact that the
new line after the header is missing. In the current implementation of
mime4j (0.5) that file couldn't be decoded.
In the proposed patch, if the Content-Transfer-Encoding is not
recognized, it will be guessed if possible.

So, if the header is like the one I receive,i.e.:

Content-Transfer-Encoding: base64 Content-Disposition: attachment;

the Content-Transfer-Encoding is correctly guessed and the file
correctly decoded. I just made a little change to
org.apache.james.mime4j.descriptor.DefaultBodyDescriptor.

The file Excample.txt attached is an example of file that can be decoded only with the patch.

Thanks
Valentina


--
Valentina Medici

CUP 2000 S.p.A.
Via del Borgo di S. Pietro, 90/c - 40126 Bologna
tel. +39 051 4208411 - Fax +39 051 4208511

e-mail: valentina.med...@cup2000.it



--- DefaultBodyDescriptor.java  2009-01-21 11:02:08.000000000 +0100
+++ DefaultBodyDescriptor.vale  2009-01-21 11:09:40.000000000 +0100
@@ -103,7 +103,7 @@
             
             value = value.trim().toLowerCase();
             if (value.length() > 0) {
-                transferEncoding = value;
+                transferEncoding = isValidEncoding(value)? value: 
guessTransferEncoding(value);
             }
             
         } else if (name.equals("content-length")  &&  contentLength != -1) {
@@ -117,7 +117,32 @@
         }
     }
 
-    private void parseContentType(String value) {
+    private boolean isValidEncoding(String value) {            
+        if (MimeUtil.ENC_QUOTED_PRINTABLE.equals(value) ||
+           MimeUtil.ENC_BINARY.equals(value) ||
+           MimeUtil.ENC_BASE64.equals(value) ||
+           MimeUtil.ENC_8BIT.equals(value) ||
+           MimeUtil.ENC_7BIT.equals(value)) {
+           return true;
+       }
+        return false;
+    }
+
+    private String guessTransferEncoding(String value) {
+        log.warn("Invalid content-transfer-encoding: " + value);
+        int endIndex=value.indexOf(' ');
+        if (endIndex!=-1){
+            String guessedEncoding = value.substring(0,endIndex);
+            if (isValidEncoding(guessedEncoding)){
+                log.warn("Guessed encoding: "+ guessedEncoding);
+                return guessedEncoding;
+            }
+        }
+        log.warn("Unable to guess Content-transfer-encoding from value: " + 
value);
+        return value;
+    }
+
+       private void parseContentType(String value) {
         contentTypeSet = true;
         
         Map params = MimeUtil.getHeaderParams(value);


MIME-Version: 1.0 Content-Type: multipart/mixed; 
boundary=----_Abderaware_NextPart_4258668384642082 
Date: sab 10 gen 2009 12:14:23 +0200 This is a multi-part message in MIME 
format. 
------_Abderaware_NextPart_4258668384642082 
Content-Type: type/subtype; name="RefRad_90794111.txt" 
Content-Transfer-Encoding: base64 Content-Disposition: attachment;
filename="RefRad_90794111.txt" 

VGVzdCBCb2R5

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

Reply via email to