Call getEmbeddedObjects (); (Domino Server API) returns incorrect results

Domino API getEmbeddedObjects(); returns an invalid result (zero) when mail containing an attachment (as an embedded object) is sent from a script. Although the attachment is dispatched as an EmbeddedOBject , getEmbeddedObjects(); returns ZERO . Type of mail is NOT MIME .

This is a Java application. Is there any workaround?

I take the body from the document. If the body has a richtextitem, I call getEmbeddedObjects (), which returns zero, although the attachment is present as an embedded object.

+4
source share
4 answers

Attachments do not have to be embedded in the RichText field. To quote using the designer’s help:

If you need access to OLE / 2 embedded objects that exist in the document but are not part of a rich text element (for example, since the object was originally created in the form of a document), use the EmbeddedObjects property in the document.

Another source of your problem may be that there are several RichText Body elements that you would need to check.

NTN

+2
source

Lotus Notes does not provide a single reliable method for extracting attachments from a NotesDocument object, unfortunately. To be thorough, you need to check all the richtext elements contained in it, as well as the document object itself.

I wrote the following code to extract attachments from selected emails in a mailbox to reduce file size (my users saved everything). However, the main loop is relevant to your question. It shows the process of iterating over all elements of a document that are looking for richtext elements with attachments, and then loop through all the elements again looking for elements of type "Attachment".

(forgive hacking code. It was not written for efficiency)

 Sub Initialize Set s = New NotesSession Set db = s.CurrentDatabase Set dc = db.UnprocessedDocuments Set doc = dc.GetFirstDocument Dim rtItem As NotesRichTextItem Dim RichTextItemNames List As String Dim DocumentItemNames List As String Dim itemCount as Integer While Not (doc Is Nothing) 'Scan all richtext items in document for embedded objects Forall i In doc.Items If i.Type = RICHTEXT Then Set rtItem = doc.GetFirstItem(i.Name) If Not Isempty(rtItem.EmbeddedObjects) Then RichTextItemNames(itemCount) = Cstr(i.Name) itemCount = itemCount + 1 End If End If End Forall 'Loop through richtext items and extract the embedded attachments For j = 0 To itemCount - 1 Set rtItem = doc.GetfirstItem(RichTextItemNames(j)) Forall Obj In rtItem.EmbeddedObjects If ( Obj.Type = EMBED_ATTACHMENT ) Then Call ExportAttachment(Obj) Call Obj.Remove Call doc.Save( False, True ) 'creates conflict doc if conflict exists End If End Forall Next 'Scan all items in document for Attachment type items itemCount = 0 Forall i In doc.Items If i.Type = ATTACHMENT Then DocumentItemNames(itemCount) = i.Values(0) itemCount = itemCount + 1 End If End Forall 'Loop through all attachment items in document and extract them For j = 0 To itemCount - 1 Set attachmentObject = doc.GetAttachment(DocumentItemNames(j)) Call ExportAttachment(attachmentObject) Call attachmentObject.Remove Call doc.Save( False, True ) 'creates conflict doc if conflict exists Next Set doc = dc.GetNextDocument(doc) Wend End Sub Sub ExportAttachment(o As Variant) Dim sAttachmentName As String Dim sNum As String Dim sTemp As String ' Append number to end of filename if filename exists. sAttachmentName = sDir & "\" & o.Source While Not (Dir$(sAttachmentName, 0) = "") sNum = Right(Strleftback(sAttachmentName, "."), 2) If Isnumeric(sNum) Then sTemp = Strleftback(sAttachmentName, ".") sTemp = Left(sTemp, Len(sTemp) - 2) sAttachmentName = sTemp & Format$(Cint(sNum) + 1, "##00") & _ "." & Strrightback(sAttachmentName, ".") Else sAttachmentName = Strleftback(sAttachmentName, ".") & _ "01." & Strrightback(sAttachmentName, ".") End If Wend Print "Exporting " & sAttachmentName 'Save the file Call o.ExtractFile( sAttachmentName ) End Sub 
+2
source

Looking through all the elements of a document for attachment, it does a lot of work for nothing. All you have to do is get the collection of attachment names using the @AttachmentNames formula (accessible using the evaluation method () of the Session object using the Document argument), and if the collection contains more than an empty string, use the getAttachment () of the document to get handle to the corresponding EmbeddedObject.

getAttachment () can capture any attachment in a document, whether it is associated with a RichTextItem or a V2-style attachment (as would be created by the web interface or when converting external mail). And never be afraid to use the language of the Formula when appropriate - it can make your life a lot easier.

+2
source

If you get embedded objects from a Document object, they will not contain attachments. Using getEmbeddedObjects with the body

RichTextItem also receives attachments.

Does it help?

+1
source

All Articles