| Sub Initialize |
| '################################################################################### |
| 'Purpose: |
| 'Decrypt emails |
| ' |
| 'Usage: |
| 'Create a Lotus Script agent - "All documents in database" and copy this code to "Initialize". |
| '*IMPORTANT*: Run this agent with the same public key (ID-file) that was used to encrypt the documents. |
| 'Otherwise this will not work! |
| '------------------------------------------------------------------------------------------------------- |
| 'Version Date Programmer |
| '1.00 04/27/2004 Matthias TMC |
| '################################################################################### |
| |
| On Error Goto ErrorHandler |
| Dim session As New Notessession |
| Dim db As Notesdatabase |
| Dim dc As Notesdocumentcollection |
| Dim dcEncrypted As Notesdocumentcollection |
| Dim item As NotesItem |
| Dim doc As notesdocument |
| Dim iCounter As Integer |
| Dim iAllCount As Integer |
| Set db = session.Currentdatabase |
| Set dc = db.allDocuments |
| |
| '----> We need an empty doccollection |
| Set dcEncrypted= db.GetDocumentByUnid(db.Views(0).UniversalID).Responses |
| '< |
| |
| '------> Search for encrypted docs and put them in the 2nd doc collection |
| iCounter = 0 |
| iAllCount = dc.Count |
| Set doc = dc.Getfirstdocument |
| While Not doc Is Nothing |
| ' |
| iCounter = iCounter +1 |
| Print iCounter & "of " iAllCount "docs processed." |
| '<--- |
| If doc.IsEncrypted Then |
| Call dcEncrypted.AddDocument(doc) |
| End If |
| Set doc = dc.Getnextdocument(doc) |
| Wend |
| '< |
| |
| '-----> Message.... |
| If dcEncrypted.Count = 0 Then |
| Msgbox "No documents in this database are encrypted.", 64, db.Title |
| Exit Sub |
| Else |
| If Not Messagebox (dcEncrypted.Count & " documents in this database are encrypted." &Chr(10) &Chr(10)_ |
| & "Do you really want to decrypt these documents? ",1 + 32,db.Title) = 1 Then Exit Sub |
| End If |
| '< |
| |
| '--------> Now we remove the encryption stuff |
| iCounter = 0 |
| iAllCount = dcEncrypted.Count |
| Set doc = dcEncrypted.GetFirstDocument |
| While Not doc Is Nothing |
| |
| 'See progress |
| iCounter = iCounter +1 |
| Print iCounter & "of " iAllCount "docs processed." |
| |
| 'decrypt Body field..... |
| Forall i In doc.Items |
| If i.Name = "Body" Then |
| i.IsEncrypted = False |
| End If |
| End Forall |
| |
| 'decrypt $Files..... |
| Forall i In doc.Items |
| If i.Name = "$FILE" Then |
| i.IsEncrypted = False |
| End If |
| End Forall |
| |
| 'Remove all Encrypt - Items |
| While (doc.HasItem("Encrypt")) |
| Set item = doc.GetFirstItem("Encrypt") |
| Call item.Remove |
| Wend |
| |
| 'Remove all $Seal - Items |
| While (doc.HasItem("$Seal")) |
| Set item = doc.GetFirstItem("$Seal") |
| Call item.Remove |
| Wend |
| |
| 'Now let's save the cleaned document |
| Call doc.Save(False, False) |
| Set doc = dcEncrypted.GetNextDocument(doc) |
| |
| Wend |
| '<----------- |
| |
| Msgbox "The" & dcEncrypted.Count & " documents are decrypted now!", 64, db.Title |
| |
| ExitScript: |
| Exit Sub |
| |
| ErrorHandler: |
| Msgbox "Error: " & Err & " - " & Error$ & Chr(10) & Chr(10)_ |
| & "Line: " & Erl & Chr(10)_ |
| ,48,"An error occured" |
| Resume ExitScript |
| |
| End Sub |