# Global maildrop filter file

SHELL="/bin/bash"

import EXT
import HOST

logfile "/var/log/maildrop.log"

VPOP="| /var/vpopmail/bin/vdelivermail '' bounce-no-mailbox"
VHOME=`/var/vpopmail/bin/vuserinfo -d $EXT@$HOST`
SPAMFOLDER="Spamverdacht"
LEARNFOLDER="Spamlernen"

log "EXT is $EXT"
log "HOST is $HOST"
log "VHOME is $VHOME"

`test "$EXT" == "doublebounce"`
if ( $RETURNCODE == 0 )
{
	log "Delete doublebounce"
	exit
}

`test "$VHOME" == ""`
if ( $RETURNCODE == 0 )
{
	log "No such user, delivering to normal qmail"
	to "$VPOP"
}

# Create the spamfolder if it does not exists
`test -d "$VHOME/.maildir/.$SPAMFOLDER"`
if( $RETURNCODE == 0 )
{
}
else
{
	`/usr/bin/maildirmake -f "$SPAMFOLDER" "$VHOME/.maildir"`
	`chown vpopmail:vpopmail -R "$VHOME/.maildir/.$SPAMFOLDER"`
	
	`/usr/bin/maildirmake -f "$LEARNFOLDER" "$VHOME/.maildir"`
	`chown vpopmail:vpopmail -R "$VHOME/.maildir/.$LEARNFOLDER"`

	`echo "INBOX.Spamverdacht" >> $VHOME/.maildir/courierimapsubscribed`
	`echo "INBOX.Spamlernen" >> $VHOME/.maildir/courierimapsubscribed`
}

if (/^X-Spam-Status: *YES/)
{
exception {
	to "$VHOME/.maildir/.$SPAMFOLDER"
}
exception {
	to "$VPOP"
}
}
else
{
exception {
	to "$VPOP"
}
}

