split mfetch script in mail and feed sync services

This commit is contained in:
Felix Van der Jeugt 2021-03-16 12:10:07 +01:00
parent cc8184a717
commit 1f4788fb03
No known key found for this signature in database
GPG key ID: 58B209295023754D
3 changed files with 39 additions and 22 deletions

54
services/mailsync/run Executable file
View file

@ -0,0 +1,54 @@
#!/bin/sh
export USER="$(whoami)"
export HOME=/home/"$USER"
export DISPLAY=":0"
set -e
# Split outbox emails
mlist /data/mail/outbox | mpick -t 'from =~~ "posteo"' | mflag -F | mrefile /data/mail/posteo/Sent
mlist /data/mail/outbox | mpick -t 'from =~~ "ugent"' | mflag -F | mrefile /data/mail/ugent/Sent
mlist /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)"
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'
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

25
services/sfeed/run Executable file
View file

@ -0,0 +1,25 @@
#!/bin/sh
export USER="$(whoami)"
export HOME=/home/"$USER"
export DISPLAY=":0"
set -e
# check for internet connection
ip route ls | grep -q '.'
# check if the gpg-agent is running
pgrep gpg-agent > /dev/null
# Find new messages in feeds
d="$(mktemp -d)"
mmkdir "$d"
sfeed_update > /dev/null 2>&1
sfeed_mbox ~/.sfeed/feeds/* | mdeliver -M -v "$d" | while read mail; do
if ! mlist /data/mail/feeds | magrep -q message-id:"$(mshow -qh message-id "$mail" | cut -d' ' -f2)"; then
mdeliver -X F /data/mail/feeds < "$mail" > /dev/null
fi
done
rm -rf "$d"
exec sleep 1h

View file

@ -2,7 +2,6 @@
export USER="$(whoami)"
export HOME=/home/"$USER"
export DISPLAY=":0"
. "$HOME"/.profile
set -e