configuration/services/mailsync/run

42 lines
1.0 KiB
Plaintext
Raw Normal View History

2020-12-04 14:56:09 +01:00
#!/bin/sh
export USER="$(whoami)"
export HOME=/home/"$USER"
export DISPLAY=":0"
set -e
# Don't sync mails while composing
if pgrep -f mcom > /dev/null; then exit; fi
if pgrep -f mfwd > /dev/null; then exit; fi
if pgrep -f mbnc > /dev/null; then exit; fi
if pgrep -f mrep > /dev/null; then exit; fi
2020-12-04 14:56:09 +01:00
# Split outbox emails
mlist -d /data/mail/outbox | mpick -t 'from =~~ "posteo"' | mflag -F | mrefile /data/mail/posteo/Sent
2020-12-04 14:56:09 +01:00
# check for internet connection
ip route ls | grep -q '.'
# check if the gpg-agent is running
pgrep gpg-agent > /dev/null
2020-12-13 00:38:48 +01:00
2020-12-04 14:56:09 +01:00
# Sync email
2022-01-04 00:27:11 +01:00
mbsync -a -q || true
2020-12-04 14:56:09 +01:00
# No further processing if there are no new mails
if ! mdirs /data/mail | mlist -N | grep -q .; then
exec sleep 1m
2020-12-04 14:56:09 +01:00
fi
# Incorporate new mails and store them in the temp sequence
2021-03-16 10:47:31 +01:00
s="$(mktemp)"
trap "rm '$s'" EXIT KILL
mdirs /data/mail | minc > "$s"
2020-12-04 14:56:09 +01:00
{
# Ignores
2021-03-16 10:47:31 +01:00
mpick -t 'subject =~ "\[hackers\] \[slstatus\]"' < "$s"
mpick -t 'subject =~ "\[hackers\] \[svkdb\]"' < "$s"
mpick -t 'subject ~~ "*Bump * from * to *" && "cc" !~~ "Felix*"' < "$s"
} | sort | uniq | mflag -Sf > /dev/null