Lotus Notes Agent - 删除嵌入的图像?

发布于 2024-10-17 16:20:29 字数 5939 浏览 3 评论 0原文

我有一个多年前分享的代理,它可以获取附加文件,将它们保存到我的硬盘上,然后从电子邮件中删除它们。我用它来保留我的电子邮件一段时间,但不超过我的公司邮箱配额。我收到很多附件。

我现在发现许多剩余的大型电子邮件都嵌入了图像而不是“附加文件”。任何人都可以共享一个实际上能够对嵌入图像执行相同操作(保存到硬盘驱动器,从电子邮件中删除)的脚本吗?

FWIW,这是我用来分离附件的代理。感谢原作者,不知道是谁。

Dim sDir As String
Dim s As NotesSession
Dim w As NotesUIWorkspace
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument

Sub Initialize

    Set s = New NotesSession
    Set w = New NotesUIWorkspace 
    Set db = s.CurrentDatabase
    Set dc = db.UnprocessedDocuments
    Set doc = dc.GetFirstDocument
    Dim rtItem As NotesRichTextItem
    Dim RTNames List As String
    Dim DOCNames List As String
    Dim itemCount As Integer
    Dim sDefaultFolder As String

    Dim vtDir As Variant
    Dim iCount As Integer
    Dim j As Integer
    Dim lngExportedCount As Long
    Dim attachmentObject As Variant
    Dim text As String

    Dim subjectLine As String
    Dim attachmentMoved As Boolean

    ' Prompt the user to ensure they wish to continue extracting the attachments
    Dim x As Integer
    x = Msgbox("V4 This action will extract all attachments from the " & Cstr (dc.Count) &  " document(s) you have selected, and place them into the folder of your choice." & _
    Chr(10) & Chr(10) & "Would you like to continue?", 32 + 4, "Export Attachments")
    If x <> 6 Then Exit Sub 

    ' Set the folder where the attachments will be exported
    sDefaultFolder = s.GetEnvironmentString("LPP_ExportAttachments_DefaultFolder")
    If sDefaultFolder = "" Then sDefaultFolder = "F:"  
    vtDir = w.SaveFileDialog( False, "Export attachments to which folder?", "All files|*.*", sDefaultFolder, "Choose Folder and Click Save")
    If Isempty(vtDir) Then Exit Sub
    sDir = Strleftback(vtDir(0), "\")
    Call s.SetEnvironmentVar("LPP_ExportAttachments_DefaultFolder", sDir) 

    ' Loop through all the selected documents
    While Not (doc Is Nothing)

        iCount = 0
        itemCount = 0
        lngExportedCount = 0
        Erase RTNames
        Erase DocNames

        ' Find all of the RichText fields in the current document.  If any have an embedded object, add the item to the RTNames array.
        Forall i In doc.Items
            If i.Type = RICHTEXT Then
                If Not Isempty(i.EmbeddedObjects) Then
                    'Msgbox i.Name,64,"Has embedded objects"                    
                End If
                Set rtItem = doc.GetfirstItem(i.Name)
                'Set rtItem = i
                If Not Isempty(rtItem.EmbeddedObjects) Then
                    RTNames(itemCount) = Cstr(i.Name)
                    itemCount = itemCount +1
                End If
            End If

        End Forall  

        ' Loop through the RTNames array and see if any of the embedded objects are attachments
        attachmentMoved = False
        For j = 0 To itemCount-1 
            Set rtItem = Nothing
            Set rtItem = doc.GetfirstItem(RTNames(j))
            Forall Obj In rtItem.EmbeddedObjects
                If ( Obj.Type = EMBED_ATTACHMENT ) Then
                    ' The embedded object is an attachment.  Export it to the chosen directory
                    Call ExportAttachment(Obj)

                    ' Append to the bottom of the file details on the extracted file and its new location. 
                    Call rtItem.AddNewline(1)
                    Call rtitem.AppendText("---------------------------------------" + Chr(13) + Chr(10)) 

                    text = """" + sDir + "\"+ Obj.Name + """" + Chr(13) + Chr(10) + Chr(9) + "Extracted by: " + s.UserName + " on " + Str$(Today()) +  ".  "
                    Call rtitem.AppendText(text )               
                    Call rtItem.AddNewline(1)               

                    ' Remove the object from the file and save the document.
                    Call Obj.Remove
                    Call doc.Save( False, True )  'creates conflict doc if conflict exists
                    attachmentMoved = True
                Else
                    Forall verb In Obj.Verbs
                        'Msgbox verb, 64, "VERB"
                    End Forall
                End If 
            End Forall 

            ' If the document had an attachment moved, update the subject line 
            If attachmentMoved = True Then
                Dim item As Notesitem
                Set item = doc.GetFirstItem("Subject")
                subjectLine = item.Text + "- ATTACHMENT MOVED"
                Set item = doc.ReplaceItemValue("Subject", subjectLine)
                Call doc.Save( False, True )  'creates conflict doc if conflict exists
            End If
        Next

        Set doc = dc.GetNextDocument(doc)
    Wend

    Msgbox "Export Complete.", 64, "Finished"

End Sub

Sub ExportAttachment(o As Variant)

    Dim sAttachmentName As String
    Dim sNum As String
    Dim sTemp As String

    ' Create the destination filename
    sAttachmentName = sDir & "\" & o.Source

    ' Loop through until the filename is unique
    While Not (Dir$(sAttachmentName, 0) = "")

        ' Get the last three characters of the filename - "_XX"
        sNum = Right(Strleftback(sAttachmentName, "."), 3)

        ' Ensure the first of the three characters is an underscore and the next two are numeric.  If they are, add one to the existing number and insert it back in.
        If Left(sNum,1) = "_" And Isnumeric(Right(sNum, 2)) Then
            sTemp = Strleftback(sAttachmentName, ".")
            sTemp = Left(sTemp, Len(sTemp) - 2)
            sAttachmentName = sTemp & Format$(Cint(Right(sNum,2)) + 1, "##00") & "." & Strrightback(sAttachmentName, ".")
        Else
            sAttachmentName = Strleftback(sAttachmentName, ".") & "_01." & Strrightback(sAttachmentName, ".")
        End If
    Wend

    ' Save the file
    Call o.ExtractFile( sAttachmentName ) 

End Sub 

I have an agent someone shared years ago which takes attached files, saves them to my hard drive, and removes them from the email. I use it to keep my emails for a while but stay under my corporate mailbox quota. I get a LOT of attachments.

I'm now finding that a lot of the remaining large emails have embedded images rather than "attached files". Can anyone share a script that would actually be able to do the same (save to hard drive, remove from email) with an embedded image?

FWIW, here is the agent I use for detaching attachments. Props to original author, don't know who that was.

Dim sDir As String
Dim s As NotesSession
Dim w As NotesUIWorkspace
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument

Sub Initialize

    Set s = New NotesSession
    Set w = New NotesUIWorkspace 
    Set db = s.CurrentDatabase
    Set dc = db.UnprocessedDocuments
    Set doc = dc.GetFirstDocument
    Dim rtItem As NotesRichTextItem
    Dim RTNames List As String
    Dim DOCNames List As String
    Dim itemCount As Integer
    Dim sDefaultFolder As String

    Dim vtDir As Variant
    Dim iCount As Integer
    Dim j As Integer
    Dim lngExportedCount As Long
    Dim attachmentObject As Variant
    Dim text As String

    Dim subjectLine As String
    Dim attachmentMoved As Boolean

    ' Prompt the user to ensure they wish to continue extracting the attachments
    Dim x As Integer
    x = Msgbox("V4 This action will extract all attachments from the " & Cstr (dc.Count) &  " document(s) you have selected, and place them into the folder of your choice." & _
    Chr(10) & Chr(10) & "Would you like to continue?", 32 + 4, "Export Attachments")
    If x <> 6 Then Exit Sub 

    ' Set the folder where the attachments will be exported
    sDefaultFolder = s.GetEnvironmentString("LPP_ExportAttachments_DefaultFolder")
    If sDefaultFolder = "" Then sDefaultFolder = "F:"  
    vtDir = w.SaveFileDialog( False, "Export attachments to which folder?", "All files|*.*", sDefaultFolder, "Choose Folder and Click Save")
    If Isempty(vtDir) Then Exit Sub
    sDir = Strleftback(vtDir(0), "\")
    Call s.SetEnvironmentVar("LPP_ExportAttachments_DefaultFolder", sDir) 

    ' Loop through all the selected documents
    While Not (doc Is Nothing)

        iCount = 0
        itemCount = 0
        lngExportedCount = 0
        Erase RTNames
        Erase DocNames

        ' Find all of the RichText fields in the current document.  If any have an embedded object, add the item to the RTNames array.
        Forall i In doc.Items
            If i.Type = RICHTEXT Then
                If Not Isempty(i.EmbeddedObjects) Then
                    'Msgbox i.Name,64,"Has embedded objects"                    
                End If
                Set rtItem = doc.GetfirstItem(i.Name)
                'Set rtItem = i
                If Not Isempty(rtItem.EmbeddedObjects) Then
                    RTNames(itemCount) = Cstr(i.Name)
                    itemCount = itemCount +1
                End If
            End If

        End Forall  

        ' Loop through the RTNames array and see if any of the embedded objects are attachments
        attachmentMoved = False
        For j = 0 To itemCount-1 
            Set rtItem = Nothing
            Set rtItem = doc.GetfirstItem(RTNames(j))
            Forall Obj In rtItem.EmbeddedObjects
                If ( Obj.Type = EMBED_ATTACHMENT ) Then
                    ' The embedded object is an attachment.  Export it to the chosen directory
                    Call ExportAttachment(Obj)

                    ' Append to the bottom of the file details on the extracted file and its new location. 
                    Call rtItem.AddNewline(1)
                    Call rtitem.AppendText("---------------------------------------" + Chr(13) + Chr(10)) 

                    text = """" + sDir + "\"+ Obj.Name + """" + Chr(13) + Chr(10) + Chr(9) + "Extracted by: " + s.UserName + " on " + Str$(Today()) +  ".  "
                    Call rtitem.AppendText(text )               
                    Call rtItem.AddNewline(1)               

                    ' Remove the object from the file and save the document.
                    Call Obj.Remove
                    Call doc.Save( False, True )  'creates conflict doc if conflict exists
                    attachmentMoved = True
                Else
                    Forall verb In Obj.Verbs
                        'Msgbox verb, 64, "VERB"
                    End Forall
                End If 
            End Forall 

            ' If the document had an attachment moved, update the subject line 
            If attachmentMoved = True Then
                Dim item As Notesitem
                Set item = doc.GetFirstItem("Subject")
                subjectLine = item.Text + "- ATTACHMENT MOVED"
                Set item = doc.ReplaceItemValue("Subject", subjectLine)
                Call doc.Save( False, True )  'creates conflict doc if conflict exists
            End If
        Next

        Set doc = dc.GetNextDocument(doc)
    Wend

    Msgbox "Export Complete.", 64, "Finished"

End Sub

Sub ExportAttachment(o As Variant)

    Dim sAttachmentName As String
    Dim sNum As String
    Dim sTemp As String

    ' Create the destination filename
    sAttachmentName = sDir & "\" & o.Source

    ' Loop through until the filename is unique
    While Not (Dir$(sAttachmentName, 0) = "")

        ' Get the last three characters of the filename - "_XX"
        sNum = Right(Strleftback(sAttachmentName, "."), 3)

        ' Ensure the first of the three characters is an underscore and the next two are numeric.  If they are, add one to the existing number and insert it back in.
        If Left(sNum,1) = "_" And Isnumeric(Right(sNum, 2)) Then
            sTemp = Strleftback(sAttachmentName, ".")
            sTemp = Left(sTemp, Len(sTemp) - 2)
            sAttachmentName = sTemp & Format$(Cint(Right(sNum,2)) + 1, "##00") & "." & Strrightback(sAttachmentName, ".")
        Else
            sAttachmentName = Strleftback(sAttachmentName, ".") & "_01." & Strrightback(sAttachmentName, ".")
        End If
    Wend

    ' Save the file
    Call o.ExtractFile( sAttachmentName ) 

End Sub 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云柯 2024-10-24 16:20:29

这对于脚本来说是非常有问题的,因为它目前的情况是 MIME 编码的图像不会使用 EmbeddedObjects 属性显示为任何类型的附件。

如果图像作为 MIME 消息的一部分内联存储,Notes 客户端会将它们转换为附件以供查看,但以编程方式只能作为 MIME 消息的一部分进行访问。应该可以获取带有编码图像的多部分 MIME 消息的正确部分(使用 MIMEEntity 类),将其流式传输到光盘并重新构建原始文件,然后删除表示它的 MIMEEntity(并获取上升空间)。

的更多信息

有关IBM 支持站点

NotesMIMEEntity 类文档

This is very problematic to do with the script as it currently stands as MIME encoded images won't show up as any type of attachment using the EmbeddedObjects Property.

If the images are stored inline as part of a MIME message, the Notes client will turn them into an attachment for viewing, but programmatically the can only be accessed as parts of the MIME message. It should be achievable to grab the correct part of a multi-part MIME message with the image encoded (using the MIMEEntity classes), stream this out to disc and reconstitute the original file(s) then remove the MIMEEntity that represented it (and took up the space).

More info on the

IBM Support Site

NotesMIMEEntity Class Documentation

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文