#!/bin/sh
read -r first_line_from_stdin  # consume the first line of stdin; remaining lines are read by commands below
if [ "$first_line_from_stdin" = 'self-resend' ]; then  # check first line to decide which commands to execute
	/usr/bin/unresend.crm  | ( /usr/bin/mailfilter.crm --fileprefix=/var/mailfilter/ --learnnonspam || /bin/cat )
else
	/usr/bin/movemsgid.crm | ( /usr/bin/mailfilter.crm --fileprefix=/var/mailfilter/                || ( /bin/cat; echo FAILED CRM ) )
fi
