Compare commits

...

2 Commits
0.1 ... master

Author SHA1 Message Date
Y 9c343d46e4 do not send an email when the body is empty 2020-02-10 21:41:52 +01:00
Y 857d22870a specify UTF-8 encoding for emails 2020-02-09 19:23:38 +01:00
2 changed files with 26 additions and 23 deletions

View File

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

View File

@ -103,11 +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
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 '
@ -119,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() {