# Procmail Recipes for Nulligarchy  -*- mode: default-generic -*-

# Configuration

# Variables I need in the recipies
NULLDIR=$HOME/projects/nulligarchie
BACKUPS=$NULLDIR/tests/process-mail

# Variables that procmail uses
LOGABSTRACT=all
LOGFILE=$NULLDIR/tests/procmail.log

# Recipies

:0 h
* Subject:.*nulligarch.*new
* !^Subject:.*Re:
* !^FROM_DAEMON
* !^X-Loop: alex@gnu.org
{
 MAILDIR=$NULLDIR # chdir to the game directory

 :0 c             # keep a copy of the mail for debugging
 $BACKUPS

 :0 fhw           # reverse mailheader and extract name
 * ^Subject: *nulligarch.*new\>\/.*
 | formail -rA "X-Loop: alex@gnu.org"

 LOG="Matched: <$MATCH> "
 NAME="$MATCH"    # the name requested (if at all)

 # Header was filtered, body ignored, now send it back.
 :0 ah            # add output of null-administration
 | perl null-administration.pl --new $NAME | $SENDMAIL -oi -t

}


:0 h
* Subject:.*nulligarch.*orders?
* !^Subject:.*Re:
* !^FROM_DAEMON
* !^X-Loop: alex@gnu.org
{
 MAILDIR=$NULLDIR # chdir to the game directory

 :0 c             # keep a copy of the mail for debugging
 $BACKUPS

 :0 fw            # reverse mailheader and extract password, keep body
 * ^Subject: *nulligarch.*orders?\>\/.*
 | formail -rkbA "X-Loop: alex@gnu.org"

 LOG="Matched: <$MATCH> "
 PASSWORD="$MATCH"  # the password supplied (if at all)

 :0 aw            # add output of null-administration
 | perl null-administration.pl --save-orders $PASSWORD | $SENDMAIL -oi -t
 # | perl null-administration.pl --save-orders $PASSWORD >> tests/out
 # tests/out

}


:0 h
* Subject:.*nulligarch.*pass?
* !^Subject:.*Re:
* !^FROM_DAEMON
* !^X-Loop: alex@gnu.org
{
 MAILDIR=$NULLDIR # chdir to the game directory

 :0 c             # keep a copy of the mail for debugging
 $BACKUPS

 :0 fw            # reverse mailheader and extract password
 * ^Subject: *nulligarch.*pass[a-z]*\>\/.*
 | formail -rA "X-Loop: alex@gnu.org"

 LOG="Matched: <$MATCH> "
 PASSWORD="$MATCH"  # the password supplied (if at all)

 :0 aw            # add output of null-administration
 | perl null-administration.pl --change-password $PASSWORD | $SENDMAIL -oi -t

}
