#!/usr/bin/env sh

mbsync -a || exit

cd ~/.mail/personal/ || exit

printf "Filtering email.\n"

find Inbox/new/ -type f | while read -r FILENAME ; do
	if grep --quiet -i -e "^Delivered-To: *gemini@lists\.orbitalfox\.eu$" -e "^Delivered-To: *mailman-qutebrowser@zucker\.schokokeks\.org$" "$FILENAME"; then
		NAME=$(basename $FILENAME)
		mv "$FILENAME" "mailing-list/new/${NAME%,*,*}"
	fi
done
