configuration/local/bin/mfetch

62 lines
2.3 KiB
Plaintext
Raw Normal View History

2020-12-04 14:56:09 +01:00
#!/bin/sh
# Split outbox emails
2021-03-16 10:47:31 +01:00
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
2020-12-04 14:56:09 +01:00
2020-12-13 00:38:48 +01:00
# Find new messages in feeds
d="$(mktemp -d)"
mmkdir "$d"
2021-03-16 10:47:31 +01:00
date
2020-12-13 00:38:48 +01:00
sfeed_update
2021-03-16 10:47:31 +01:00
date
2020-12-13 00:38:48 +01:00
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 /data/mail/feeds < "$mail"
2021-03-16 10:47:31 +01:00
# TODO -X dfprst or -X '' (no flags)
2020-12-13 00:38:48 +01:00
fi
done
2021-03-16 10:47:31 +01:00
date
2020-12-13 00:38:48 +01:00
rm -rf "$d"
2020-12-04 14:56:09 +01:00
# Sync email
mbsync -a
# No further processing if there are no new mails
if ! mdirs /data/mail | mlist -N | grep -q .; then
exit
fi
# Incorporate new mails and store them in the temp sequence
2021-03-16 10:47:31 +01:00
s="$(mktemp)"
minc $(mdirs /data/mail) > "$s"
2020-12-04 14:56:09 +01:00
{
# Ignores
2021-03-16 10:47:31 +01:00
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" \
2020-12-04 14:56:09 +01:00
| xargs grep -E -l 'course_id: (284|317|335|339|346|349|355|359|374|375|376|380|384|414)'
2021-03-16 10:47:31 +01:00
mpick -t 'to =~ "dodona@ugent.be" && subject =~ "internal error"' < "$s" \
2020-12-04 14:56:09 +01:00
| xargs grep -E -l 'user_id: 3'
2021-03-16 10:47:31 +01:00
mpick -t 'subject =~ "\[hackers\] \[slstatus\]"' < "$s"
mpick -t 'from =~ "dependabot-preview"' < "$s"
2020-12-04 14:56:09 +01:00
# Muted mails
for muted in $(cat ~/.mblaze/muted); do
2021-03-16 10:47:31 +01:00
mpick -t '"references" =~~ "'"$muted"'"' < "$s"
2020-12-04 14:56:09 +01:00
done
2020-12-13 00:38:48 +01:00
} | sort | uniq | mflag -Sf
2020-12-04 14:56:09 +01:00
# Clear muted sequence
#mseq -f < ~/.mblaze/muted | mpick -t 'date < "'"$(date -I -d '1 month ago')"'"' | sponge ~/.mblaze/muted
# Show the remaining new mails
2021-03-16 10:47:31 +01:00
mseq -f < "$s" | mpick -t 'flagged || ! seen' | mseq -S
2020-12-04 14:56:09 +01:00
mscan