AGENT ACCOUNTRESTORE: _____________________________________ Option Public Option Declare Sub Initialize ' agent's purpose is to restore after lock-out of the current user from mail when gone for extended period ' runs via selected document(s). selected documents are person/contact documents using standard "people" fields Dim s As New NotesSession Dim nDb As NotesDatabase ' domino directory Dim nCol As NotesDocumentCollection ' selected docs to process Dim nDoc As NotesDocument ' person doc On Error Goto ErrorHandler Print "Starting . . ." Set nCol = nDb.UnprocessedDocuments If (nCol.Count = 0) Then ' quit Print "No documents selected. Done." Exit Sub End If Set nDoc = nCol.GetFirstDocument() While Not (nDoc Is Nothing) ' process person ... ' change mailfile acl Call RestoreMailAccess(s, nDb, nDoc) ' loop Call s.UpdateProcessedDoc( nDoc ) Set nDoc = nCol.GetNextDocument(nDoc) Wend ' done Print "Done." Exit Sub ErrorHandler: Print "(Initialize) Unexpected Error: " & Cstr(Err) & " " & Error$ & ", on line: " & Cstr(Erl) Exit Sub End Sub Function RestoreMailAccess(s As NotesSession, nDb As NotesDatabase, nDoc As NotesDocument) As Integer ' using passed person doc (nDoc) gets mail file and gives editor (3) access for person Dim mailserver As String Dim mailfilepath As String Dim mDb As NotesDatabase ' mailfile database for mailserver and mailfilepath Dim userfullname As String ' user's FullName(0) first value, contains the canonical name of user Dim userNm As NotesName ' user's name as name object Dim mACL As NotesACL ' mailfile acl Dim mACLE As NotesACLEntry On Error Goto FErrorHandler If (nDoc Is Nothing) Then ' quit RestoreMailAccess = 0 Exit Function End If ' get the user and mailfile paths userfullname = nDoc.FullName(0) ' first value contains whole name mailserver = nDoc.MailServer(0) ' already in canonical format mailfilepath = nDoc.MailFile(0) If (userfullname = "") Then ' not a person? Print "(RestoreMailAccess) Fullname field is empty. Cannot continue without the person's name! Cancelled lockout restore." RestoreMailAccess = 0 Exit Function End If If (mailserver = "") Then ' give up Print "(RestoreMailAccess) MailServer field is empty. Cannot continue without the person's server! Cancelled lockout restore." RestoreMailAccess = 0 Exit Function End If If (mailfilepath = "") Then ' give up Print "(RestoreMailAccess) MailFile field is empty. Cannot continue without the person's mailfile path/filename! Cancelled lockout restore." RestoreMailAccess = 0 Exit Function End If ' create name object Set userNm = s.CreateName(userfullname) If (userNm Is Nothing) Then ' bad text passed, give up Print "(RestoreMailAccess) Could not create name object from Fullname value: " & userfullname & ". Cannot continue. Cancelled lockout restore." RestoreMailAccess = 0 Exit Function End If ' get the mail file Set mDb = s.GetDatabase(mailserver, mailfilepath, False) If (mDb Is Nothing) Then ' no mailfile Print "(RestoreMailAccess) Could not get mail application on server:: " & mailserver & ", path: " & mailfilepath & ". Cannot continue. Cancelled lockout restore." RestoreMailAccess = 0 Exit Function End If ' check if open If Not (mDb.IsOpen) Then ' try to open, now it should already be open, but current user may not have access Call mDb.Open(mailserver, mailfilepath) If Not (mDb.IsOpen) Then ' give up Print "(RestoreMailAccess) Could not open mail application on server:: " & mailserver & ", path: " & mailfilepath & ". Cannot continue - Use Full Access mode. Cancelled lockout restore." RestoreMailAccess = 0 Exit Function End If End If ' get acl Set mACL = mDb.ACL Set mACLE = mACL.GetFirstEntry() While Not (mACLE Is Nothing) ' look for user If (Strcompare(mACLE.Name, userNm.Canonical, 5)=0) Then ' have match, set acl level to 3 mACLE.Level = 3 Call mACL.Save() ' return success RestoreMailAccess = 1 Exit Function End If ' loop Set mACLE = mACL.GetNextEntry(mACLE) Wend ' if here, user not found, add user entry if not found (would be unusual) Set mACLE = mACL.CreateACLEntry(userNm.Canonical, 3) ' save acl change Call mACL.Save() ' return success RestoreMailAccess = 1 FExit: Exit Function FErrorHandler: Print "(Initialize) Unexpected Error: " & Cstr(Err) & " " & Error$ & ", on line: " & Cstr(Erl) RestoreMailAccess = 0 Resume FExit End Function