Skip to content

Instantly share code, notes, and snippets.

@fgr0
Last active May 12, 2019 13:31
Show Gist options
  • Select an option

  • Save fgr0/8aa5397ade17a9ce1bd74193f7fb10af to your computer and use it in GitHub Desktop.

Select an option

Save fgr0/8aa5397ade17a9ce1bd74193f7fb10af to your computer and use it in GitHub Desktop.
Maildrop Configuration for Uberspace
# sorting for mailing lists by using list-id for foldername
# only apply rules if recipient is mailing@domain.tld
if ( $RECIPIENT =~ /.*-(mailing|lists)@.+/ )
{
# check if List-ID is present and use it as a folder name
if ( /^List-ID:.*<(.*)>/:h )
{
LISTID=`echo $MATCH1 | awk -F. '{print $1}'`
log "List-ID: $LISTID"
FOLDER = "$VUSERMAILDIR/.lists.$LISTID"
}
}
# sorting for mailing lists by using list-id for foldername
# check blacklist
if ( /^From:\s*(.*)/ && lookup( $MATCH1 , "$HOME/.maildrop-blacklist.txt"))
{
log "Dropped: Sender is blacklisted\n"
exit
}
# check spamscore
if ( /^X-Rspamd-Bar: (\+{$SPAMMAX,})$/:h )
{
log "Spam: $MATCH1"
log "Dropped: Spamscore to high\n"
exit
}
elsif ( /^X-Rspamd-Bar: (\+{$SPAMMIN,})$/:h )
{
log "Spam: $MATCH1"
FOLDER = "$VUSERMAILDIR/.junk"
}
# sorting for wildcard inbox *.*@domain.tld by using .*.* as foldername
# recipient contains a '.' in the userpart of the address
if ( $RECIPIENT =~ /((.+)\..+)@.+/ )
{
# remove mail-namespace prefix
DIR=tolower(substr($MATCH1, length($NAMESPACEPREFIX)))
PDIR=tolower(substr($MATCH2, length($NAMESPACEPREFIX)))
# Make sure that parent folder exists
`test -d $VUSERMAILDIR/.$PDIR/new && exit 1 || exit 0`
if ( $RETURNCODE == 1 )
{
log "Wildcard: $DIR"
FOLDER = "$VUSERMAILDIR/.$DIR/"
}
}
VUSERMAILDIR = "$HOME/Maildir"
NAMESPACEPREFIX = "ubername-"
SPAMMIN = "3"
SPAMMAX = "10"
# logging
logfile "$HOME/maildrop.log"
# check for valid username
if ( $RECIPIENT =~ /(.+)@.+/ && lookup(substr($MATCH1, length($NAMESPACEPREFIX)), "$HOME/.maildrop/users.txt"))
{
log "Username: $MATCH1"
FOLDER = "$VUSERMAILDIR/"
}
# mailing list detection and sorting
include "$HOME/.maildrop-lists.conf"
# wildcard sorting
include "$HOME/.maildrop-wildcard.conf"
if ( $FOLDER )
{
# spam filtering
include "$HOME/.maildrop-spam.conf"
# deliver mail
`test -d $FOLDER/new && exit 1 || exit 0`
if ( $RETURNCODE == 0 )
{
`maildirmake $FOLDER`
}
to "$FOLDER"
}
log "Dropped: No valid recipient ($FROM -> $RECIPIENT)\n"
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment