Rebuilding a Notes Mail Inbox

Your Inbox in your mail file has become corrupt for whatever reason. Because the Inbox is a folder, it does not use selection formulas to give a collection of documents. It is built by the router depositing messages there. Once the folder is destroyed or replaced, the collection is lost with it. After replacing it with a new one, only new documents will be deposited in it from that point on.

Below is a script that can be used to repopulate your Inbox with the older mail messages that have not been currently filed in folders. The script can be placed in a button and mailed to the users who need it.


NOTE: It is very important to make a backup of the mail file before using it.

This script agent moves ANY document that does not exist in a folder to the Inbox. This means that some documents that only exist in the All Documents view will also be moved. This includes documents such as Profile documents and Organizer Setup documents. When finished, the user should select these documents and choose Actions, Remove From Folder from the menu.

NOTE: Deleting a document from any view or folder deletes it entirely from the database.

'************************************************************
' This script builds an array of documents that are included in a folder.
' It then compares each document in the All Documents view to each document
' in the array.  If it finds one, it breaks out
' and continues onto the next document.  If it reaches the end of the array,
' then it hasn't found a match and the document is moved to the Inbox folder.
'************************************************************

Sub Initialize
 Dim s As New notessession
 Dim db As notesdatabase
 Dim fDoc As NotesDocument   ' Document in folder
 Dim ad As notesview         ' All Documents view
 Dim aDoc As notesdocument   ' document in All Docs view
 Dim fUNID() As String       ' array of UNID's of docs in folders
 Dim i As Integer            ' UNID array index
 Dim deldate As notesitem
 Dim Chair1 As notesitem

 i =0
 Set db = s.CurrentDatabase

 Redim fUNID(0)

 ' Build UNID array by looping through folders, then their documents
 Forall view In db.views
  If view.IsFolder And Not view.Name=("($All)") Then
   Set fDoc = view.GetFirstDocument
   While Not fDoc Is Nothing
    Redim Preserve fUNID(i)
    fUNID(i) = fDoc.UniversalID
    i=i+1
    Set fDoc = view.GetNextDocument(fDoc)
   Wend
  End If
 End Forall

 ' Loop through docs in the All Documents view and compare UNIDs to each doc in the array
 Set ad = db.GetView("($All)")
 Set aDoc = ad.GetFirstDocument
 While Not aDoc Is Nothing
  i = 0
  Do While i < = Ubound(fUNID)
   If fUNID(i) = aDoc.UniversalID Then
    Exit Do
   End If
   i = i + 1
  Loop
  Set deldate = adoc.getfirstitem("delivereddate")
  Set Chair1 = adoc.getfirstitem("CHAIR")
  If i > Ubound(fUNID) And Not deldate Is Nothing And Chair1 Is Nothing Then
   Call adoc.PutInFolder( "($Inbox)")

  End If
  Set aDoc = ad.GetNextDocument(adoc)
 Wend
End Sub

Lotus Software KnowledgeBase Document# 152633

3 thoughts on “Rebuilding a Notes Mail Inbox

  1. Hi,

    I have tested this Script and I found an error in the last part (line 35 and 38). The last part must be look like this:

     ' Loop through docs in the All Documents view and compare UNIDs to each doc in the array
       Set ad = db.GetView("($All)")
       Set aDoc = ad.GetFirstDocument
       While Not aDoc Is Nothing
                 i = 0
          Do While i  Ubound(fUNID) And Not deldate Is Nothing And Chair1 Is Nothing Then
                 Call adoc.PutInFolder( "($Inbox)")
          End If
                 Set aDoc = ad.GetNextDocument(adoc)
          Wend
    End Sub
    

    Enjoy

  2. Wenn das Array fUNID die 65kB-Marke sprengt, tritt ein nicht abgefangener Fehler auf. Das passiert, wenn mehr als ca. 1800 Mails in Ordnern sind.

    Vielleicht kann jemand das Script überarbeiten mit der Listenumwandlung.

  3. Hallo,

    vielen Dank für den Code.

    Habe Ihn ein wenig überarbeitet (Liste statt Array und div. Kleinigkeiten)

    Daniel

    	On Error Goto errHandler
    
    	Dim s As New notessession
    	Dim db As notesdatabase
    	Dim fDoc As NotesDocument   ' Document in folder
    	Dim ad As notesview         ' All Documents view
    	Dim aDoc As notesdocument   ' document in All Docs view
    	Dim fUNID List As Boolean       ' List of UNID's of docs in folders
    	Dim deldate As notesitem
    	Dim Chair1 As notesitem
    	Dim CounterMoved As Long
    	Dim CounterDocsInFolder As Long
    	Dim CounterDocsInAllDocsView As Long
    	Dim msg As String
    
    	Set db = s.CurrentDatabase
    
     ' Build List by looping through folders, then their documents
    	CounterDocsInFolder=0
    	Print "Start analysing ..."
    	Forall view In db.views
    		If view.IsFolder And Not view.Name=("($All)") Then
    			Set fDoc = view.GetFirstDocument
    			While Not fDoc Is Nothing
    				fUNID(fDoc.UniversalID) = True
    				CounterDocsInFolder = CounterDocsInFolder +1
    				Set fDoc = view.GetNextDocument(fDoc)
    			Wend
    		End If
    	End Forall
    
     ' Loop through docs in the All Documents view and compare UNIDs to each doc in the List
    	Set ad = db.GetView("($All)")
    	Set aDoc = ad.GetFirstDocument
    	CounterMoved = 0
    	CounterDocsInAllDocsView = 0
    	While Not aDoc Is Nothing
    		CounterDocsInAllDocsView = CounterDocsInAllDocsView+1
    		If fUNID(aDoc.UniversalID) Then Goto skipDoc ' If current Doc is in a folder skip Doc, if not error handler resumes next and doc is moved to inbox
    
    		Set deldate = adoc.getfirstitem("delivereddate")
    		Set Chair1 = adoc.getfirstitem("CHAIR")
    		If Not deldate Is Nothing And Chair1 Is Nothing Then
    			Call adoc.PutInFolder( "($Inbox)")
    			CounterMoved = CounterMoved+1
    		End If
    
    skipDoc:
    		Set aDoc = ad.GetNextDocument(adoc)
    	Wend
    
    	msg =  "Total: "+Cstr(CounterDocsInAllDocsView)+" docs | Already in folders: "+Cstr(CounterDocsInFolder)+" docs | Moved to inbox: "+Cstr(CounterMoved)
    	Print msg
    	Msgbox (msg)
    	Exit Sub
    
    errHandler:
    
    	If Err = 120 Then 'DUID is not in List
    		Resume Next
    	Else
    		Msgbox Cstr(Err)+"  -  "+Error$
    		Exit Sub
    	End If
    

Comments are closed.