Skip to content

Instantly share code, notes, and snippets.

@romanofski
Last active December 11, 2015 06:48
Show Gist options
  • Save romanofski/4561872 to your computer and use it in GitHub Desktop.
Save romanofski/4561872 to your computer and use it in GitHub Desktop.
To test a procmail setup (Source: http://lipas.uwasa.fi/~ts/info/proctips.html#start)
# check if a mail has interesting content for me based on a keyword
# search
SHELL=/bin/sh
PATH="$HOME/bin:/usr/bin:/usr/local/bin:/usr/include:/usr/local/sbin:/bin:/sbin:/usr/sbin"
TESTDIR=/tmp/procmailtest
MAILDIR=${TESTDIR}
LOGFILE=${TESTDIR}/Proctest.log
LOGABSTRACT=all
VERBOSE=yes
#
# mark my own mails which are not addressed to me as read
#
# check the body :D -> case insensitive
:0HBfD
* -1^0
* 1^0 ^List-
* 1^0 romanofski
|formail -I"X-Interesting: Yes"
# if the mail is flagged as interesting, deliver it to new and flag it
# with !
:0:
* X-Interesting:.*Yes
{
# First deliver to maildir so LASTFOLDER gets set
:0 c
${TESTDIR}/
# Manipulate the filename
:0 ai
* LASTFOLDER ?? ()\/[^/]+^^
|mv "$LASTFOLDER" "${TESTDIR}/new/$MATCH:2,FS"
}
# Hier landen alle restlichen Mails:
:0:
${TESTDIR}/Proctest.mail
#!/bin/bash
# Tests the procmail setup.
# from: http://lipas.uwasa.fi/~ts/info/proctips.html#start
TESTDIR=/tmp/procmailtest
if [ ! -d ${TESTDIR} ] ; then
echo "Directory ${TESTDIR} does not exist; First create it"
exit 0
fi
if [[ "$1" != /* ]]
then
echo "$1 needs to be an absolute path"
exit 1
fi
if [[ "$2" = "" ]]
then
echo "Second parameter should be the mail"
exit 1
fi
#Feed an email message to procmail. Apply proctest.rc recipes file.
#First prepare a mail.msg email file which you wish to use for the
#testing.
echo "procmail $1 < $2" >> ${TESTDIR}/Proctest.log
procmail $1 < $2
#
#Show the results.
less ${TESTDIR}/Proctest.log
clear
less ${TESTDIR}/Proctest.mail
#
#Clean up.
rm -i ${TESTDIR}/Proctest.log
rm -i ${TESTDIR}/Proctest.mail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment