#set delete-oversized
#set default-user "nicholas"
#set allow-multiple
set purge-after 50
#set proxy "socks://localhost:1080/"
#set timeout 120
set parallel-accounts 2

# My fdm configuration base path.
$base = "%h/.fdm.d"

# Lock file path.
set lock-file "${base}/lock"

# Maximum mail size.
set maximum-size 100 MB

# Verify SSL certificates.
set verify-certificates

# These seem to vaguely work okay for me.
set queue-high 5
set queue-low 3

# Use dotlock locking, since FreeBSD doesn't like anything else on NFS.
#set lock-types dotlock

# Macro holding the path where the maildirs are.
$path = "%h/mail"

# My main inbox and junk mail directories.
action "inbox" maildir "${path}/Inbox"
action "junk" maildir "${path}/Junk"

# Account definitions. All passwords and most usernames are read from .netrc.
#account "ntlworld" pop3s server "pop.ntlworld.com" port 995

account "gmail.nicholas.marriott" imaps server "imap.googlemail.com"
	port 993 user "nicholas.marriott@gmail.com" no-verify

# The stdin account is disabled: it will be ignored unless explicitly requested
# using the -a switch on the command line.
account "stdin" disabled stdin

# ------------------------------------------------------------------------------
# These two definitions are part of killfiling - the action appends the
# message-id to my block list and the macro is used to check that no message-id
# in the references or in-reply-to headers matches any in the file, if it does
# the mail is dropped later. This means I not only don't need to read mail from
# idiots, I also don't have to read many of the hundred follow-ups telling them
# they are an idiot. Use with care: this can be slow.
# ------------------------------------------------------------------------------
action "dead" maildir "${path}/diediedie"
action "diediedie" { exec "echo '%[message_id]' >>${base}/ignore" action "dead" }
$is_dead = "echo '%1'|grep -Fqif ${base}/ignore"
# ------------------------------------------------------------------------------

# ------------------------------------------------------------------------------
# Archive mail to mailboxes.
# ------------------------------------------------------------------------------
account "archive" disabled maildirs {
	"${path}/blug"
	"${path}/openbsd-{misc,ports,bugs,source-changes,ports-changes}"
	"${path}/openssh-unix-dev"
	"${path}/austin-group-l"
}
#action "archive" mbox "${path}/%[maildir]-archives/%[maildir]-%yq%Q" compress
action "archive" drop

match account "archive" {
	# Archive mail with invalid dates or older than 30 days.
	match age invalid or age > 30 days action "archive"

	# Don't let any other mail get to the normal rules.
	match all action keep
}
# ------------------------------------------------------------------------------

# ------------------------------------------------------------------------------
# Newsgroups. These are disabled so I can run them using a "fdm -anews f" from
# a seperate cronjob less often than normal mail accounts.
# ------------------------------------------------------------------------------
account "news" disabled nntp
        server "infosun2.rus.uni-stuttgart.de"
        groups {
                "comp.unix.bsd.openbsd.misc"
#               "comp.unix.programmer"
        }
        cache "${base}/news"

match account "news" {
        match "\\<HTML\\>" in body action "junk"

        # comp.unix.programmer pointless argument usual suspects.
        match "^From:.*rweikusat@mssgmbh.com" in headers action drop
        match "^From:.*davids@webmaster.com" in headers action drop

        # Idiots.
        match "^From:.*MI5-?Victim@mi5.gov.uk" in headers action drop
        match "^Organization:.*www.altopia.com" in headers action drop
        match "^From:.*robin_carey5@yahoo.co.uk" in headers action drop

	# Spammers.
	match "^From:.*jak@isp2dial.com" in headers action drop
	match "^From:.*doctor@doctor.nl2k.ab.ca" in headers action drop

        # Match based on the group name.
        match all action maildir "${path}/news-%[group]"
}
# ------------------------------------------------------------------------------

# Catch local mail early.
match account "stdin" action "inbox"

# Catch duplicate messages using a message-id cache.
$db = "${base}/duplicates"
$key = "%[message_id]"
cache $db expire 1 week

