Hello everybody, I'm new to the list and I'm learning to use mime4j as
a mime parser, I'm doing well so far but can't figure out how to
detect if a BodyPart is an attachment.

I do something like:

Message msg = new Message(...) ;

to get a Message object,  then I do a recursive scan in the Message
parts to find a part that is not multipart. This procedure give me a
BodyPart object, but I can't find a way in the API to identify it as
an attachment.

Looking the mime4j API I found the clasess DefaultBodyDescriptor and
MaximalBodyDescriptor, the class MaximalBodyDescriptor has a method
getContentDispositionType() that I think should return 'attachment'
when the part is an attachment. I did not find a direct way to get a
MaximalBodyDescriptor from a BodyPart, so I did the following:


DefaultBodyDescriptor bodyDescriptor = new DefaultBodyDescriptor();             
                
List<Field> partHeaderFields = part.getHeader().getFields();
Iterator<Field> fieldsIt = partHeaderFields.iterator();
while (fieldsIt.hasNext()) {
        Field field = fieldsIt.next();
        String fieldName = field.getName();
        String fieldValue = field.getBody();
        bodyDescriptor.addField(fieldName, fieldValue);
        }
MaximalBodyDescriptor maximalBodyDescriptor = new
MaximalBodyDescriptor(bodyDescriptor);
String contentDispositionType =
maximalBodyDescriptor.getContentDispositionType();

But the call maximalBodyDescriptor.getContentDispositionType() returns
'null', even when the part analized is an attachment and has the
header Content-Disposition: "attachment".

I know that I can do a string pattern matching in field.getName() and
field.getBody(), looking for 'content-type' and 'attachment', but I
would like to do it using the mime4j API.

I'm really clueless Any ideas?

Thanks in advance, Alejandro.

PS: I'm not sure if it is the right mailing list for this kind of post...

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

Reply via email to