Domino Code Fragment

Code Name*
Removes file attachments from Notes documents
Date*
10/12/1998
Source (or email address if you prefer)*
Jamie Magee
IP address:.18.224.37.68
Description*
Removes file attachments from Notes documents that are older than X days old.
Type*
LotusScript
Categories*
Diagnostics/Analysis/Debugging, Email/PIM
Implementation:
Modify code
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
Sub Initialize
    Dim S As New NotesSession
    Dim v As NotesView
    Dim doc As NotesDocument
    Dim db As NotesDatabase
    Set db = S.currentDatabase
    Set v = db.GetView("docs with attachments by date")
    If (v Is Nothing) Then
         Messagebox ("could not find required view")
         End
    End If
    Set doc = v.GetFirstDocument()
    Dim totalsize As Long
    Dim count As Long
    Dim rtitem As NotesRichTextItem
    Do While Not(doc Is Nothing)
         If (doc.HasEmbedded & doc.KeepAttachments(0)<>"1" & doc.LastModified + 5 < Today) Then  '...I don't think the + 5 is allowable!
              Set rtitem = doc.GetFirstItem("Body")  '...grab a handle to the Body field so we can log our removal of file attachments
              Forall obj In doc.EmbeddedObjects   '...go thru the array of type NotesEmbeddedObject
                   count = count + 1   '...increase the file attachment counter
                   totalsize = totalsize + obj.filesize    '...increase the total size counter

                    Call rtitem.AppendText("File " & obj.Source & " was removed on " & Str$(Today) )   '...log removal of the file
                   Call rtitem.AddNewLine(1)   '... add a new line                    
                   Call obj.Remove()  '...finally remove the file attachment
              End Forall
         End If
         Call doc.save(True, True) '...commit our changes to the current doc
         Set doc = v.GetNextDocument(doc)  ' get the next document
    Loop    
    used = db.PercentUsed
    If (used < 85) Then          
         warning = "  You should probably compact this database."
    End If
    Messagebox(Str$(count) & " document(s) were removed, totaling " & Str$(totalsize) & " bytes.  " & Str$(used) & "% of this database is now used." & warning)
End Sub