#!/bin/bash

# xymon-by-email receiving script

# pick up standard environment - only really need $XYMSRV
source /home/xymon/server/etc/xymonserver.cfg

# while testing, clear the previous headers
> /tmp/xymonmsg.header

while read header
do
  # headers can be evaluated with a case statement, maybe pick out the "From"
  # address to verify the sender before dumping the report into xymon.
  if [ "X$header" = "X" ]; then
    # found the blank line that marks end of headers
    break
  fi

  # while testing, save headers
  echo "$header" >> /tmp/xymonmsg.header
done

# copy the remainder to xymon, dropping any return data
# the payload is base64 encoded because *something* was folding long lines.  Clearly, the pipeline
# could temporarily store the message for checking md5/sha1 fingerprints, decryption, etc.
cat - | base64 -d | tee /tmp/xymonmsg.body | /home/xymon/server/bin/xymon $XYMSRV "@" > /dev/null 2>&1
