Sizereport for all users in all IMAP folders

This section contains scripts that hMailServer has contributed with. hMailServer 5 is needed to use these.
Post Reply
large
Normal user
Normal user
Posts: 33
Joined: 2004-12-31 12:47
Contact:

Sizereport for all users in all IMAP folders

Post by large » 2020-06-18 00:48

Script generates a report like this
-------------------------------------------------
Account: name@domain.com
Total used space: 52,457 MB

Folders:
INBOX: 1632 (49,17 MB)
-Sent: 3 (0,00 MB)
--ASubDir: 0 (0,00 MB)
-Trash: 2 (0,01 MB)
-Drafts: 0 (0,00 MB)
Trash: 0 (0,00 MB)
Sent: 1 (0,00 MB)
Spam: 81 (2,29 MB)
Archive: 0 (0,00 MB)
Modify the script as you like, I have not added any filters to get the total overview.

Code: Select all

'------------------------------------------------
' Size report of all users for each directory
' Created by: Lars Werner
' Date: 18.06.2020
' Warranty: Out of the door...
'------------------------------------------------

Option Explicit

'   #### CONFIG START
    Const HMSADMINUSER = "Administrator"	' Admin username
    Const HMSADMINPWD = "yourpassword"	' Admin password
    Const HMSSERVER = "localhost"			' hMailServer Server (host / DCOM)
'   #### CONFIG END

    Dim oApp, oDomain, oAccount, oFolders
    Dim x, y
	
'    On Error Resume Next

    Set oApp = CreateObject("hMailServer.Application", HMSSERVER)
    Call oApp.Authenticate(HMSADMINUSER, HMSADMINPWD)

	'-------------
	'Loop through all domains, accounts and then recursive count all the mails
    For x = 0 To oApp.Domains.Count - 1
        Set oDomain = oApp.Domains.Item(x)
        'If oDomain.Active Then
            For y = 0 To oDomain.Accounts.Count - 1
                Set oAccount = oDomain.Accounts.Item(y)
				
				Wscript.Echo "--------------------------------------------------"
				wscript.echo "Account: " & oAccount.Address
				wscript.echo "Total used space: " & oAccount.Size & " MB"
				wscript.echo ""
				WScript.echo "Folders:"
				
				Set oFolders = oAccount.IMAPFolders
				
				'Start recursive listing for this user
				call RecursiveFolder(oFolders, 0)

				'Space up for the next user
				wscript.echo ""
            Next
        'End If
    Next

	'-------------
	'Recursize function that will be called again and again until no more subfolders exists
	Function RecursiveFolder(oFld, nLevel)
		Dim nIntCount, oFolder, oMessages, oMessage, nSize, nCount, z
		For nIntCount = 0 to oFld.Count - 1
			nSize = 0
			set oFolder = oFld.Item(nIntCount)
			set oMessages = oFolder.Messages
			nCount = oMessages.Count 'Number of messages
			
			'Loop through each message and sum up the sizes
			for z = 0 to oMessages.Count - 1
				set oMessage = oMessages.Item(z)
				nSize = nSize + oMessage.Size
			Next
			
			'Print out the folder, message count and size
			WScript.echo replace(space(nLevel), " ", "-") & oFolder.Name & ": " & nCount & " (" & FormatNumber(nSize / 1024, 2) & " MB)" '& " ---> " & nIntCount & "/" & oFld.Count - 1			
			
			'If there are subfolders, do the next one
			if Not IsNull(oFolder.SubFolders) then
				if oFolder.SubFolders.Count > 0 then
					call RecursiveFolder(oFolder.SubFolders, nLevel + 1)
				end if
			end if
		Next
			
	End Function
Lars Werner
http://lars.werner.no
Check out my tools:
http://lars.werner.no/unpacker/ - 100% automated extraction tool
http://lars.werner.no/sizeme/ - Maximize the output on a given media (like CD/DVD ect)

Post Reply