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

View File

@ -1,30 +1,27 @@
#!/bin/sh #!/bin/sh
export USER="$(whoami)"
export HOME=/home/"$USER"
export DISPLAY=":0"
set -e
# Split outbox emails # 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 =~~ "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 =~~ "ugent"' | mflag -F | mrefile /data/mail/ugent/Sent
mlist /data/mail/outbox | mpick -t 'from =~~ "gmail"' | mflag -F | mrefile /data/mail/gmail/Sent mlist /data/mail/outbox | mpick -t 'from =~~ "gmail"' | mflag -F | mrefile /data/mail/gmail/Sent
# Find new messages in feeds # check for internet connection
d="$(mktemp -d)" ip route ls | grep -q '.'
mmkdir "$d"
date # check if the gpg-agent is running
sfeed_update pgrep gpg-agent > /dev/null
date
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"
# TODO -X dfprst or -X '' (no flags)
fi
done
date
rm -rf "$d"
# Sync email # Sync email
mbsync -a mbsync -a -q
# No further processing if there are no new mails # No further processing if there are no new mails
if ! mdirs /data/mail | mlist -N | grep -q .; then if ! mdirs /data/mail | mlist -N | grep -q .; then
exit exec sleep 1m
fi fi
# Incorporate new mails and store them in the temp sequence # Incorporate new mails and store them in the temp sequence
@ -51,11 +48,7 @@ minc $(mdirs /data/mail) > "$s"
for muted in $(cat ~/.mblaze/muted); do for muted in $(cat ~/.mblaze/muted); do
mpick -t '"references" =~~ "'"$muted"'"' < "$s" mpick -t '"references" =~~ "'"$muted"'"' < "$s"
done done
} | sort | uniq | mflag -Sf } | sort | uniq | mflag -Sf > /dev/null
# Clear muted sequence # Clear muted sequence
#mseq -f < ~/.mblaze/muted | mpick -t 'date < "'"$(date -I -d '1 month ago')"'"' | sponge ~/.mblaze/muted #mseq -f < ~/.mblaze/muted | mpick -t 'date < "'"$(date -I -d '1 month ago')"'"' | sponge ~/.mblaze/muted
# Show the remaining new mails
mseq -f < "$s" | mpick -t 'flagged || ! seen' | mseq -S
mscan

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 USER="$(whoami)"
export HOME=/home/"$USER" export HOME=/home/"$USER"
export DISPLAY=":0" export DISPLAY=":0"
. "$HOME"/.profile
set -e set -e