Maildrop and the automatic maildirmake problem

If you are using a vanilla maildrop in a classic postfix (or another MTA) environment, you will have your master.cf to look like this:

maildrop unix - n n - - pipe
flags=DRhu user=vmail:vmail argv=/usr/bin/maildrop -d ${user}@${nexthop} ${user} ${nexthop} ${sender}

for example. And with this configuration, maildrop will not elaborate at all your /etc/maildroprc directive file. Why? Very simple (once you discover it): because we are using the -d switch which implies the Delivery mode. And it’s even written in the maildrop man page! Look:

Delivery mode

maildrop is the mail server’s mail delivery agent. maildrop runs in delivery mode when no filename is specified on the command line. maildrop
changes the current directory to the user’s home directory, then reads /etc/maildroprc, then $HOME/.mailfilter.

so, what’s happening here? Maildrop check if the ${user}@${nexthop} home directory exists and since it doesn’t, it simply exits spitting in your face :) So, no maildroprc rule applies, so you cannot create on-the-fly the homedir.
Now, there are two solutions:

  1. create manually (well, in the user-creation script) the home directory plus the Maildir with something like this:
    mkdir -p /home/vmail/domains/$DOMAIN/$USER
    maildirmake /home/vmail/domains/$DOMAIN/$USER/Maildir
    chown -R vmail:vmail /home/vmail/domains/$DOMAIN/$USER
  2. edit master.cf to be like this (in the maildrop part):

    maildrop unix - n n - - pipe
    flags=DRhu user=vmail:vmail argv=/usr/bin/maildrop /etc/maildroprc ${user} ${nexthop} ${sender}
    then give 0600 permissions and vmail ownership to /etc/maildroprc and finally append this to it (if you want to enable maildrop filter capabilities)
    USERMAILDIRFILTER="/home/vmail/domains/$DOMAIN/$USER/.mailfilter"
    DEFAULT="/home/vmail/domains/$DOMAIN/$USER/Maildir/."
    `[ -f $USERMAILDIRFILTER ]`
    if ( $RETURNCODE == 0 )
    {
    include $USERMAILDIRFILTER
    }

PS: Gentoo maildrop version is affected by this “problem”. On the other hand, Debian’s one seems to be “immune”

3 thoughts on “Maildrop and the automatic maildirmake problem

  1. Thanks for this post! It got me started in the right direction. Your solution does indeed work, but I have to use the -d option so that maildrop (I’m using the courier version) will talk to the courier auth service and get the mailQuotaSize from the LDAP directory holding all our users. Unfortunately, if I use the -d option, maildirs don’t get created. What I did was create a script called maildrop2.sh and put the maildir creation portion at the top. It reads piped data and pipes it out to maildrop with the -d option. In my master.cf file, I changed the maildrop command to point to the maildrop2.sh script. So far, it’s been working very well.

    maildrop2.sh:

    VHOME="/home/vmail/$2"
    MAILDIR="$VHOME/maildir"
    RCPT=$1

    while read DATA
    do
    MSG="${MSG}${DATA}\n"
    done

    if [ ! -d $MAILDIR ]
    then
    mkdir -p $VHOME
    maildirmake $MAILDIR
    fi

    echo -e $MSG | maildrop -w 90 -d $RCPT

    I’m not too good with shell scripting, so I’m sure it could be better.

  2. Ignore the code in my previous comment. It mangled headers pretty bad and I didn’t notice because the webmail I was using was tolerant of them. I updated the script to ‘cat’ the input instead of reading it line by line. This makes more sense (to me at least) and should be a little faster.

    maildrop2.sh

    VHOME="/home/vmail/$2"
    MAILDIR="$VHOME/maildir"
    RCPT=$1


    if [ ! -d $MAILDIR ]
    then
    mkdir -p $VHOME
    maildirmake $MAILDIR
    fi

    cat - | maildrop -w 90 -d $RCPT

Leave a comment