Lotus-Notes 代理:仅从当前电子邮件中恢复文件

Lotus-Notes Agent: Recover only the files from the current email

目前在我的代理中,我这样浏览我的电子邮件文件:

    Dim session As New NotesSession
    Dim db As NotesDatabase
    Dim view As NotesView
    Dim doc As NotesDocument
    Dim item As Variant
    Dim ws As New NotesUIWorkspace
    Dim uidoc As NotesUIDocument

    Dim myServer As String
    Dim myMailfile As String

    myServer = <server>
    myMailfile = <mailfile>
    ' *** Open the specified mail file using back-end classes
    Set db = New NotesDatabase(myServer, myMailfile)
    
    If Not (db Is Nothing) Then
        Set view = db.GETVIEW("$Inbox")
        If Not (view Is Nothing) Then
            Call view.Refresh
            Set doc = view.GETFIRSTDOCUMENT
            Do While Not doc Is Nothing
                On Error Resume Next
                Set item = doc.GETFIRSTITEM("Body")
                If doc.HasEmbedded Then
                    item.EmbeddedObjects
                    ForAll attachment In item.EmbeddedObjects
                        Call attachment.ExtractFile ("C:\Users\admin\Documents\files\" & attachment.Name)
                    End ForAll
                End If
                Set doc = view.GETNEXTDOCUMENT(doc)
            Loop
        End If
    End If

但它会恢复我电子邮件中的所有文件。而我只想从当前电子邮件(我选择的电子邮件)中恢复文件。可以吗?

感谢您的帮助

在代理属性中,您可以设置代理的“目标”是什么。默认情况下它是“选定的文档”。使用 NotesDatabase- 对象的“UnprocessedDocuments”- 属性 使“目标”可供代理使用。

Dim dc as NotesDocumentCollection
Set db = session.CurrentDatabase '- get the database where the agent runs
Set dc = db.UnprocessedDocuments
Set doc = dc.GetFirstDocument()
While not doc is Nothing
    '- here comes the inner code from your own while loop
    Set doc = dc.GetNextDocument( doc )
Wend

只有一件事:item.EmbeddedObjects 不会获取您邮件的所有附件。 MIME 邮件中的附件可能会失败。

如果您真的想要获取所有附件,无论邮件的来源/类型如何,您都应该使用@AttachmentNames(0) - 解决方法:

Dim arrAttachments as Variant
Dim embObj as NotesEmbeddedObject

arrAttachments = Evaluate( "@Attachmentnames(0)" )
Forall strAttachment in arrAttachments
  Set embObj = doc.GetAttachment(strAttachment)
  Call embObj.ExtractFile ("C:\Users\admin\Documents\files\" & embObj.Name)
End Forall