#!/bin/sh # # moving mail rules for notmuch # # the moving of mails is adapted from: # https://github.com/abcdw/rde/blob/master/rde/features/mail.scm alias nmsearch="$(command -v notmuch) search --exclude=false --output=files -- not folder:queued and" # move out untagged messages move_out() { for tag in inbox sent trash spam; do # if the $tag was removed, but the file still is in the folder, move it out for f in $(nmsearch path:"/.*\/${tag}\//" and not tag:"$tag" | grep "/${tag}/"); do new=$(echo "$f" | sed "s;/${tag}/;/all/;" | sed 's/,U=[0-9]*:/:/') [ -f "$f" ] && mv -v "$f" "$new" done done } # move in tagged messages move_in() { for tag in inbox sent trash spam; do # if the $tag was added, and the file is not on the folder, move it in for f in $(nmsearch not path:"/.*\/${tag}\//" and tag:"$tag"); do new=$(echo "$f" | sed "s;/[[:alnum:]]*/cur/;/${tag}/cur/;" | sed 's/,U=[0-9]*:/:/') [ -f "$f" ] && mv -v "$f" "$new" done done } case $1 in out) move_out ;; in) move_in ;; *) move_out move_in ;; esac