match not string $key to "" {
	# Filter messages already in the cache.
	match in-cache $db key $key {
	      # Stupid Google Groups sends me everything twice.
	      match "List-Id:.*belfastlinux.googlegroups.com" in headers
	      	    action drop

	      match all action maildir "${path}/Duplicates"
	}

	# Add message-ids to the cache.
	match all action to-cache $db key $key continue
}

# Junk (eejits).
match ".*YAHOO.*BOOTER.*" in body action drop

# Junk (spam).
match "^From:.*ezine@recruitni.com" in headers action drop
match "^From:.*@*.chase.com" in headers action drop
match "^From:.*@*.chaseonline.com" in headers action drop
match "^From:.*@citi-bank.com" in headers action drop
match "^From:.*@emaillabs.com" in headers action drop
match "^From:.*baypos@gmail.com" in headers action drop
match "^From:.*E-Greeting" in headers action drop
match "^From:.*@postcard.org" in headers action drop
match "^From:.*@mail.itp.net" in headers action drop
match "^From:.*@faith-h.net" in headers action drop
match "^From:.*reponse@altech-france.fr" in headers action drop
match "^From:.*ecards@americangreetings.com" in headers action drop

# Junk (ISP/website garbage).
match "^From:.*@newsletter.ntlworld.com" in headers action drop
match "^From:.*@newsletter.virginmedia.com" in headers action drop
match "^From:.*mailings@(gmxnet.de|gmx.net|gmx-gmbh.de)" in headers action drop
match "^From:.*mailings@fmp.gmxnet.de" in headers action drop
match "^From:.*@friendsreunited.co.uk" in headers action drop
match "^From:.*offers@dabs.com" in headers action drop

# AWAD uninteresting crap.
match "^Subject:[ \t]*AWADmail Issue [0-9]+" in headers action drop

# Copy invalid dates to a special action so I can inspect them.
match age invalid action maildir "${path}/Invalid" continue

# Copy HTML mail to special action to test attachment parsing.
#match attachment any-type "*/html" action maildir "${path}/HTML" continue

# Test rewriting through cat.
#match all action rewrite "cat" continue

# Test mbox delivery.
#match size > 1K and size < 4K action mbox "${path}/MBOX" compress continue

# Add line count header.
match all action add-header "Lines" value "%[lines]" continue

# Add rule number header.
#match all action add-header "Rule" value "%[rule]" continue

# BLUG mailing list.
match "^X-Apparently-To:.*belfastlinux@googlegroups.com" in headers or
	"List-ID:.*belfastlinux.googlegroups.com" in headers
	action maildir "${path}/blug"

# ------------------------------------------------------------------------------
# OpenBSD.
# ------------------------------------------------------------------------------
match "^Sender:.*owner-([a-z-]*)@openbsd.org" in headers {
	# Tag the mail.
	match all action tag "list" value "%1" continue

	# Drop any mail which is replying to a message-id on the ignore list.
	match "^References:[ \t]*(.*)" in headers and
		exec ${is_dead} returns (0, ) action "dead"
	match "^In-Reply-To:[ \t]*([^()]*)" in headers and
		exec ${is_dead} returns (0, ) action "dead"

	# Drop a selection of eejits/trolls/time wasters/whiners/pompous
	# twits/uninteresting persons and add to ignore list.
	match "^From:.*noobzillatron@gmail.com" in headers action "diediedie"
	match "^From:.*4625khz@gmail.com" in headers action "diediedie"
	match "^From:.*Rhubbell@iHubbell.com" in headers action "diediedie"
	match "^From:.*af.gourmet@videotron.ca" in headers action "diediedie"
	match "^From:.*billitch@gmail.com" in headers action "diediedie"
	match "^From:.*chefren@pi.net" in headers action "diediedie"
	match "^From:.*clock@twibright.com" in headers action "diediedie"
	match "^From:.*demuel@thephinix.org" in headers action "diediedie"
	match "^From:.*dfeustel@mindspring.com" in headers action "diediedie"
	match "^From:.*donaldcallen@gmail.com" in headers action "diediedie"
	match "^From:.*emaillistemail@gmail.com" in headers action "diediedie"
	match "^From:.*fritz@.*.rodent.frell.theremailer.net" in headers action "diediedie"
	match "^From:.*glisten@witworx.com" in headers action "diediedie"
	match "^From:.*jl2868@yahoo.com" in headers action "diediedie"
	match "^From:.*john@johntate.org" in headers action "diediedie"
	match "^From:.*leonleon77@gmail.com" in headers action "diediedie"
	match "^From:.*lvl@omnitec.net" in headers action "diediedie"
	match "^From:.*ma1l1ists@yahoo.co.uk" in headers action "diediedie"
	match "^From:.*nealhogan@gmail.com" in headers action "diediedie"
	match "^From:.*nicedaemon@googlemail.com" in headers action "diediedie"
	match "^From:.*nobody@dizum.com" in headers action "diediedie"
	match "^From:.*peter_philipp@freenet.de" in headers action "diediedie"
	match "^From:.*philipp.peter@freenet.de" in headers action "diediedie"
	match "^From:.*rms@1407.org" in headers action "diediedie"
	match "^From:.*ropers@gmail.com" in headers action "diediedie"
	match "^From:.*suck@my-balls.com" in headers action "diediedie"
	match "^From:.*timo.schoeler@riscworks.net" in headers action "diediedie"
	match "^From:.*vim.unix@googlemail.com" in headers action "diediedie"
	match "^From:.*yclwebmaster@gmail.com" in headers action "diediedie"
	match "^From:.*slashy83@gmail.com" in headers action "diediedie"

	# Special-case announce.
	match string "%[list]" to "announce" action "inbox"

	# Special-case gnats.
	match string "%[list]" to "gnats" action "${path}/openbsd-bugs"

 	# Deliver to openbsd-%1.
	match all action maildir "${path}/openbsd-%[list]"
}
# ------------------------------------------------------------------------------

