From 438c25f4ff0dd682a311e00e17dcdbfd7e6e3481 Mon Sep 17 00:00:00 2001 From: David JULIEN Date: Fri, 4 Nov 2022 14:50:41 +0100 Subject: [PATCH 1/2] [mail] feat: add filters for univ --- .config/notmuch/default/hooks/post-new | 3 +++ .config/notmuch/default/hooks/pre-sync | 27 ++++++++++++++++++++++++++ .local/bin/statusbar/sb-mailbox | 6 +++--- 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100755 .config/notmuch/default/hooks/post-new create mode 100755 .config/notmuch/default/hooks/pre-sync diff --git a/.config/notmuch/default/hooks/post-new b/.config/notmuch/default/hooks/post-new new file mode 100755 index 0000000..5e1c658 --- /dev/null +++ b/.config/notmuch/default/hooks/post-new @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +notmuch tag --input $XDG_CONFIG_HOME/notmuch/tags/univ diff --git a/.config/notmuch/default/hooks/pre-sync b/.config/notmuch/default/hooks/pre-sync new file mode 100755 index 0000000..d62bc58 --- /dev/null +++ b/.config/notmuch/default/hooks/pre-sync @@ -0,0 +1,27 @@ +#!/usr/bin/env sh + +# Archive files that are NOT tagged Inbox +accounts="univ" + +# Update paths & tags +notmuch new --no-hooks + +filter() { + notmuch search --output=files --format=text0 $parameters and tag:new| xargs -0 --no-run-if-empty mv -t "$XDG_DATA_HOME/mail/$account/$tag/new/" + notmuch search --output=files --format=text0 $parameters and not tag:new| xargs -0 --no-run-if-empty mv -t "$XDG_DATA_HOME/mail/$account/$tag/cur/" +} + +for account in $accounts +do + tags_location="$XDG_CONFIG_HOME/notmuch/tags/$account" + tags="$(grep "+" "$tags_location" | sed -e 's/^.//' -e 's/ .*//')" + for tag in $tags + do + [ "univ" = $tag ] && continue + parameters="folder:$account/INBOX and tag:$tag" + filter + done +done + +# Update paths +notmuch new --no-hooks diff --git a/.local/bin/statusbar/sb-mailbox b/.local/bin/statusbar/sb-mailbox index c2d46be..9f0d45b 100755 --- a/.local/bin/statusbar/sb-mailbox +++ b/.local/bin/statusbar/sb-mailbox @@ -16,9 +16,9 @@ do new="$(find "${XDG_DATA_HOME:-$HOME/.local/share}"/mail/$acc -path */new/* -type f | grep -iv -e "trash" -e "drafts" | wc -l 2>/dev/null)" if [ $new -gt 0 ]; then box="" - [ -n "$(echo "$acc" | sed -n '/@univ/p')" ] && box="" - [ -n "$(echo "$acc" | sed -n '/@mailo/p')" ] && box="" - [ -n "$(echo "$acc" | sed -n '/@posteo/p')" ] && box="" + [ -n "$(echo "$acc" | sed -n '/univ/p')" ] && box="" + [ -n "$(echo "$acc" | sed -n '/mailo/p')" ] && box="" + [ -n "$(echo "$acc" | sed -n '/posteo/p')" ] && box="" unread="$unread/$box$new" fi done From e28c09a733c09b0bac58b9faec063a9d8c4876fb Mon Sep 17 00:00:00 2001 From: David JULIEN Date: Fri, 4 Nov 2022 16:29:48 +0100 Subject: [PATCH 2/2] [mail] fix: filters for univ --- .config/notmuch/default/hooks/post-new | 22 ++++++++++++++++++++- .config/notmuch/default/hooks/pre-sync | 27 -------------------------- 2 files changed, 21 insertions(+), 28 deletions(-) delete mode 100755 .config/notmuch/default/hooks/pre-sync diff --git a/.config/notmuch/default/hooks/post-new b/.config/notmuch/default/hooks/post-new index 5e1c658..0c8b092 100755 --- a/.config/notmuch/default/hooks/post-new +++ b/.config/notmuch/default/hooks/post-new @@ -1,3 +1,23 @@ #!/usr/bin/env sh -notmuch tag --input $XDG_CONFIG_HOME/notmuch/tags/univ +# The accounts to be cleaned +accounts="univ" + +filter() { + notmuch search --output=files --format=text0 $parameters and tag:unread| xargs -0 --no-run-if-empty mv -t "$XDG_DATA_HOME/mail/$account/$tag/new/" + notmuch search --output=files --format=text0 $parameters and not tag:unread| xargs -0 --no-run-if-empty mv -t "$XDG_DATA_HOME/mail/$account/$tag/cur/" +} + +for account in $accounts +do + notmuch tag --input $XDG_CONFIG_HOME/notmuch/tags/$account + tags_location="$XDG_CONFIG_HOME/notmuch/tags/$account" + tags="$(grep "+" "$tags_location" | sed -e 's/^.//' -e 's/ .*//')" + for tag in $tags + do + case $tag in + "+univ") ;; + *) parameters="folder:$account/INBOX and tag:$tag" && filter;; + esac + done +done diff --git a/.config/notmuch/default/hooks/pre-sync b/.config/notmuch/default/hooks/pre-sync deleted file mode 100755 index d62bc58..0000000 --- a/.config/notmuch/default/hooks/pre-sync +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env sh - -# Archive files that are NOT tagged Inbox -accounts="univ" - -# Update paths & tags -notmuch new --no-hooks - -filter() { - notmuch search --output=files --format=text0 $parameters and tag:new| xargs -0 --no-run-if-empty mv -t "$XDG_DATA_HOME/mail/$account/$tag/new/" - notmuch search --output=files --format=text0 $parameters and not tag:new| xargs -0 --no-run-if-empty mv -t "$XDG_DATA_HOME/mail/$account/$tag/cur/" -} - -for account in $accounts -do - tags_location="$XDG_CONFIG_HOME/notmuch/tags/$account" - tags="$(grep "+" "$tags_location" | sed -e 's/^.//' -e 's/ .*//')" - for tag in $tags - do - [ "univ" = $tag ] && continue - parameters="folder:$account/INBOX and tag:$tag" - filter - done -done - -# Update paths -notmuch new --no-hooks