commit 7cc41f93f74c38ddd53ed08194455697fa0c1c66
parent 82becde65bcd84969686fea720bde1ebe8951166
Author: Alex Balgavy <alex@balgavy.eu>
Date: Mon, 2 Aug 2021 15:19:39 +0200
Improve interplay between maildir and notmuch tags
Diffstat:
5 files changed, 70 insertions(+), 20 deletions(-)
diff --git a/emacs/config.org b/emacs/config.org
@@ -652,6 +652,11 @@ Set tags:
("d" notmuch-delete-tags "Delete")))
#+end_src
+Run notmuch-hook script on hello refresh, to move messages to folders according to their tags:
+
+#+begin_src emacs-lisp
+ (add-hook 'notmuch-hello-refresh-hook (lambda () (start-process "notmuch-hook" nil "notmuch-hook" "tags2folders")))
+#+end_src
* MPC
Set the windows I want to show:
diff --git a/mutt/personal b/mutt/personal
@@ -51,7 +51,7 @@ macro index o "<shell-escape>mbsync -c ~/.config/mbsync/mbsyncrc $my_personal_em
# Delete
macro index,pager d "\
<delete-message>\
-<modify-labels-then-hide>-inbox -archive -drafts -spam +trash -sent -unread<enter>"
+<modify-labels-then-hide>-inbox -archive -draft -spam +trash -sent -unread<enter>"
# Actually delete
bind index,pager D purge-message
@@ -70,10 +70,10 @@ macro index,pager gt "<change-vfolder>Trash (P)<enter>" "go to Trash"
macro index,pager gs "<change-vfolder>Sent (P)<enter>" "go to Sent"
# Moving emails
-macro index,pager MI "<modify-labels>+inbox -archive -drafts -spam -trash -sent -unread<enter><save-message>=Inbox<enter>" "move mail to Inbox"
-macro index,pager MA "<modify-labels>-inbox +archive -drafts -spam -trash -sent -unread<enter><save-message>=Archive<enter>" "move mail to Archive"
-macro index,pager a "<modify-labels>-inbox +archive -drafts -spam -trash -sent -unread<enter><save-message>=Archive<enter>" "move mail to Archive"
-macro index,pager MD "<modify-labels>-inbox -archive +drafts -spam -trash -sent -unread<enter><save-message>=Drafts<enter>" "move mail to Drafts"
-macro index,pager MJ "<modify-labels>-inbox -archive -drafts +spam -trash -sent -unread<enter><save-message>=Spam<enter>" "move mail to Spam"
-macro index,pager MT "<modify-labels>-inbox -archive -drafts -spam +trash -sent -unread<enter><save-message>=Trash<enter>" "move mail to Trash"
-macro index,pager MS "<modify-labels>-inbox -archive -drafts -spam -trash +sent -unread<enter><save-message>=Sent<enter>" "move mail to Sent"
+macro index,pager MI "<modify-labels>+inbox -archive -draft -spam -trash -sent -unread<enter><save-message>=Inbox<enter>" "move mail to Inbox"
+macro index,pager MA "<modify-labels>-inbox +archive -draft -spam -trash -sent -unread<enter><save-message>=Archive<enter>" "move mail to Archive"
+macro index,pager a "<modify-labels>-inbox +archive -draft -spam -trash -sent -unread<enter><save-message>=Archive<enter>" "move mail to Archive"
+macro index,pager MD "<modify-labels>-inbox -archive +draft -spam -trash -sent -unread<enter><save-message>=Drafts<enter>" "move mail to Drafts"
+macro index,pager MJ "<modify-labels>-inbox -archive -draft +spam -trash -sent -unread<enter><save-message>=Spam<enter>" "move mail to Spam"
+macro index,pager MT "<modify-labels>-inbox -archive -draft -spam +trash -sent -unread<enter><save-message>=Trash<enter>" "move mail to Trash"
+macro index,pager MS "<modify-labels>-inbox -archive -draft -spam -trash +sent -unread<enter><save-message>=Sent<enter>" "move mail to Sent"
diff --git a/mutt/school b/mutt/school
@@ -48,7 +48,7 @@ macro index o "<shell-escape>mbsync -c ~/.config/mbsync/mbsyncrc $my_school_emai
# Delete
macro index,pager d "\
<delete-message>\
-<modify-labels-then-hide>-inbox -archive -drafts -spam +trash -sent -unread<enter>"
+<modify-labels-then-hide>-inbox -archive -draft -spam +trash -sent -unread<enter>"
# Actually delete
bind index,pager D purge-message
@@ -67,11 +67,11 @@ macro index,pager gt "<change-vfolder>Trash (S)<enter>" "go to Trash"
macro index,pager gs "<change-vfolder>Sent (S)<enter>" "go to Sent"
# Moving emails
-macro index,pager MI "<modify-labels>+inbox -archive -drafts -spam -trash -sent -unread<enter><save-message>=Inbox<enter>" "move mail to Inbox"
-macro index,pager MA "<modify-labels>-inbox +archive -drafts -spam -trash -sent -unread<enter><save-message>=Archive<enter>" "move mail to Archive"
-macro index,pager a "<modify-labels>-inbox +archive -drafts -spam -trash -sent -unread<enter><save-message>=Archive<enter>" "move mail to Archive"
-macro index,pager MD "<modify-labels>-inbox -archive +drafts -spam -trash -sent -unread<enter><save-message>=Drafts<enter>" "move mail to Drafts"
-macro index,pager MJ "<modify-labels>-inbox -archive -drafts +spam -trash -sent -unread<enter><save-message>=Junk Email<enter>" "move mail to Junk Email"
-macro index,pager MT "<modify-labels>-inbox -archive -drafts -spam +trash -sent -unread<enter><save-message>=Deleted Items<enter>" "move mail to Deleted Items"
-macro index,pager MS "<modify-labels>-inbox -archive -drafts -spam -trash +sent -unread<enter><save-message>=Sent Items<enter>" "move mail to Sent Items"
+macro index,pager MI "<modify-labels>+inbox -archive -draft -spam -trash -sent -unread<enter><save-message>=Inbox<enter>" "move mail to Inbox"
+macro index,pager MA "<modify-labels>-inbox +archive -draft -spam -trash -sent -unread<enter><save-message>=Archive<enter>" "move mail to Archive"
+macro index,pager a "<modify-labels>-inbox +archive -draft -spam -trash -sent -unread<enter><save-message>=Archive<enter>" "move mail to Archive"
+macro index,pager MD "<modify-labels>-inbox -archive +draft -spam -trash -sent -unread<enter><save-message>=Drafts<enter>" "move mail to Drafts"
+macro index,pager MJ "<modify-labels>-inbox -archive -draft +spam -trash -sent -unread<enter><save-message>=Junk Email<enter>" "move mail to Junk Email"
+macro index,pager MT "<modify-labels>-inbox -archive -draft -spam +trash -sent -unread<enter><save-message>=Deleted Items<enter>" "move mail to Deleted Items"
+macro index,pager MS "<modify-labels>-inbox -archive -draft -spam -trash +sent -unread<enter><save-message>=Sent Items<enter>" "move mail to Sent Items"
diff --git a/scripts/notmuch-hook b/scripts/notmuch-hook
@@ -1,5 +1,50 @@
#!/bin/sh
notmuch new
-notmuch tag --remove-all +sent -- from:alex@balgavy.eu or from:a.balgavy@gmail.com or from:a.balgavy@student.vu.nl
-notmuch tag --remove-all +drafts -- folder:/Drafts/
-notmuch tag -inbox +spam -- folder:/Spam/ or folder:/Junk/
+
+# Change tags according to folders
+folders2tags() {
+ # Retag according to folders
+
+ notmuch tag --remove-all --batch <<EOF
+# This will always be read mail
++archive -- folder:/Archive/
++draft -- folder:/Drafts/
++sent -- from:alex@balgavy.eu or from:a.balgavy@gmail.com or from:a.balgavy@student.vu.nl
++trash -- folder:/Trash/ or folder:/Deleted/
++tickets -- folder:/Tickets/
+
++spam +unread -- (folder:/Spam/ or folder:/Junk/) and tag:unread
++spam -- (folder:/Spam/ or folder:/Junk/) and not tag:unread
+
++inbox +unread -- folder:/Inbox/ and tag:unread
++inbox -- folder:/Inbox/ and not tag:unread
+EOF
+
+}
+safeMove() { s=${1##*/}; s=${s%%,*}; mv -f "$1" "$2"/"$s"; }
+alias nms="notmuch search --exclude=false --output=files"
+
+# Move to folders according to tags
+tags2folders() {
+ # Move a message file while removing its UID-part
+ maildir="$HOME/.local/share/mail"
+
+ for i in $(nms folder:/alex@balgavy.eu/ and tag:archive and not folder:/Archive/); do safeMove "$i" "$maildir/alex@balgavy.eu/Archive/cur"; done
+ for i in $(nms folder:/alex@balgavy.eu/ and tag:draft and not folder:/Drafts/); do safeMove "$i" "$maildir/alex@balgavy.eu/Drafts/cur"; done
+ for i in $(nms folder:/alex@balgavy.eu/ and tag:inbox and not folder:/Inbox/); do safeMove "$i" "$maildir/alex@balgavy.eu/Inbox/cur"; done
+ for i in $(nms folder:/alex@balgavy.eu/ and tag:spam and not folder:/Spam/); do safeMove "$i" "$maildir/alex@balgavy.eu/Spam/cur"; done
+ for i in $(nms folder:/alex@balgavy.eu/ and tag:tickets and not folder:/Tickets/); do safeMove "$i" "$maildir/alex@balgavy.eu/Tickets/cur"; done
+ for i in $(nms folder:/alex@balgavy.eu/ and tag:trash and not folder:/Trash/); do safeMove "$i" "$maildir/alex@balgavy.eu/Trash/cur"; done
+ for i in $(nms folder:/alex@balgavy.eu/ and tag:sent and not folder:/Sent/); do safeMove "$i" "$maildir/alex@balgavy.eu/Sent/cur"; done
+
+ for i in $(nms folder:/a.balgavy@student.vu.nl/ and tag:archive and not folder:/Archive/); do safeMove "$i" "$maildir/a.balgavy@student.vu.nl/Archive/cur"; done
+ for i in $(nms folder:/a.balgavy@student.vu.nl/ and tag:trash and not folder:/Deleted/); do safeMove "$i" "$maildir/a.balgavy@student.vu.nl/Deleted Items/cur"; done
+ for i in $(nms folder:/a.balgavy@student.vu.nl/ and tag:draft and not folder:/Drafts/); do safeMove "$i" "$maildir/a.balgavy@student.vu.nl/Drafts/cur"; done
+ for i in $(nms folder:/a.balgavy@student.vu.nl/ and tag:spam and not folder:/Junk/); do safeMove "$i" "$maildir/a.balgavy@student.vu.nl/Junk Email/cur"; done
+ for i in $(nms folder:/a.balgavy@student.vu.nl/ and tag:sent and not folder:/Sent/); do safeMove "$i" "$maildir/a.balgavy@student.vu.nl/Sent Items/cur"; done
+}
+
+# When using notmuch, we set tags, so specify to move messages to folders based on tags
+if [ $# -gt 0 ] && [ "$1" = "tags2folders" ]; then tags2folders
+# Otherwise, in mutt or while retrieving new messages, want to set notmuch tags from folders
+else folders2tags; fi
diff --git a/vim/vimrc b/vim/vimrc
@@ -25,7 +25,7 @@ Plug 'rstacruz/sparkup'
" Endwise - smart do-end, if-fi, if-end, case-esac, etc.
Plug 'tpope/vim-endwise'
-" Sandwich - super useful plugin for surrounding stuff with quotes/brackets/tags
+" Surround - super useful plugin for surrounding stuff with quotes/brackets/tags
Plug 'tpope/vim-surround'
" Eunuch - shell commands but in vim