开发者

Call to getEmbeddedObjects(); (Domino Server API) returns wrong results

开发者 https://www.devze.com 2023-03-10 07:05 出处:网络
The Domino server API getEmbeddedObjects(); returns the wrong result (z开发者_运维技巧ero) when a mail containing an attachment (as embedded object) is sent from the script.

The Domino server API getEmbeddedObjects(); returns the wrong result (z开发者_运维技巧ero) when a mail containing an attachment (as embedded object) is sent from the script. Though an attachment is sent as an EmbeddedOBject, getEmbeddedObjects(); returns ZERO. The mail type is NOT MIME.

This is a Java application. Is there is any workaround for this problem?

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


Looking through all of the items in a document for the possibility of an attachment is doing a lot of work for nothing. All you need to do is get the collection of attachment names using the @AttachmentNames formula (available through the evaluate() method of the Session object, using the Document argument), and if the collection contains more than an empty string, use the getAttachment() method of the document to get a handle to the corresponding EmbeddedObject.

getAttachment() can grab any attachment to a document, whether it's associated with a RichTextItem or a V2-style attachment (as would be created by a web UI or when converting external mail). And never be afraid to use Formula Language when it's appropriate -- it can make your life a whole lot simpler.


Attachments do not necessarily have to be embedded inside a RichText field. To quote from the designer-help:

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

Another source of your problem could be, that there are several "Body" RichText items you would have to check.

HTH


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

I wrote the following code to extract attachments from selected emails in a mailbox, in an effort to cut down the file size (my users saved everything). The main loop is relevant to your question, though. It shows the process of looping through all of the document's items looking for richtext items with attachments, followed by a loop through all items again looking for items of type "Attachment".

(forgive the hackiness of the code. It wasn't 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


If you get the embedded objects from the Document object, they won't contain attachments. Using getEmbeddedObjects with the "Body" RichTextItem gets the attachments too.

Does that help?

0

精彩评论

暂无评论...
验证码 换一张
取 消