we have a requirement to extract all the file attachments from notes messages in JAVA. We cannot use lotus scripts!
I am using the Notes getEmbeddedObjects() of RichTextItem to get all the attachments that are present in the “Body” of the message :
below is the code -
RichTextItem body = (RichTextItem)doc.getFirstItem(“Body”);
Vector v = body.getEmbeddedObjects();
Enumeration e = v.elements();
while (e!=null && e.hasMoreElements()) {
EmbeddedObject eo = (EmbeddedObject)e.nextElement();
//check if the object is a file attachment
String type = getObjectType(eo);
if (type.equals(“file attachment”)){
eo.extractFile(“C:\extracts\”+eo.getSource());
}
}
This approach fails when we have a message with just attachments and No Body (RichTextItem cannot be used as the attachment is not a part of the “Body” ).
Please let me know if you are aware of an alternate solution to extract attachments that are NOT a part of the Body or to extract attachments from messages that do not have a body.
Hi,thanks for your inputs and responses… it was of great help !I finally got it working using the doc.getItems and doc.getAttachment() properties… I am pasting the code snippet for your reference :
if(doc.hasItem(“$FILE”))
{
Vector items = doc.getItems();
for (int j=0; j<items.size(); j++) {
Item item = (Item)items.elementAt(j);
if(item.getName().equals("$FILE")){
System.out.println("document contains an attachment :");
EmbeddedObject eo = doc.getAttachment(item.getValueString());
if(eo!=null){
//check if the object is a file attachment
String type = getObjectType(eo);
log.info("\t\tNon RichTextItem : Type: " + type);
if (type.equals("file attachment")){
eo.extractFile("C:\\extracts\\"+eo.getSource());
}
}
}
}