Mime4j has general demonstrable performance problems:
http://buni.org/bugzilla/show_bug.cgi?id=137
http://blog.buni.org/blog/mbarker/Meldware/2007/01/27/Look-out-Its-behind-you

I'd suggest a general code review for the "byte at a time + buffered input stream" anti-pattern
and general refactoring to do things in blocks where possible.

-Andy

Niklas Therning wrote:
Norman Maurer wrote:
Hi all,

i just looked at the mime4j javadoc and wonder what whould be the best
solution to get all attachment names of a given inputstream.. I thought
this will maybe give me a better performance then using javamail for
this... Im wrong ?
Mime4j should be faster for this kind of things. See the attachment for
an example of how to get the filename parameter from the
Content-Disposition fields using Mime4j. I think you are looking for
something like this, right?
The other thing i noticed is that mime4j has no "altering" support.
Anything planned here ?
Nope, nothing planned at the moment. But if you have any ideas of how
Mime4j could be improved, please share them.

------------------------------------------------------------------------

import java.io.FileInputStream;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.mime4j.AbstractContentHandler;
import org.mime4j.EOLConvertingInputStream;
import org.mime4j.MimeStreamParser;
import org.mime4j.field.Field;
import org.mime4j.field.UnstructuredField;


public class Main {
    private static final Pattern P = 
Pattern.compile(".*filename=(\".*?\"|[^\\s]*).*");

    public static void main(String[] args) throws IOException {
        MyHandler handler = new MyHandler();
        MimeStreamParser parser = new MimeStreamParser();
        parser.setContentHandler(handler);
        parser.parse(new EOLConvertingInputStream(new 
FileInputStream(args[0])));
    }

    public static class MyHandler extends AbstractContentHandler {
        @Override
        public void field(String fieldData) {
            if (fieldData.toLowerCase().startsWith("content-disposition:")) {
                UnstructuredField field = (UnstructuredField) 
Field.parse(fieldData);
                Matcher m = P.matcher(field.getValue());
                if (m.matches()) {
                    String filename = m.group(1);
                    System.out.println(filename);
                }
            }
        }
    }
}

------------------------------------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to