I am trying to write a LotusScript agent (Target: All selected documents) which will scan all of the selected docs in a view, scan the SendTo and CopyTo fields in these docs and remove the e-mail addresses of any NON-local address recipients (eg. recipients other than ‘Joe Bloggs/Local Notes Domain’ or ‘jbloggs@localdomain.com’).
I am able to scan the indicated docs and fields and identify the external addresses using the following code:
Dim sess As New NotesSession
Dim db As NotesDatabase
Dim coll As NotesDocumentCollection
Dim doc1 As NotesDocument
Set db = sess.CurrentDatabase
Set coll = db.UnprocessedDocuments
Set doc1 = coll.GetFirstDocument()
While Not (doc1 Is Nothing)
Forall temp1 In doc1.GetItemValue("SendTo")
If Instr(1,temp1,"Local Notes Domain") = 0 And Instr(1,temp1,"localdomain.com") = 0 Then
' The current e-mail address is not a local recipient and should be removed
' Do that here
End If
End Forall
Wend
However, I’m not sure how to modify or remove individual list members of the SendTo field (for instance, set them to “”) or wholly replace the value in the SendTo field.
I was thinking of something like:
’ inside Forall loop (addr and ret are strings)
addr = doc1.GetItemValue(“SendTo”)
ret = Replace(addr,temp1,“”)
Call doc1.ReplaceItemValue(“SendTo”,ret)
Call doc1.Save(True,False)
OR
’ inside Forall loop (newSendTo is a string)
if (address should NOT be removed) Then
newSendTo = newSendTo + temp1 + ","
End If
’ after/outside Forall loop
Call doc1.ReplaceItemValue(“SendTo”,newSendTo)
Call doc1.Save(True,False)
Nothing seems to work and I often end up in an infinite (Forall?) loop. I’ve tried using ubound to limit the number of times the loop runs (eg. c% = Ubound(doc1.SendTo), For i = 1 to c, If doc1.SendTo(i) Then, Next) - this doesn’t work either.
Any ideas how I can accomplish this task?
Paul.