From 1f4788fb0323732a0622b6ef1ec3abfc4c52640d Mon Sep 17 00:00:00 2001 From: Felix Van der Jeugt Date: Tue, 16 Mar 2021 12:10:07 +0100 Subject: [PATCH] split mfetch script in mail and feed sync services --- local/bin/mfetch => services/mailsync/run | 35 +++++++++-------------- services/sfeed/run | 25 ++++++++++++++++ services/vdirsyncer/run | 1 - 3 files changed, 39 insertions(+), 22 deletions(-) rename local/bin/mfetch => services/mailsync/run (78%) create mode 100755 services/sfeed/run diff --git a/local/bin/mfetch b/services/mailsync/run similarity index 78% rename from local/bin/mfetch rename to services/mailsync/run index fde04e4..afd944f 100755 --- a/local/bin/mfetch +++ b/services/mailsync/run @@ -1,30 +1,27 @@ #!/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 -# Find new messages in feeds -d="$(mktemp -d)" -mmkdir "$d" -date -sfeed_update -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" +# 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 +mbsync -a -q # No further processing if there are no new mails if ! mdirs /data/mail | mlist -N | grep -q .; then - exit + exec sleep 1m fi # 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 mpick -t '"references" =~~ "'"$muted"'"' < "$s" done -} | sort | uniq | mflag -Sf +} | 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 - -# Show the remaining new mails -mseq -f < "$s" | mpick -t 'flagged || ! seen' | mseq -S -mscan diff --git a/services/sfeed/run b/services/sfeed/run new file mode 100755 index 0000000..1bae06f --- /dev/null +++ b/services/sfeed/run @@ -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 diff --git a/services/vdirsyncer/run b/services/vdirsyncer/run index a706016..a25cd1e 100755 --- a/services/vdirsyncer/run +++ b/services/vdirsyncer/run @@ -2,7 +2,6 @@ export USER="$(whoami)" export HOME=/home/"$USER" export DISPLAY=":0" -. "$HOME"/.profile set -e