• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 491
  • Last Modified:

Number of Folders in a Mailfile

Is there a method or way to go out to a mailfile and find out the number of folders that the database contains?

The reason we need this information is we are in the process of migrating users to new templates and ran across an issue when a user had too many folders and only the first 255 migrated with the template. Unfortunately we have a few users with inordinate amounts of folders so we need to identify all of those users so we can handle them as special cases. (Yes I myself cannot understand the need for so many, but I am a mere pawn...)

I would like a way to do this in batch so I can launch it from an information gathering database that we have and have it record the results in each database's documents.
0
Blackmoorian
Asked:
Blackmoorian
  • 5
  • 4
4 Solutions
 
SysExpertCommented:
Yes I am pretty sure you can certainly go throgh and count folders. I'll have to dg up code.
What Version of Notes Swerver and Client are you using ?

I hope this helps !


0
 
SysExpertCommented:
eee
http://www.experts-exchange.com/Applications/Email/Lotus_Notes_Domino/Q_21608085.html?query=folder+count&topics=133

For some sample code for a similar issue.

You should be able to put it in a central db to gather the info for all the mail files, after some slight changes.

I hope this helps !
0
 
marilyngCommented:
Well, I looked over those links to be sure I'm not stomping on your post, Mike.  They seem to refer to maximum folders, and I didn't see any code there.  

Now, I do have an agent that you can run.  It's not the most efficient, (10-15 Seconds per mail file) because it cycles through all the views and folders, and counts the folders, and then sends you an email with the results.  Dunno, I've never tried it on more than 200 mail files.  I wouldn't run it on a server, I would run it in an agent in a test database on a local client.


I'm wondering if scanez from ytria.com would do this better for you.  YOu can download a free copy, or rent it for a week :)

At any rate, set this as an agent with level 3 access, and be sure to fill in who gets the email, the administration server, and the folder flag count (the agent will color those lines RED if the have or exceed the count you set)