# ------------------------------------------------------------------------------
# NetBSD.
# ------------------------------------------------------------------------------
#match "^List-Id: ([a-z-]*).NetBSD.org" in headers
#	action maildir "${path}/netbsd-%1"
# ------------------------------------------------------------------------------

# ------------------------------------------------------------------------------
# FreeBSD.
# ------------------------------------------------------------------------------
#match "^Sender:.*owner-([a-z-]*)@freebsd.org" in headers
#	action maildir "${path}/freebsd-%1"
# ------------------------------------------------------------------------------

# ------------------------------------------------------------------------------
# GNU Screen.
# ------------------------------------------------------------------------------
match "^X-BeenThere:.*screen-users@gnu.org" in headers
	action maildir "${path}/screen-users"
match "^X-BeenThere:.*screen-devel@gnu.org" in headers
	action maildir "${path}/screen-devel"
# ------------------------------------------------------------------------------

# ------------------------------------------------------------------------------
# GNU ncurses.
# ------------------------------------------------------------------------------
match "^X-BeenThere:.*bug-ncurses@gnu.org" in headers
	action maildir "${path}/bug-ncurses"
# ------------------------------------------------------------------------------

# ------------------------------------------------------------------------------
# libevent.
# ------------------------------------------------------------------------------
match "^Sender: owner-libevent-users@freehaven.net" in headers
	action maildir "${path}/libevent-users"
# ------------------------------------------------------------------------------

# ------------------------------------------------------------------------------
# btpd.
# ------------------------------------------------------------------------------
match "^Sender: btpd-users@googlegroups.com" in headers
	action maildir "${path}/btpd-users"
# ------------------------------------------------------------------------------

# ------------------------------------------------------------------------------
# OpenSSH.
# ------------------------------------------------------------------------------
match "^X-BeenThere:.*openssh-unix-dev@mindrot.org" in headers
	action maildir "${path}/openssh-unix-dev"
# ------------------------------------------------------------------------------

# ------------------------------------------------------------------------------
# OSS Security.
# ------------------------------------------------------------------------------
#match "^List-Post:.*oss-security@lists.openwall.com" in headers
#	action maildir "${path}/oss-security"
# ------------------------------------------------------------------------------

# ------------------------------------------------------------------------------
# Austin-Group-L.
# ------------------------------------------------------------------------------
match "^X-Mailing-List:.*austin-group-l" in headers
	action maildir "${path}/austin-group-l"
# ------------------------------------------------------------------------------

# Default action.
match all action "inbox"
