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 15:48:26 UTC
svn commit: r496713 - in
/jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime:
MimeFileContentInfoFactory.java MimeFileObject.java MimeFileSystem.java
Author: imario
Date: Tue Jan 16 06:48:22 2007
New Revision: 496713
URL: http://svn.apache.org/viewvc?view=rev&rev=496713
Log:
introduced another special file "_content" to allow access to the mail itself (eg. its content-type) and to its content
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
jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileSystem.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=496713&r1=496712&r2=496713
==============================================================================
--- 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 06:48:22 2007
@@ -16,17 +16,15 @@
*/
package org.apache.commons.vfs.provider.mime;
-import org.apache.commons.vfs.FileContentInfoFactory;
-import org.apache.commons.vfs.FileContentInfo;
import org.apache.commons.vfs.FileContent;
+import org.apache.commons.vfs.FileContentInfo;
+import org.apache.commons.vfs.FileContentInfoFactory;
import org.apache.commons.vfs.FileSystemException;
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
@@ -39,13 +37,22 @@
public FileContentInfo create(FileContent fileContent) throws FileSystemException
{
MimeFileObject mimeFile = (MimeFileObject) fileContent.getFile();
+ Part part = mimeFile.getPart();
+
+ String contentTypeString = null;
+ String charset = null;
+
try
{
+ // special handling for multipart
if (mimeFile.isMultipart())
{
- // if this is a multipart message we deliver the preamble instead of an inupt string
+ // get the original content type, but ...
+ contentTypeString = part.getContentType();
+
+ // .... 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
+ charset = MimeFileSystem.PREAMBLE_CHARSET;
}
}
catch (MessagingException e)
@@ -53,29 +60,18 @@
throw new FileSystemException(e);
}
- String contentTypeString = null;
-
- Part part = mimeFile.getPart();
- try
+ if (contentTypeString == null)
{
- Object content = part.getContent();
- if (content instanceof Message)
+ // normal message ... get the content type
+ try
{
- contentTypeString = ((Message) content).getContentType();
+ contentTypeString = part.getContentType();
}
- else
+ catch (MessagingException e)
{
- contentTypeString = part.getContentType();
+ throw new FileSystemException(e);
}
}
- catch (IOException e)
- {
- throw new FileSystemException(e);
- }
- catch (MessagingException e)
- {
- throw new FileSystemException(e);
- }
ContentType contentType;
try
@@ -87,8 +83,15 @@
throw new FileSystemException(e);
}
+ if (charset == null)
+ {
+ // charset might already be set by the multipart message stuff, else
+ // extract it from the contentType now
+ charset = contentType.getParameter("charset"); // NON-NLS
+ }
+
return new DefaultFileContentInfo(
contentType.getBaseType(),
- contentType.getParameter("charset")); // NON-NLS
+ charset);
}
}
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=496713&r1=496712&r2=496713
==============================================================================
--- 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 06:48:22 2007
@@ -22,6 +22,7 @@
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.FileType;
import org.apache.commons.vfs.NameScope;
+import org.apache.commons.vfs.VFS;
import org.apache.commons.vfs.provider.AbstractFileObject;
import org.apache.commons.vfs.provider.AbstractFileSystem;
import org.apache.commons.vfs.provider.UriParser;
@@ -86,32 +87,34 @@
return null;
}
- if (!isMultipart())
- {
- // not a multipart
- return null;
- }
-
- Multipart multipart = (Multipart) part.getContent();
- if (partName.startsWith(MimeFileSystem.NULL_BP_NAME))
+ if (isMultipart())
{
- int partNumber = Integer.parseInt(partName.substring(MimeFileSystem.NULL_BP_NAME.length()), 10);
- if (partNumber < 0 || partNumber+1 > multipart.getCount())
+ Multipart multipart = (Multipart) part.getContent();
+ if (partName.startsWith(MimeFileSystem.NULL_BP_NAME))
{
- // non existent
- return null;
+ int partNumber = Integer.parseInt(partName.substring(MimeFileSystem.NULL_BP_NAME.length()), 10);
+ if (partNumber < 0 || partNumber+1 > multipart.getCount())
+ {
+ // non existent
+ return null;
+ }
+
+ return multipart.getBodyPart(partNumber);
}
- return multipart.getBodyPart(partNumber);
+ for (int i = 0; i<multipart.getCount(); i++)
+ {
+ Part childPart = multipart.getBodyPart(i);
+ if (partName.equals(childPart.getFileName()))
+ {
+ return childPart;
+ }
+ }
}
- for (int i = 0; i<multipart.getCount(); i++)
+ if (partName.equals(MimeFileSystem.CONTENT_NAME))
{
- Part childPart = multipart.getBodyPart(i);
- if (partName.equals(childPart.getFileName()))
- {
- return childPart;
- }
+ return (Part) part.getContent();
}
return null;
@@ -132,11 +135,13 @@
return FileType.IMAGINARY;
}
+ /*
if (!isMultipart())
{
// we cant have children ...
return FileType.FILE;
}
+ */
// we have both
return FileType.FILE_OR_FOLDER;
@@ -158,7 +163,7 @@
return null;
}
- List vfs = Collections.EMPTY_LIST;
+ List vfs = new ArrayList();
if (isMultipart())
{
Object container = part.getContent();
@@ -187,6 +192,20 @@
}
}
}
+ else
+ {
+ Object content = part.getContent();
+ if (content instanceof Part)
+ {
+ MimeFileObject fo = (MimeFileObject) FileObjectUtils.getAbstractFileObject(getFileSystem().resolveFile(
+ getFileSystem().getFileSystemManager().resolveName(
+ getName(),
+ MimeFileSystem.CONTENT_NAME,
+ NameScope.CHILD)));
+ fo.setPart((Part) content);
+ vfs.add(fo);
+ }
+ }
return (MimeFileObject[]) vfs.toArray(new MimeFileObject[vfs.size()]);
}
@@ -250,14 +269,6 @@
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();
}
Modified: jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileSystem.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileSystem.java?view=diff&rev=496713&r1=496712&r2=496713
==============================================================================
--- jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileSystem.java (original)
+++ jakarta/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileSystem.java Tue Jan 16 06:48:22 2007
@@ -47,6 +47,7 @@
private Log log = LogFactory.getLog(MimeFileSystem.class);
public final static String NULL_BP_NAME = "_body_part_";
+ public final static String CONTENT_NAME = "_content";
public final static String PREAMBLE_CHARSET = "UTF-8";
private InputStream mimeStream = null;
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org