File: sendmail-matrix

package info (click to toggle)
systemd-cron 2.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 656 kB
  • sloc: cpp: 2,276; sh: 933; makefile: 228; ansic: 133
file content (25 lines) | stat: -rwxr-xr-x 815 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/sh
TOKEN=systemd-cron  # probably source this from a file only readable by user _cron-failure, and don't make it "systemd-cron"
# The TO stanza should look something like
# TO='!QQQQQqqQQqQQqqQQqq:qqqqqqqqqqqqqq.qqq@https://matrix.qqqqqqqqqqqqqq.qqq:8448'


from=
to=
subject=
while read -r header rest; do
	case "$header" in
		""      )	break           ;;
		From:   )	from="$rest"    ;;
		To:     )	to="$rest"      ;;
		Subject:)	subject="$rest" ;;
	esac
done

room="${to%@*}"
server="${to#*@}"


content="$(jq -Rs --arg from "$from" --arg subject "$subject" '$subject + " ‒ " + $from + "\n\n" + .')"
exec curl --fail-with-body --no-progress-meter --oauth2-bearer "$TOKEN" \
	--data-binary '{"msgtype": "m.text", "body": '"$content"'}' -XPUT "$server/_matrix/client/r0/rooms/$room/send/m.room.message/$$"