#!/bin/sh

. "`dirname \"$0\"`/common.sh"

USER="mailto:paul.boddie@example.com"
SENDER="mailto:resource-room-confroom@example.com"

mkdir -p "$PREFS/$USER"
echo 'Europe/Oslo' > "$PREFS/$USER/TZID"
echo 'share' > "$PREFS/$USER/freebusy_sharing"

  "$PERSON_SCRIPT" $ARGS < "$TEMPLATES/fb-publish.txt" 2>> $ERROR \
| "$SHOWMAIL" \
> out0.tmp

  "$LIST_SCRIPT" $LIST_ARGS "$USER" "freebusy_other" "$SENDER" \
> out1.tmp

   grep -q "^20140401T070000Z${TAB}20140401T080000Z" "out1.tmp" \
&& grep -q "^20140401T080000Z${TAB}20140401T100000Z" "out1.tmp" \
&& echo "Success" \
|| echo "Failed"

  "$PERSON_SCRIPT" $ARGS < "$TEMPLATES/fb-publish-again.txt" 2>> $ERROR \
| "$SHOWMAIL" \
> out2.tmp

  "$LIST_SCRIPT" $LIST_ARGS "$USER" "freebusy_other" "$SENDER" \
> out3.tmp

   grep -q "^20140401T070000Z${TAB}20140401T080000Z" "out3.tmp" \
&& ! grep -q "^20140401T080000Z${TAB}20140401T100000Z" "out3.tmp" \
&& grep -q "^20140401T083000Z${TAB}20140401T100000Z" "out3.tmp" \
&& echo "Success" \
|| echo "Failed"
