You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Simon Kitching <si...@ecnetwork.co.nz> on 2003/06/26 04:41:54 UTC

looking for multipart-mime-handling library

Hi All,

I'm looking for code which can handle multipart mime messages, both
building them and decoding them.

Currently I am using the javax.mail apis, with the implementation
downloadable from Sun. However, frankly, the javax.mail API stinks. And
the implementation isn't much better, as well as being closed-source. In
fact I've run into a showstopper bug in it which means I'm now looking
around for any alternative implementations. As a last resort I can
roll-my-own but I'd rather not.

Is there any project (apache or otherwise) which provides mime handling
utilities? I guess there is some in james.apache.org, but it doesn't
seem to be separated out (not that I've looked deeply yet).

If there isn't anything around, how would people feel about adding it to
codec? I think it is a good fit for that project, with the major
question being whether there is enough demand to make it worth doing...


Cheers,

Simon


Re: looking for multipart-mime-handling library

Posted by Simon Kitching <si...@ecnetwork.co.nz>.
On Fri, 2003-06-27 at 16:02, Martin Cooper wrote:
> On Wed, 26 Jun 2003, Simon Kitching wrote:
> 
> > Hi All,
> >
> > I'm looking for code which can handle multipart mime messages, both
> > building them and decoding them.
[snip]
> There's some multipart parsing code buried in FileUpload, and probably
> bits and pieces in other Jakarta components. I'm not aware of a really
> comprehensive and robust open source implementation, though.
[snip]
> If you're really going to do it right, I would think that it would merit
> its own component. I don't think the question is really whether or not
> there would be enough users, I think it's more like would there be enough
> interest in developing such a beast to build a community around it. I'm
> sure there would be plenty of people who would be happy to use it.
> 
> --
> Martin Cooper

Thanks Martin. I will have a look at what FileUpload has...



Re: looking for multipart-mime-handling library

Posted by Martin Cooper <ma...@apache.org>.

On Wed, 26 Jun 2003, Simon Kitching wrote:

> Hi All,
>
> I'm looking for code which can handle multipart mime messages, both
> building them and decoding them.
>
> Currently I am using the javax.mail apis, with the implementation
> downloadable from Sun. However, frankly, the javax.mail API stinks. And
> the implementation isn't much better, as well as being closed-source. In
> fact I've run into a showstopper bug in it which means I'm now looking
> around for any alternative implementations. As a last resort I can
> roll-my-own but I'd rather not.

Yup, JavaMail sucks. The FAQ actually includes the following statement:

"In general you'll find that the JavaMail API errs on the side of "simple"
instead of "robust"."

Great. Thanks.

>
> Is there any project (apache or otherwise) which provides mime handling
> utilities? I guess there is some in james.apache.org, but it doesn't
> seem to be separated out (not that I've looked deeply yet).

There's some multipart parsing code buried in FileUpload, and probably
bits and pieces in other Jakarta components. I'm not aware of a really
comprehensive and robust open source implementation, though.

>
> If there isn't anything around, how would people feel about adding it to
> codec? I think it is a good fit for that project, with the major
> question being whether there is enough demand to make it worth doing...

If you're really going to do it right, I would think that it would merit
its own component. I don't think the question is really whether or not
there would be enough users, I think it's more like would there be enough
interest in developing such a beast to build a community around it. I'm
sure there would be plenty of people who would be happy to use it.

--
Martin Cooper


>
>
> Cheers,
>
> Simon
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>

Re: looking for multipart-mime-handling library

Posted by Scott Walters <wa...@edge.net>.
I found the javamail jars to be good for this but the missing piece that
I could never find in it was something to determine the boundary string
when parsing an existing document.  After digging throughly into the
javamail source code, I determined that it doesn't seem to do this at
all.  Once I wrote this and figured out how to plug it my own code to
the framework, everything worked great.  The class I wrtote for this is
called MimeStringDataSource and is attached below. It extends
javax.activation.DataSource and an instance of it is passed into the
MimeMultipart ctor like so...

MimeMultipart mm = new MimeMultipart(new MimeStringDataSource(new
String(mimeDocument)));


Here's the MimeStringDataSource class.  The getContentType method is
invoked by the mail framework and determines the start and end of the
boundary string.  Then it creates an instance of
javax.mail.internet.ContentType and sets the boundary parameter on it to
the newly determined boundary string.  The string representation of the
ContentType object that contains the correct boundary string is returned
to the MimeMultipart ctor.

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.activation.DataSource;
import javax.mail.internet.ContentType;

/**
 * @author Administrator
 *
 * To change this generated comment edit the template variable
"typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
 */
public class MimeStringDataSource implements DataSource {

	private String _src;
	public MimeStringDataSource(String src) {
		_src = src;
	}

	/**
	 * @see javax.activation.DataSource#getContentType()
	 */
	public String getContentType() {
		ContentType cType = new ContentType("multipart", "mixed", null);
		String boundary = null;
		int curpos = 0, endpos, delimSize = 2;
		String delimCompare = "--";
		while(boundary == null) {
			endpos = _src.indexOf("\r\n", curpos);
			if (endpos < 0) {
				endpos = _src.indexOf("\n", curpos);
				delimSize = 1;
				delimCompare = "-";
				if (endpos < 0)
					endpos = _src.indexOf("\r", curpos);
				if (endpos < 0)
					return "unknown";
			}
			if (_src.substring(curpos, curpos+2).equals("--"))
				boundary = _src.substring(curpos+2, endpos);
			else
				curpos = endpos + 2;
		}
		cType.setParameter("boundary", boundary);
		return cType.toString();
	}

	/**
	 * @see javax.activation.DataSource#getInputStream()
	 */
	public InputStream getInputStream() throws IOException {
		return new ByteArrayInputStream(_src.getBytes());
	}

	/**
	 * @see javax.activation.DataSource#getName()
	 */
	public String getName() {
		return new String("MimeStringDataSource");
	}

	/**
	 * @see javax.activation.DataSource#getOutputStream()
	 */
	public OutputStream getOutputStream() throws IOException {
		return new ByteArrayOutputStream();
	}

}


Bill Keese wrote:
> For encoding multipart mime messages, there's httpclient's
> MultipartPostMethod, but maybe that's tied to http (and also I'm not sure
> where the decoding counterpart is)
> 
> ----- Original Message ----- 
> From: "Simon Kitching" <si...@ecnetwork.co.nz>
> To: <co...@jakarta.apache.org>
> Sent: Thursday, June 26, 2003 11:41 AM
> Subject: looking for multipart-mime-handling library
> 
> 
> 
>>Hi All,
>>
>>I'm looking for code which can handle multipart mime messages, both
>>building them and decoding them.
>>
>>Currently I am using the javax.mail apis, with the implementation
>>downloadable from Sun. However, frankly, the javax.mail API stinks. And
>>the implementation isn't much better, as well as being closed-source. In
>>fact I've run into a showstopper bug in it which means I'm now looking
>>around for any alternative implementations. As a last resort I can
>>roll-my-own but I'd rather not.
>>
>>Is there any project (apache or otherwise) which provides mime handling
>>utilities? I guess there is some in james.apache.org, but it doesn't
>>seem to be separated out (not that I've looked deeply yet).
>>
>>If there isn't anything around, how would people feel about adding it to
>>codec? I think it is a good fit for that project, with the major
>>question being whether there is enough demand to make it worth doing...
>>
>>
>>Cheers,
>>
>>Simon
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>>
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 



Re: looking for multipart-mime-handling library

Posted by Bill Keese <bi...@tech.beacon-it.co.jp>.
For encoding multipart mime messages, there's httpclient's
MultipartPostMethod, but maybe that's tied to http (and also I'm not sure
where the decoding counterpart is)

----- Original Message ----- 
From: "Simon Kitching" <si...@ecnetwork.co.nz>
To: <co...@jakarta.apache.org>
Sent: Thursday, June 26, 2003 11:41 AM
Subject: looking for multipart-mime-handling library


> Hi All,
>
> I'm looking for code which can handle multipart mime messages, both
> building them and decoding them.
>
> Currently I am using the javax.mail apis, with the implementation
> downloadable from Sun. However, frankly, the javax.mail API stinks. And
> the implementation isn't much better, as well as being closed-source. In
> fact I've run into a showstopper bug in it which means I'm now looking
> around for any alternative implementations. As a last resort I can
> roll-my-own but I'd rather not.
>
> Is there any project (apache or otherwise) which provides mime handling
> utilities? I guess there is some in james.apache.org, but it doesn't
> seem to be separated out (not that I've looked deeply yet).
>
> If there isn't anything around, how would people feel about adding it to
> codec? I think it is a good fit for that project, with the major
> question being whether there is enough demand to make it worth doing...
>
>
> Cheers,
>
> Simon
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>