commit ded648933c595a29f39ac93240ce64df1b4762a7
parent cd654f31118938fd6d2723639c0978c691b7d57f
Author: Anton Konyahin <me@konyahin.xyz>
Date: Sun, 9 Apr 2023 19:36:10 +0300
scripts: mail filtering
Diffstat:
5 files changed, 100 insertions(+), 4 deletions(-)
diff --git a/LICENSE b/LICENSE
@@ -0,0 +1,21 @@
+MIT/X Consortium License
+
+© 2023 Anton Konyahin <me@konyahin.xyz>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
diff --git a/isync/.config/dot-mbsyncrc b/isync/.config/dot-mbsyncrc
@@ -20,7 +20,6 @@ Subfolders Verbatim
Channel epik
Far :epik-remote:
Near :epik-local:
-Create Both
-Expunge Both
+Sync Pull
Patterns *
SyncState *
diff --git a/mutt/.config/mutt/muttrc b/mutt/.config/mutt/muttrc
@@ -5,6 +5,7 @@ color header brightgreen black ^date
# New mail is boldened:
color index brightyellow black "~N"
+color index brightyellow black "~O"
# use a for alias adding
set alias_file = ~/.config/mutt/aliases
@@ -68,4 +69,4 @@ set record = "+Sent"
set trash = "+Trash"
set postponed = "+Drafts"
-mailboxes =INBOX =Sent =Trash =Drafts =Checks =spam =Archive =stratoplan
+mailboxes =INBOX =Sent =Trash =Drafts =Checks =spam =ports-obsd =misc-obsd =announce-obsd =dev-suckless =lists
diff --git a/scripts/dot-bin/mfilter b/scripts/dot-bin/mfilter
@@ -0,0 +1,75 @@
+#!/usr/bin/env sh
+
+# MIT/X Consortium License
+# © 2023 Anton Konyahin <me@konyahin.xyz>
+#
+# Depends on mblaze: https://git.vuxu.org/mblaze/
+
+set -eu
+
+help () {
+ cat <<EOF
+$0 [-hcp] [maildir]
+ -h show this help
+ -c filter old mails (by default we look at new)
+ -p print all rules without filtering
+You should specify maildir with -c and -p options. You can use only one flag at time.
+EOF
+ exit 0
+}
+
+if [ -z "${1:-}" ]; then
+ help
+fi
+
+case "$1" in
+ "-h" )
+ help
+ ;;
+ "-p" )
+ PRINT_ONLY=yes
+ MAIL_DIR=${2:-}
+ ;;
+ "-c" )
+ MAIL_DIR=$2
+ MLIST_FILTER=-C
+ MAIL_DEST=cur
+ ;;
+ * )
+ MAIL_DIR=$1
+ MLIST_FILTER=-N
+ MAIL_DEST=new
+ ;;
+esac
+
+if [ -z "$MAIL_DIR" ]; then
+ echo "You should specify maildir path"
+ exit 1
+fi
+
+FILTER_FILE="$MAIL_DIR/.filter"
+if [ ! -e "$FILTER_FILE" ]; then
+ echo "You should have .filter file in maildir"
+ exit 1
+fi
+
+move () {
+ if [ -n "${PRINT_ONLY:-}" ]; then
+ printf "%s\t-> %s\n" "$1" "$2"
+ else
+ mlist "$MLIST_FILTER" "$MAIL_DIR/INBOX" |
+ mpick -t "\"To\" =~~ \"$1\" ||
+ \"Cc\" =~~ \"$1\" ||
+ \"From\" =~~ \"$1\"" |
+ xargs -r -n1 -I {} mrefile -v {} "$MAIL_DIR/$2" |
+ xargs -r -n1 -I {} mv {} "$MAIL_DIR/$2/$MAIL_DEST"
+ fi
+}
+
+# if file doesn't end with new line, we need second check
+while read -r line || [ -n "$line" ]; do
+ if [ -n "$line" ]; then
+ # shellcheck disable=SC2086
+ move $line
+ fi
+done < "$FILTER_FILE"
diff --git a/sh/.config/ksh/kshrc b/sh/.config/ksh/kshrc
@@ -27,7 +27,7 @@ alias e=$EDITOR
alias v='bat'
alias nb='newsboat && bookmark count'
alias m='mutt'
-alias isync='mbsync -c ~/.config/.mbsyncrc -a'
+alias isync='mbsync -c ~/.config/.mbsyncrc -a && mfilter ~/data/mail/fastmail'
alias scratch='$EDITOR ~/data/notes/scratch.md'