Sub Initialize
      'Agent to go through the catalog and count the folders for each mail file listed.
      'It will send a full report via email to the person listed in the SendMailTo Const.
      'This may be best run off of a local client since it might span servers, and take awhile
      'ADD YOUR NAME AND SERVER NAME
      Const SENDMAILTO="YOUR NAME/DOMAIN"
      Const ADMINISTRATIONSERVER="YOUR SERVER/DOMAIN"
      'ADD FOLDER COUNT TO FLAG IN THE EMAIL...........................
      Const FLAGFOLDERCOUNT= 200      
      Dim Session As New NotesSession
      Dim tb As String, msg As String
      tb = Chr(9)
      
      On Error Goto Handle_Error
      
      'Instantiate the Log
      Dim curdb As NotesDatabase
      Set curdb = session.currentdatabase
      Dim logdoc As NotesDocument
      Set logdoc = curdb.CreateDocument
      Dim Subject As String
      Subject = {Starting Review of Mail Folder Count on } + Format(Now)
      With logdoc
            .Principal = session.UserName
            .form = "memo"
            .subject = subject
            .SendTo = SENDMAILTO
      End With
      
      Dim rtItem As New NotesRichTextItem(logdoc,"Body")
      Dim redStyle As NotesRichTextStyle
      Dim richStyle As NotesRichTextStyle
      Set redStyle = session.CreateRichTextStyle
      Set richStyle = session.CreateRichTextStyle
      
      With richStyle
            .NotesFont = Font_helv
            .NotesColor = Color_dark_blue
            .Bold = False
            .Fontsize = 9
      End With
      
      With redStyle
            .NotesFont = Font_helv
            .NotesColor = Color_red
            .Bold = True
            .Fontsize = 9
      End With
      
      Dim rtpStyle As NotesRichTextParagraphStyle
      Dim pos As Long
      Dim interval As Long
      Set rtpStyle = session.CreateRichTextParagraphStyle
      pos = RULER_ONE_INCH*3
      Call rtpStyle.SetTab(pos, Tab_left )
      
      Call rtitem.AppendParagraphStyle(rtpstyle)
      Call rtitem.appendstyle(richStyle)
      
      Dim namedb As New NotesDatabase(ADMINISTRATIONSERVER,"names.nsf")
      If Not namedb.IsOpen Then Call namedb.Open("","")
      If Not namedb.IsOpen Then
            msg = {Unable to open the Address Book.}      
            Call rtitem.AddNewline(1)
            Call rtitem.appendtext(msg)
            Goto ExitHere
      End If
      
      Dim view As NotesView
      Set view = namedb.GetView("Mail Users")
      If view Is Nothing Then
            Call rtitem.AddNewline(1)
            Call rtitem.appendtext(msg)
            Goto ExitHere
      End If
      
      Dim persondoc As NotesDocument
      Dim mailserver As String, mailfile As String
      Dim maildb As New NotesDatabase("","")
      Dim count As Integer, failed As Integer, foldercount As Integer, person As NotesName
      Dim processcount As Integer
      Dim na As Integer
      Dim theViews As Variant
      count = 0
      On Error Goto Handle_Mail_Error
      Set persondoc = view.getfirstdocument
      While Not persondoc Is Nothing
            With persondoc
                  processcount = processcount +1
                  Select Case .getItemValue("MailSystem")(0)
                  Case "1"
                        'Only collect Notes Users
                        mailserver = .getItemValue("MailServer")(0)
                        mailfile=.getItemValue("mailfile")(0)
                        Set person = New NotesName(.getItemValue("fullname")(0))
                        Print "Processing " + Cstr(processcount) + ": " +  person.common
                        'Check values of mail server and mail file
                        If mailserver ="" Then
                              msg={Mail Server not listed for: }  
                              Call rtitem.AddNewline(1)                              
                              Call rtitem.appendtext(msg)
                              Call rtitem.AddTab(1)
                              Call rtitem.appendtext(person.Common)
                              failed = failed +1
                              Goto NextDoc
                        End If
                        
                        If mailfile = "" Then
                              msg=tb + {Mail File not listed for: }
                              Call rtitem.AddNewline(1)
                              Call rtitem.appendtext(msg)
                              Call rtitem.AddTab(1)
                              Call rtitem.appendtext(person.Common)
                              failed = failed +1
                              Goto NextDoc
                        End If
                        
                        'Open the mail file
                        Set maildb = session.getDatabase(mailserver,mailfile,False)
                        If Not maildb Is Nothing Then
                              'Trap open mail errors
                              If Not maildb.IsOpen Then Call maildb.Open("","")
                              If Not maildb.IsOpen Then
                                    msg={Could not Open Mail Database for: }
                                    Call rtitem.AddNewline(1)
                                    Call rtitem.appendtext(msg)
                                    Call rtitem.AddTab(1)
                                    Call rtitem.appendtext(person.common + { (} + mailfile + {)})
                                    failed = failed +1
                                    Goto NextDoc
                              End If      
                              
                              'Now the maildb is open
                              theViews = maildb.Views
                              Forall v In theViews
                                    If v.isFolder Then
                                          foldercount = foldercount +1
                                    End If
                              End Forall
                              
                              'Write the results
                              If foldercount=>FLAGFOLDERCOUNT Then
                                    Call rtItem.AppendStyle(redStyle)
                              Else
                                    Call rtItem.AppendStyle(richStyle)
                              End If      
                              Call rtitem.AddNewline(1)
                              Call rtitem.appendtext(person.common + {-} +mailfile)
                              Call rtitem.AddTab(1)
                              Call rtitem.AppendText({Folders: } + Cstr(foldercount) )                              
                              If foldercount=>FLAGFOLDERCOUNT Then
                                    Call rtItem.AppendStyle(richStyle)
                              End If
                              count = count +1      
                        Else
                              msg={Mail Database does not exist for: }  
                              Call rtitem.AddNewline(1)
                              Call rtitem.appendtext(msg)
                              Call rtitem.AddTab(1)
                              Call rtitem.AppendText(person.common)                              
                              failed = failed +1
                              Goto NextDoc
                        End If
                  Case Else
                        na = na +1
                        Goto NextDoc
                  End Select                        
            End With
NextDoc:
            Erase theViews
            foldercount = 0
            mailserver=""
            mailfile=""
            Set person = Nothing
            Set maildb = Nothing            
            Set persondoc = view.GetNextDocument(persondoc)
      Wend
      
      On Error Goto Handle_Error
      
      msg= {Finished processing } + Cstr(processcount) + { mail files} + Chr(13) +_
      {Successful: } + Cstr(count) + Chr(13) + {Failed: } + Cstr(failed)
      Call rtitem.AddNewline(2)
      Call rtitem.appendtext(msg)
      
      
      Msgbox msg,,"Finished"      
      
