Skip to content

Instantly share code, notes, and snippets.

@moisseev
Last active March 17, 2017 05:48
Show Gist options
  • Save moisseev/3cd6f0eef59bfc84ec6ace7ec584ef67 to your computer and use it in GitHub Desktop.
Save moisseev/3cd6f0eef59bfc84ec6ace7ec584ef67 to your computer and use it in GitHub Desktop.
Check DKIM signatures of messages stored in a Maildir
#!/bin/sh
MAILDIR="/vmail/example.com/test/Maildir"
DIR_BAD="$MAILDIR/.dkim_bad/new"
DIR_GOOD="$MAILDIR/.dkim_good/new"
DIR_NO_SIG="$MAILDIR/.dkim_no_sig/new"
#-------------------------------
MODE_SORT=
PROGNAME=`basename $0`
PROGDESCR="$PROGNAME - check DKIM signatures of messages stored in a Maildir"
usage () {
cat >&2 <<EOF
$PROGDESCR
usage: $PROGNAME [-s|-h]
-s sort messages using predefined directories
-h brief help
EOF
}
while getopts sh opt; do
case "$opt" in
s)
MODE_SORT=1;;
# \? - unknown flag
h|?)
usage
[ $opt = "h" ] && exit 0
exit 1;;
esac
done
cd $MAILDIR || exit 1
for MSG in ./cur/* ./new/* ; do
[ -f "$MSG" ] || continue
RES=`zcat -f "$MSG" | opendkim-testmsg 2>&1`
printf '.'
[ $? -ne "0" ] && printf "$MSG\n\n"
case "$RES" in
'')
[ $MODE_SORT ] && mv "$MSG" "$DIR_GOOD/";;
'opendkim-testmsg: dkim_eom(): Bad signature')
printf "\nBad signature: $MSG\n"
[ $MODE_SORT ] && mv "$MSG" "$DIR_BAD/";;
'opendkim-testmsg: dkim_chunk(): No signature')
printf "\nNo signature: $MSG\n"
[ $MODE_SORT ] && mv "$MSG" "$DIR_NO_SIG/";;
*)
echo "Unknown test result: $RES";;
esac
done
echo
@moisseev
Copy link
Author

moisseev commented Oct 14, 2016

Dovecot passwd-file entry:

[email protected]:password::::::userdb_mail=maildir:~/Maildir

main.cf:

sender_bcc_maps = hash:$config_directory/sender_bcc

sender_bcc:

@example.com        [email protected]
@example1.com       [email protected]
@example2.com       [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment