You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by im...@apache.org on 2007/01/16 13:54:33 UTC

svn commit: r496675 - in /jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime: MimeFileContentInfoFactory.java MimeFileObject.java

Author: imario
Date: Tue Jan 16 04:54:32 2007
New Revision: 496675

URL: http://svn.apache.org/viewvc?view=rev&rev=496675
Log:
deliver mail content only (no header) with inputStream, adjusted contentInfo to determine the correct content type/encoding

Modified:
    jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileContentInfoFactory.java
    jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileObject.java

Modified: jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileContentInfoFactory.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileContentInfoFactory.java?view=diff&rev=496675&r1=496674&r2=496675
==============================================================================
--- jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileContentInfoFactory.java (original)
+++ jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileContentInfoFactory.java Tue Jan 16 04:54:32 2007
@@ -23,7 +23,10 @@
 import org.apache.commons.vfs.impl.DefaultFileContentInfo;
 
 import javax.mail.MessagingException;
+import javax.mail.Part;
+import javax.mail.Message;
 import javax.mail.internet.ContentType;
+import java.io.IOException;
 
 /**
  * get access to the content info stuff for mime objects
@@ -36,33 +39,56 @@
 	public FileContentInfo create(FileContent fileContent) throws FileSystemException
 	{
 		MimeFileObject mimeFile = (MimeFileObject) fileContent.getFile();
-
-		ContentType contentType;
 		try
 		{
-			String contentTypeString = mimeFile.getPart().getContentType();
-			contentType = new ContentType(contentTypeString);
+			if (mimeFile.isMultipart())
+			{
+				// if this is a multipart message we deliver the preamble instead of an inupt string
+				// the preamble will be delivered in UTF-8 - fixed
+				return new DefaultFileContentInfo("text/plain", MimeFileSystem.PREAMBLE_CHARSET); // NON-NLS
+			}
 		}
 		catch (MessagingException e)
 		{
 			throw new FileSystemException(e);
 		}
 
-		String charset = contentType.getParameter("charset");
+		String contentTypeString = null;
+
+		Part part = mimeFile.getPart();
 		try
 		{
-			if (mimeFile.isMultipart())
+			Object content = part.getContent();
+			if (content instanceof Message)
 			{
-				// if this is a multipart message we deliver the preamble instead of an inupt string
-				// the preamble will be delivered in UTF-8 - fixed
-				charset = MimeFileSystem.PREAMBLE_CHARSET;
+				contentTypeString = ((Message) content).getContentType();
+			}
+			else
+			{
+				contentTypeString = part.getContentType();
 			}
 		}
+		catch (IOException e)
+		{
+			throw new FileSystemException(e);
+		}
+		catch (MessagingException e)
+		{
+			throw new FileSystemException(e);
+		}
+
+		ContentType contentType;
+		try
+		{
+			contentType = new ContentType(contentTypeString);
+		}
 		catch (MessagingException e)
 		{
-			throw  new FileSystemException(e);
+			throw new FileSystemException(e);
 		}
 
-		return new DefaultFileContentInfo(contentType.getBaseType(), charset);
+		return new DefaultFileContentInfo(
+			contentType.getBaseType(),
+			contentType.getParameter("charset")); // NON-NLS
 	}
 }

Modified: jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileObject.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileObject.java?view=diff&rev=496675&r1=496674&r2=496675
==============================================================================
--- jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileObject.java (original)
+++ jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileObject.java Tue Jan 16 04:54:32 2007
@@ -244,10 +244,20 @@
     {
 		if (isMultipart())
 		{
+			// deliver the preamble as the only content
+
 			String preamble = ((MimeMultipart) part.getContent()).getPreamble();
 			return new ByteArrayInputStream(preamble.getBytes(MimeFileSystem.PREAMBLE_CHARSET));
 		}
 
+		// try to deliver the content only
+		Object content = part.getContent();
+		if (content instanceof Message)
+		{
+			return ((Message) content).getInputStream();
+		}
+
+		// hmmm ... dont know, deliver the plain stream
 		return part.getInputStream();
 	}
 
@@ -296,4 +306,4 @@
 	{
 		return part.getAllHeaders();
 	}
-}
+}
\ No newline at end of file



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