Create a Courier-imap shared Spam folder

My aim is to ask procmail to deliver everyone’s spam emails into “shared.System.Spam” IMAP folder. All my mail-receiving users belong to a unix group called “users“.

  1. I need to create the shared maildir first. I put all my shared folders under “/var/spool/Maildir“, so first I will create a “System” sharable maildir, and then create a “Spam” folder inside it. Run these commands as root.
    # maildirmake -S /var/spool/Maildir/System
    # maildirmake -s write -f Spam /var/spool/Maildir/System
  2. The problem with the default “maildirmake -s write” is that it creates directories with mode 1777. Because of this sticky bit (mode ‘t‘ displayed in directory listing), you cannot remove files that does not belong to you. However, it is necessary for Courier IMAP to move all email files from ‘new/‘ to ‘cur/‘ when a user tries to select that folder. Thus the files that cannot be moved, i.e. files belong to other users, will not be picked up by Courier IMAP. That is the reason you cannot see other users’ newly delivered emails, even though these files do exist in the shared folder.The quick ‘n’ dirty solution would be turning off the sticky bit. But we also want to restrict the access to our user group only. So..
    # chgrp -R users /var/spool/Maildir/System/.Spam
    # chmod 1770 /var/spool/Maildir/System/.Spam/[cnt]??
  3. Finally, you want to link the shared folder to your own maildir. Run this as a regular user.
    $ maildirmake --add System=/var/spool/Maildir/System $HOME/Maildir

    You might need to run the above command for every user which needs to access the sharable maildir. Alternatively, you can set up a file called “/etc/maildirshared” (check the maildirmake man page for the exact location) to have the following configuration:

    System	/var/spool/Maildir/System

    Note that it is a character between “System” and the directory.

  4. Now you should be able to subscribe to the shared IMAP folder through your favourite mail user agent (Mozilla Mail in my case)! You should also be able to see all the new emails delivered to this folder, even if they are addressed to another user.