Maildrop automatic dir creation

Discussion in 'Server Operation' started by MrTheo, Nov 26, 2006.

  1. MrTheo

    MrTheo New Member

    Hi,

    I've done the tutorial from this site on mail filtering (http://www.howtoforge.com/postfix_mailfilter), which works great and mail gets filtered and delivered properly now. I have one problem though.

    In the /etc/maildroprc there's all kind of things to create the virtual domain dir and the maildir for the user in case it doesn't exist yet. But I kept getting "Unable to change to home directory." errors, and after checking the maildrop source, I noticed that the maildroprc doesn't get loaded until after it tries to change to the /home/vmail/domain.tld/user directory, so all those things in the maildroprc are basically there for nothing, because if it ever gets there, it means all those directories already exist.

    Of course the above can be fixed by just creating the directories myself, but I rather have it creating it in case it doesn't exist yet. Is there some way to do that using maildrop techniques, or will I have to create something for it myself?

    Also, currently Squirrelmail creates subfolders (like .Spam) the first time you login to an account, but is there some nice way to do that as well when an account is created and the first mail arrives to it before the user has logged in?

    Thanks,
    Theo
     
  2. falko

    falko Super Moderator ISPConfig Developer

    I haven't worked with that tutorial yet, so I'm afraid I can't help you... :(
     
  3. ColdDoT

    ColdDoT Member

    I've worked with it and the script he posted was surely not working for me so i writen my own maybe it is usefull to u

    /etc/maildroprc
    Code:
    #
    # Define variables
    #
    SHELL="/bin/bash"
    EXTENSION="$1"
    RECIPIENT=tolower("$2")
    HOME="/home/vmail"
    USER="$3"
    HOST="$4"
    SENDER="$5"
    DEFAULT="$HOME/$HOST/$USER"
    MAILDIR="$HOME/$HOST/$USER"
    
    logfile "/var/log/maildrop.log"
    log "Markers:   ---------------------------------------------"
    log " (**) from config file, (II) informational, (WW) warning"
    log "--------------------------------------------------------"
    log ""
    
    
    ######################################################################
    #
    # Adding missing headers for PGP/MIME
    #
    
    BPM="-----BEGIN PGP MESSAGE-----"
    EPM="-----END PGP MESSAGE-----"
    BPS="-----BEGIN PGP SIGNATURE-----"
    EPS="-----END PGP SIGNATURE-----"
    
    if (!/^Content-Type: message/ && !/^Content-Type: multipart/ \
            && !/^Content-Type: application\/pgp/)
                    {
                    if (/^$BPM/:b && /^$EPM/:b)
                    xfilter "reformail -A 'Content-Type: application/pgp; format=text; \
                            x-action=encrypt'"
    
                    if (/^$BPS/:b && /^$EPS/:b)
                    xfilter "reformail -A 'Content-Type: application/pgp; format=text; \
                            x-action=sign'"
                    }
    
    
    #####################################################################
    #
    #  Correcting wrong signature dashes
    #
    
    if (/^--($|[ ]{2,}^)/:b)
            {
            xfilter "sed -r 's/^--($|[ ]{2,}^)/-- /'"
            log "(II) Sig Dashes corrected"
            }
    
    # Include any rules set up for the user - this gives the
    #   administrator a way to override the domain's mailfilter file
    #
    #   this is also the "suggested" way to set individual values
    #   for maildrop such as quota. (why do you need quota on your own PC?)
    #
    `test -e $HOME/$HOST`
    if ( $RETURNCODE != 0 )
    {
            `/bin/mkdir $HOME/$HOST`
            `/bin/chown vmail.vmail $HOME/$HOST`
            `/bin/chmod 0700 $HOME/$HOST`
    }
    
    `test -e $HOME/$HOST/$USER`
    if ( $RETURNCODE != 0 )
    {
            `/usr/bin/maildirmake $HOME/$HOST/$USER`
            `/bin/chown -R vmail.vmail $HOME/$HOST`
            `/bin/chmod -R 0700 $HOME/$HOST`
    }
    
    `test -r $HOME/mailfilters/$HOST`
    if( $RETURNCODE == 0 )
    {
            log "(==)  Including $HOME/mailfilters/$HOST"
            include $HOME/mailfilters/$HOST
    }
    

    example filter for my domain:
    /home/vmail/mailfilters/colddot.nl
    Code:
    if( /^X-Spam-Flag: YES/ )
    {
            to "$DEFAULT/.Trash/"
    }
    
    I hope it is isefull for u

    Greets ColdDoT
    (it is working for me, tested)
     

Share This Page