
With over 400.000 mails on drive and database it is mature to be cleaned.
What I wanted was:
1. Clean everything by given year, eg 2018 and older are copied & wiped
2. Index in a directory hierarchy so it is readable for endusers (using for example http://emlreader.com )
3. Create a logfile so you know what happened during export
Directory structure example for export for mails 2018 and older
All exported files have following structure and are placed under correct directory2018
|----- Domain1.com
|----------user@domain1.com
|---------------Inbox
|--------------------Any other subdirectory
|----- Domain2.com
|----------user@domain2.com
|---------------Inbox
Here is an report example2011-03-08 11.46.55 - 713260 - The subject of the email.eml
<date&time> - <hmailID> - <Subject>
Each directory are shown with <mailboxname>: <mail exported>/<total mails> (<size exported>)2020-06-19 21.53.14 Backupscript started 19.06.2020 21:53:14
2020-06-19 21.53.14 Selected year: 2018 (and older)
2020-06-19 21.53.14 ==========================================
2020-06-19 21.53.14
2020-06-19 21.53.14 --------------------------------------------------
2020-06-19 21.53.14 Account: user@domain1.com
2020-06-19 21.53.14 Total used space: 378,574 MB
2020-06-19 21.53.14
2020-06-19 21.53.14 Folders:
2020-06-19 21.53.16 INBOX: 33/108 (38,78 MB)
2020-06-19 21.53.17 Truncated filename from: D:\MailBackup\2018\domain1.com\user@domain1.com\INBOX\Sent\2011-03-08 11.46.55 - 713260 - This is a veeeeeery long subject above 255 chars so Windows complain.eml
2020-06-19 21.53.17 Truncated filename to: D:\MailBackup\2018\domain1.com\user@domain1.com\INBOX\Sent\2011-03-08 11.46.55 - 713260 - This is a veeeeeery long subject.eml
2020-06-19 21.53.21
2020-06-19 21.53.21 -Sent: 104/149 (26,06 MB)
So "Sent: 104/149 (26,06 MB)" exported 104 of the 149 mails from "Sent" with a total size of 26,06MB. Simple right?
Edit the script for your destination, and your host, admin / password to hMailserver
How to run script and parameters to avoid delete' #### CONFIG START
Const HMSADMINUSER = "Administrator" ' Admin username
Const HMSADMINPWD = "youpassword" ' Admin password
Const HMSSERVER = "localhost" ' hMailServer Server (host / DCOM)
Const DESTINATION = "D:\MailBackup\" ' Destination, remember to end with trail (\)
' #### CONFIG END
While running each . represent a mail that are newer than year selected, x is mail that is older.cscript.exe hmailserver-backup.vbs 2018 NODELETE
(Copies everything from 2018 and older without cleaning the hMailserver database)
cscript.exe hmailserver-backup.vbs 2018
(Copies everything from 2018 and older, then deletes from database / harddrive after verification of file consistency)
Tips to remove all empty directories afterwards, run this command
Remember that you have to change directory in cmd to your backup destination. in my case D:\MailBackup\
Download filefor /f "delims=" %i in ('dir /s /b /ad ^| sort /r') do rd "%i" 2>NUL