configuration/services/mailsync/run
2021-03-17 09:59:47 +01:00

56 lines
2.1 KiB
Bash
Executable File

#!/bin/sh
export USER="$(whoami)"
export HOME=/home/"$USER"
export DISPLAY=":0"
set -e
# Split outbox emails
mlist -d /data/mail/outbox | mpick -t 'from =~~ "posteo"' | mflag -F | mrefile /data/mail/posteo/Sent
mlist -d /data/mail/outbox | mpick -t 'from =~~ "ugent"' | mflag -F | mrefile /data/mail/ugent/Sent
mlist -d /data/mail/outbox | mpick -t 'from =~~ "gmail"' | mflag -F | mrefile /data/mail/gmail/Sent
# check for internet connection
ip route ls | grep -q '.'
# check if the gpg-agent is running
pgrep gpg-agent > /dev/null
# Sync email
mbsync -a -q
# No further processing if there are no new mails
if ! mdirs /data/mail | mlist -N | grep -q .; then
exec sleep 1m
fi
# Incorporate new mails and store them in the temp sequence
s="$(mktemp)"
trap "rm '$s'" EXIT KILL
minc $(mdirs /data/mail) > "$s"
{
# Ignores
mpick -t 'to =~ "unipept@ugent.be" && subject ~~ "*Mysql2::Error::ConnectionError*"' < "$s"
mpick -t 'to =~ "dodona@ugent.be" && from =~ "logcheck system account"' < "$s"
mpick -t 'to =~ "dodona@ugent.be" && subject =~ "A request took"' < "$s"
mpick -t 'to =~ "dodona@ugent.be" && subject =~ "Onderwijsinstelling aangemaakt voor"' < "$s"
mpick -t 'to =~ "dodona@ugent.be" && subject =~ "Een gebruiker kon niet inloggen"' < "$s"
mpick -t 'to =~ "dodona@ugent.be" && subject =~ "Invalid or unknown LTI provider"' < "$s"
mpick -t 'to =~ "dodona@ugent.be" && subject =~ "Faraday::ConnectionFailed"' < "$s"
mpick -t 'to =~ "dodona@ugent.be" && subject =~ "internal error"' < "$s" \
| xargs grep -E -l 'course_id: (284|317|335|339|346|349|355|359|374|375|376|380|384|414)'
mpick -t 'to =~ "dodona@ugent.be" && subject =~ "internal error"' < "$s" \
| xargs grep -E -l 'user_id: (3|7078)'
mpick -t 'subject =~ "\[hackers\] \[slstatus\]"' < "$s"
mpick -t 'from =~ "dependabot-preview"' < "$s"
# Muted mails
for muted in $(cat ~/.mblaze/muted); do
mpick -t '"references" =~~ "'"$muted"'"' < "$s"
done
} | sort | uniq | mflag -Sf > /dev/null
# Clear muted sequence
#mseq -f < ~/.mblaze/muted | mpick -t 'date < "'"$(date -I -d '1 month ago')"'"' | sponge ~/.mblaze/muted