Automatically creating IMAP folders for new users

I recently had a request to automatically create one or more IMAP folders for all new users, and subscribe to them automatically.

I was originally hoping to implement it entirely in the content filter, but it was a bit more complex then I’d hoped.

Right now my script assumes that MDaemon is installed at C:\MDaemon\ and user folders are C:\MDaemon\Users\$DOMAIN$\$MAILBOX$\ if this is not correct, you will need to modify the batch file and content filter rules to update the paths, or post back here and I can send an updated version.

Download newuser-imap-folders which contains three files, cfrules.txt, newuser.cmd and newuser.mrk.

  1. Make a directory called C:\MDaemon\Scripts
  2. Copy the “newuser.cmd” and “newuser.mrk” files into this directory.
  3. Open cfrules.dat in notepad, copy the contents into the clipboard.
  4. Open \MDaemon\App\cfrules.dat in notepad, paste the content of my cfrules.txt into the top of cfrules.dat, save cfrules.dat and close it.
  5. Go to MDaemon, open the content filter, you should see a new rule called “Trap Welcome Message” — Enable it.

At this point any newly created user should have three folders, “Test1”, “Test2” and “Test3” created, and they should be automatically subscribed to these folders.

Changing the list of folders requires editing the two newuser files.

In newuser.cmd, there are three lines at the bottom that look like this:

MD C:\MDaemon\Users\%2\%1\Test1.IMAP

You can add as many of these lines as you want, just replace the “Test1” with the name of the folder you want to create.

If you want to use a foldername with spaces, use this instead:

MD “C:\MDaemon\Users\%2\%1\Test 1.IMAP”

You’ll also need to edit newuser.mrk, there are three lines at the bottom that look like this:

Test1=Yes

This file controls the IMAP subscriptions for the user, so if you want the created folders to be automatically subscribed, list the folders here.  No quotes are required for a folder name with spaces here.

Hopefully this all makes sense and you don’t have any troubles, but if you do, please reply back in the comments and I’d be happy to assist.

UPDATE (2008/08/20): ZIP file was not properly linked/attached the first time around, re-uploaded to the server and updated the page.

Download at newuser-imap-folders

Sending Account Pruner log to the administrator

The account pruner logs it’s activities in the accountprune.log file in the \MDaemon\Logs\ directory, including potentially important details like accounts which were deleted due to inactivity.

In addition to MDaemon’s daily stats report, I also like to review the accountprune.log just to ensure that nothing important was deleted.

On my server I created a scheduled task that calls a batch file which says “IF EXIST C:\MDaemon\Logs\accountprune.log COPY c:\MDaemon\accountprune.raw C:\MDaemon\Queues\Rawfiles\accountprune.raw”, where accountprune.raw is a RAW file I build that emails my admin mailbox and uses the attachment feature to attach (and delete) the logfile.

The RAW file is pretty simple, mine looks like this:

TO <[email protected]>
FROM <[email protected]>
SUBJECT <AccountPrune>
X-Flag=ATTACH <D:\MDaemon\Logs\AccountPrune.log, ASCII> -x

The result is that I get to see the report each morning.

Create a mailing list of Outlook Connector users

I once had a request to populate a mailing list with Outlook Connector users.  Below is the script that was born.

The script assumes a hardcoded listname of “[email protected]”, use Notepad to search and replace [email protected] with the correct list name.

Also, you need to manually create the list in MDaemon first, otherwise the script will fail.  Lastly, be aware that you cannot manually add users to the list, the entire membership list is wiped and replaced each time the script runs.  The intention is to run the script automatically on a schedule to keep the list up to date.

@ECHO OFF
CD C:\MDaemon\App
IF NOT EXIST GroupWareUsers.dat goto ERROR
IF NOT EXIST [email protected] goto ERROR
COPY [email protected] [email protected]
FIND “;” < [email protected] > [email protected]
FIND “@” < GroupWareUsers.Dat >> [email protected]
GOTO END
:ERROR
ECHO Could not find needed file, check and make sure GroupWareUsers.dat and [email protected] exist
:END