IBM Support

How to rebuild a Notes mail inbox

Technote (FAQ)


Question

Your mail inbox is corrupt in Lotus Notes®. Because the inbox is a folder, it does not use selection formulas to provide a collection of documents. Instead, 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 are deposited in it from that point on.

How can you rebuild your original inbox?


Answer

Below are examples that can be used to repopulate your inbox with older mail messages that are not currently filed in folders. Example 1 does not require the existence of a backup file in order to repopulate the Inbox. Example 2 relies on the existence of an existing backup mail file which is used to determine which documents will be placed in the Inbox.

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

*VERY IMPORTANT*: Make a backup of your mail file before proceeding.

NOTE: The sample scripts below are provided to illustrate one way to approach this issue. They are to be used as is and at your own risk. In order for these examples to perform as intended, the scripts must be laid out exactly as indicated below. Product Support cannot customize this script for specific environments or applications.

Example 1: Does not require a pre-existing backup
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, including Profile documents and Organizer Setup documents. When finished, select these documents and choose Actions --> Remove From Folder.

* The agent should be designed to act on a Target of "None".

* 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 the script 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 Long              ' 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

Example 2: Requires a pre-existing backup mail file which populates the inbox
This agent cycles through the documents found in the backup mail files's inbox, then locates the same documents in the current mail file and moves them into the inbox. If a document from the backup mail file is not found in the current mail file, then the agent skips to the next document.

* The agent should be designed to act on a Target of "None".

* The current mail file should have an existing Inbox folder which was created by refreshing or replacing the mail file's design.

* You must edit the code below to specify:
    -- the backup mail file in the call to the GetDatabase method which sets the variable, "backup".

    -- the current mail file in the call to the GetDatabase method which sets the variable, "db".

    (Declarations)
    %INCLUDE "lsxbeerr.lss"

    Sub Initialize
      On Error lsERR_NOTES_BAD_UNID Goto processError
      Dim s As New NotesSession
      Dim db As NotesDatabase
      Dim backup As NotesDatabase
      Dim doc As NotesDocument
      Dim bdoc As notesdocument
      Dim view As NotesView
      Set db = s.GetDatabase("Server/Org","mail.nsf")
      Set view=db.GetView("($Inbox)")
      If Not view Is Nothing Then
        Set backup = s.GetDatabase("Server/Org","backup.nsf")
        Set view = backup.GetView("($Inbox)")
        Set bdoc= view.GetFirstDocument
        While Not(bdoc Is Nothing)
          Set doc = db.GetDocumentByUNID(bdoc.UniversalID)
          Call doc.PutInFolder( "($Inbox)" )
      getNextDocument:
          Set bdoc = view.GetNextDocument(bdoc)
        Wend
    Exit Sub
    processError:
          Resume getNextDocument
        Else
          Messagebox "The mail file must have a Inbox folder in order to proceed. Refresh the design of the mail file and then rerun the agent"
        End If
    End Sub
NOTE: This agent can also be used to restore documents from a backup database to any folder that may have been deleted in a database. You would just have to modify the code to change the name of the view referenced from ($Inbox) to whatever the actual view name is.

Example 3: Running the convert task (successful in one particular case)
If you run the convert task (convert -u mail\username.nsf inotes6 inotes6.ntf) on a mail file that has no $Inbox, convert will replace the design and then rebuild the Inbox:
    Sample output:
    datetime Mail Convert: Finished replacing design template in 'mail/username.nsf'
    datetime Mail Convert: Started converting categories to folders in 'mail/username.nsf'
    datetime Mail Convert: Building a categorized view
    datetime Mail Convert: Checking for the maximum number of categories
    datetime Mail Convert:
    Opening & repopulating existing folder '$Inbox'
    datetime Mail Convert: Finished converting categories to folders in 'mail/username.nsf'

If no new mail is in the inbox, it is possible that the inbox is continuously caught in a corrupt state. Back up the mail file, delete the Inbox folder, and replace the design. This will add a new Inbox folder to the mail file (which will be empty at this point).

The convert task repopulates the inbox by copying into it all the e-mails received in the last three months. To prevent the convert task to repopulate the inbox and to to prevent it from converting the categories to folders you can use the -d option.

Related information

A simplified Chinese translation is available

Historical Number

152633

Document information

More support for: IBM Notes
Mail

Software version: 6.0, 6.5, 7.0, 8.0, 8.5

Operating system(s): Linux, Windows

Reference #: 1104973

Modified date: 29 March 2004


Translate this page: