do not send an email when the body is empty

master 0.3
Y 2020-02-10 21:41:52 +01:00
parent 857d22870a
commit 9c343d46e4
2 changed files with 26 additions and 24 deletions

View File

@ -1,7 +1,7 @@
# Maintainer: Yves G. <theYinYeti@yalis.fr>
pkgname=epsi2ical
pkgver=0.2
pkgver=0.3
pkgrel=1
pkgdesc="Create an ICS file based on EPSIs web calendar"
arch=('any')

View File

@ -103,12 +103,7 @@ function unwrap_ical_long_lines() {
# $1: path to the old file
# $2: path to the new file
function format_diff_and_send_mail() {
{
echo "To: $TO"
echo 'Subject: Changes in EPSI calendar'
echo 'Content-Type: text/plain; charset=UTF-8'
echo
diff -u8 \
icalChanges="$(diff -u8 \
<(crlf_to_lf <"$1" | unwrap_ical_long_lines | grep -vE '^DTSTAMP:|^UID:') \
<(crlf_to_lf <"$2" | unwrap_ical_long_lines | grep -vE '^DTSTAMP:|^UID:') \
| awk '
@ -120,23 +115,30 @@ function format_diff_and_send_mail() {
/BEGIN:VEVENT/ { inEvent=1; diff="\n"; next }
$0 ~ /^[-+]/ { inDiff=1 }
/^@|END:VEVENT/ { out() }
{ diff=diff $0 "\n" }' \
| while IFS='' read -r l; do
case "$l" in
'')
echo; continue ;;
?DT*)
h="$(sed -r 's/^.DT(.*):.*/\1/' <<<"$l")"
v="$(date -d $(sed -r 's/.*:(....)(..)(..T..)(..)(..Z)/\1-\2-\3:\4:\5/' <<<"$l"))" ;;
*)
IFS=: read -r h v <<<"${l#?}" ;;
esac
printf '%s %11s: %s\n' "${l:0:1}" "$h" "$v"
done
} \
| lf_to_crlf \
| sendmail -t 2>&1 \
| log 3 -
{ diff=diff $0 "\n" }')"
if [ -n "$icalChanges" ]; then
{
echo "To: $TO"
echo 'Subject: Changes in EPSI calendar'
echo 'Content-Type: text/plain; charset=UTF-8'
echo
while IFS='' read -r l; do
case "$l" in
'')
echo; continue ;;
?DT*)
h="$(sed -r 's/^.DT(.*):.*/\1/' <<<"$l")"
v="$(date -d $(sed -r 's/.*:(....)(..)(..T..)(..)(..Z)/\1-\2-\3:\4:\5/' <<<"$l"))" ;;
*)
IFS=: read -r h v <<<"${l#?}" ;;
esac
printf '%s %11s: %s\n' "${l:0:1}" "$h" "$v"
done <<<"$icalChanges"
} \
| lf_to_crlf \
| sendmail -t 2>&1 \
| log 3 -
fi
}
function write_output_and_send_mail() {