I used procmail to do this, but anything that lets you process mail will work.
Code: Select all
:0c
* ^TO_.*myNVRalertEmail@mydomain.tld
* 9876543210^0 ^Content-Type:.*multipart
* 9876543210^0 ^Content-Type:.*inline
* 9876543210^0 ^Content-Type:.*image/jpeg
# If the message has any sort of attachment that could be an image...
{
# Write the mime message parts to a web accessible directory
:0fw
| ripmime -i - -d /www/photodrop/
# Get one file that was created in the last minute. This will *usually* be the most recent
# File, but with 8 cameras, maybe not.
FOTO=`find /www/photodrop/ -cmin -1 -size +10k -type f -exec basename {} \; | tail -1`
# WHOST is the http://server/path of the web host
URL="<${WHOST}/${FOTO}>"
URL=`echo $URL | sed 's/ /%20/g'`
# $HOOK is the web hook from api.slack.com
PAYLOAD="payload={\"icon_emoji\":\":warning:\",\"username\":\"QCAM-NVR\",\"text\":\"${URL}\"} $HOOK"
:0c
# If these match, there was no FOTO LINK, so abort
* ! URL ?? ^^${WHOST}^^
| curl -s --data-urlencode $PAYLOAD
# Or, use Oysttyer and dm yourself, but this results in twitter getting annoyed with you.
# | oysttyer -runcommand="/dm ${TWIT} $URL"
}