Hi Alejandro,
either you create a parser to retrieve maximalbodydescriptor using:
parser = MimeTokenStream.createMaximalDescriptorStream();
This way the parser will give you a MaximalBodyDescriptor including the
data you want.
Otherwise in the upcoming mime4j 0.5 (probably out in few days) you can do
MimeEntityConfig config = new MimeEntityConfig();
config.setMaximalBodyDescriptor(true);
new MimeMessage(is, config);
You also tried with new MaximalBodyDescriptor(DefaultBodyDescriptor) but
this is not an encapsulation. Instead that method is used to create a
new bodyDescriptor within the given parent.
If you want to manually create the bodyDescriptor then simply start you
new MaximalBodyDescriptor and do the addField on that object instead of
using the DefaultBodyDescriptor.
Stefano
Alejandro Valdez ha scritto:
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]