I have three attachments in one of my lotus notes mail documents.
Desert.jpg, Hydrageas.jpg and Tulips.jpg
And I have the following code piece.
Vector<Item> itemList = lotusNotesDocument.getItems();
for (Item item : itemList)
{
if (item.getType() == Item.ATTACHMENT)
{
System.out.println("*****111********* ATTACHMENT=" + item.getName() + "=" + item.getValueString());
}
else if (item.getType() == Item.EMBEDDEDOBJECT)
{
System.out.println("*****222********* EMBEDDEDOBJECT=" + item.getName() + "=" + item.getValueString());
}
else if (item.getType() == Item.MIME_PART)
{
System.out.println("*****333********* MIME_PART=" + item.getName() + "=" + item.getValueString());
}
}
The output of this code is as follows
*****333********* MIME_PART=Body=
*****333********* MIME_PART=Body=
*****111********* ATTACHMENT=$FILE=Hydrangeas.jpg
*****111********* ATTACHMENT=$FILE=Hydrangeas.jpg
*****111********* ATTACHMENT=$FILE=Hydrangeas.jpg
*****333********* MIME_PART=Body=
*****333********* MIME_PART=Body=
Is this a bug in the domino API? have anyone else come across this before?
My exact requirement is to save the attachments to disk.
PS: I am using Lotus Expediter 6.2.3.20110921-0940
This really is a sort of bug, but so ancient that "it's just how Notes behave". If you have several items of the same name, you always get the first one.
However normally attchments in NotesDocument are embedded in rich text items, so you loop though rt items and get the attachments. If that is the case this code should do:
ForAll i In doc.Items
If i.Type = RICHTEXT Then
Print "rt item:", i.Name
If Not IsEmpty(i.EmbeddedObjects) Then
If ( i.Type = RICHTEXT ) Then
ForAll o In i.EmbeddedObjects
If ( o.Type = EMBED_ATTACHMENT ) Then
If dir(sPath & o.Name)<>"" Then Kill sPath & o.Name
Print sPath & o.Name
Call o.ExtractFile(sPath & o.Name)
End If
End ForAll
End If
End If
End If
End ForAll
For the case that they are not rich text item (attached directly to document), I'd think the code should be similar:
If Not IsEmpty(doc.Embeddedobjects) Then
ForAll o1 In doc.Embeddedobjects
If ( o1.Type = EMBED_ATTACHMENT ) Then
'Set o = obj2
If Dir(sPath & o1.Name)<>"" Then Kill sPath & o1.Name
Print "doc>", sPath & o1.Name
Call o1.ExtractFile(sPath & o1.Name)
End If
End ForAll
End If
however I just tested this code and was surprised to see that it DOES NOT pick up any attachments (nor even OLE objects in document) I wonder if anybody has a comment about this - I'm pretty sure it was working in good old days?
On further investigation - a solution that works for both - items and directly embedded ones is:
dim names, obj
names = Evaluate("@AttachmentNames", doc)
ForAll aname In names
Set obj = doc.Getattachment(aname)
Print "any>", sPath & obj.Name
Call obj.ExtractFile(sPath & obj.Name)
End ForAll
In all cases there is a limitation - in case you have several same named attachments you will have the "correct" name only once, all others will be using an internally generated name. I do not know a better solution than to drop down to C API to get this info.
I have found the answer.
I seems I have a
lotusNotesDocument.convertToMIME();
statement being executed before the code block that I posed earlier.
If I remove this the output is as follows
**1***111********* ATTACHMENT=$FILE=Desert.jpg
**1***111********* ATTACHMENT=$FILE=Hydrangeas.jpg
**1***111********* ATTACHMENT=$FILE=Tulips.jpg
I had the lotusNotesDocument.convertToMIME() in order to export the notes mail to the disk. So I will move those two statements below the attachment export section.
Found the answer through another post at the following Link
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.