ExitHere:
      On Error Goto 0
      msg = {Finished Count Folders agent at: } + Format(Now)
      Call rtitem.AddNewline(1)
      Call rtitem.appendtext(msg)
      Call logdoc.Send(False)
      Set logdoc = Nothing
      Exit Sub
      
      'ERROR TRAPS......................................................................................
Handle_Error:
      On Error Goto 0
      msg = {Error processing the count folders agent: } + Error$ + {-} + Str(Err)
      Call logdoc.Send(False)
      Resume ExitHere
      
Handle_Mail_Error:
      'This traps stuff in the loop and resumes with nextDoc
      On Error Goto 0
      msg = {Error processing:} + person.common + "-" + mailfile + ": " + Error$ + {-} + Str(Err)
      Call logdoc.Send(False)
      Resume NextDoc
      
End Sub
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
marilyngCommented:
Whoops, just realized the error trapping is wrong:

Handle_Error:
     On Error Goto 0
     msg = {Error processing the count folders agent: } + Error$ + {-} + Str(Err)
     Call rtitem.AddNewline(1)
     Call rtitem.appendtext(msg)
     Resume ExitHere
     
Handle_Mail_Error:
     'This traps stuff in the loop and resumes with nextDoc
     On Error Goto 0
     msg = {Error processing:} + person.common + "-" + mailfile + ": " + Error$ + {-} + Str(Err)
     Call rtitem.AddNewline(1)
     Call rtitem.appendtext(msg)
     Resume NextDoc

-------------
Sorry, I didn't have any errors when I ran it to test :)
0
 
SysExpertCommented:
The sample code in the link is much simpler, and easier to adapt

On Error Goto ProcessError
     Dim session As New NotesSession
     Dim db As NotesDatabase
     Dim note As NotesDocument
     Dim tmpBody As NotesItem
     Dim viewCount As Integer
     Dim msgString As Variant
     Dim dbFile, dbServ As String
     Dim recipients As String, askforfile As String
     recipients = "<your name here>"

ask:
     askforfile = Inputbox$("What database? Enter in format - dir\database.nsf.", "Enter file name ...")
     If askforfile = "" Then
          Msgbox "You must enter a value, please try again.", 0, "Oooops!"
          Goto ask
     End If

     dbServ = "<your server name here>"
     Set db = session.GetDatabase( dbServ, askforfile)
     If db Is Nothing Then Goto ask
     viewCount = 0
     msgString = ""

     If Not db.IsOpen Then
          Msgbox "Database not found. Please try again."
          Exit Sub
     End If
     
     Forall view In db.views
          viewCount = viewCount + 1
          msgString = msgString & Chr(10) & view.Name
     End Forall
     
     msgString = viewCount & Chr(10) & msgString
     
     Set note = db.CreateDocument
     note.Form = "Memo"
     note.Subject = "my list of views/folders"
     note.Body = msgString
     Call note.Send(False, recipients)
     Msgbox "List of views sent to " & recipients, 0, "Success!"
     Exit Sub

ProcessError:
     Set note = db.CreateDocument
     note.Form = "Memo"
     note.Subject = "error getting list of views/folders"
     msgString = "error no. " & Err() & " at line number " & Erl() & " - " & Error()
     note.Body = msgString
     Call note.Send(False, recipients)
     Msgbox "Sorry, an unexpected error was encountered."
     Exit Sub

===============

I hope this helps !
0
 
marilyngCommented:
The difference, is that sysExpert's code checks only one mail file.  Mine will step through your NAB and do them all. :)
0
 
SysExpertCommented:
marilyng , that's true, but he menioned he already has an information gathering DB, so I would think that he already knows  how to loop through all the Db's, and just needed a bit of code for the views/folders.


0
 
marilyngCommented:
But Marko's code that you posted does ALL the views and folders, not just the folders. :)
You have to type in each database filepath separately, and if you're trying to do a summary for more than 200 files, well, gee, I wouldn't want to do that :)

I don't think we know if he has such a database, and if so, easy enough to change the mail send to "save."  

Then all you have to do is run it once instead of typing in the server and filepath for 200+ databases. :))

I'm not trying to be critical here, just providing the asker with options.

0
 
SysExpertCommented:
As usual , we are just guessing.

 Blackmoorian, any status update on the info we have provided ?

0
 
BlackmoorianAuthor Commented:
As usual they divert my talents to another area so I didn't get a chance to implement the code (such is the life of a contractor) and rumor has it that one of their developers has already come up with this code for the same project. (Gotta love good communication.) Once I get my hands on the code or implement yours I will post the final results here. Thanks for all your input in this.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now