From 2c18bcbb13809e4b89f0b6d01b11ca5d8765b95d Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Thu, 16 May 2019 23:06:44 +0200 Subject: [PATCH] Improve mail setup. --- buster/home_files/user_eeepc/.mbsyncrc | 2 ++ buster/home_files/user_eeepc/.notmuch-config | 4 +++ buster/home_files/user_eeepc/mail_sync.sh | 29 ++++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 buster/home_files/user_eeepc/.notmuch-config create mode 100755 buster/home_files/user_eeepc/mail_sync.sh diff --git a/buster/home_files/user_eeepc/.mbsyncrc b/buster/home_files/user_eeepc/.mbsyncrc index cab35a7..d3d3d88 100644 --- a/buster/home_files/user_eeepc/.mbsyncrc +++ b/buster/home_files/user_eeepc/.mbsyncrc @@ -24,3 +24,5 @@ Patterns * Create Both # Save the synchronization state files in the relevant directory SyncState * +# If a mail is marked T ("Trashed") or deleted, remove it for real everywhere +Expunge Both diff --git a/buster/home_files/user_eeepc/.notmuch-config b/buster/home_files/user_eeepc/.notmuch-config new file mode 100644 index 0000000..230bbe3 --- /dev/null +++ b/buster/home_files/user_eeepc/.notmuch-config @@ -0,0 +1,4 @@ +[database] +path=/home/plom/mail +[search] +exclude_tags=deleted;spam; diff --git a/buster/home_files/user_eeepc/mail_sync.sh b/buster/home_files/user_eeepc/mail_sync.sh new file mode 100755 index 0000000..d20690d --- /dev/null +++ b/buster/home_files/user_eeepc/mail_sync.sh @@ -0,0 +1,29 @@ +#!/bin/sh +set -e + +# Ensure all "dir:*"-tagged mails are in proper directories. +basedir="/home/plom/test_mbsync/maildir/" +for tag in $(notmuch search --output=tags '*'); do + if [ ! $(echo "${tag}" | cut -c-4) = "dir:" ]; then + continue + fi + target_dir="${basedir}"$(echo "${tag}" | cut -c5-)"/cur/" + for f in $(notmuch search --output=files tag:"${tag}"); do + new_name=$(basename "${f}" | sed -e 's/,U=[0-9]*//') + target_path="${target_dir}${new_name}" + if [ ! "${target_path}" = "${f}" ]; then + echo "Moving ${f} to ${target_path}." + mv "${f}" "${target_path}" + fi + done +done + +# Remove all "deleted"-tagged files from maildirs. +notmuch search --output=files tag:deleted | while read f; do + echo "Deleting ${f}" + rm "${f}" +done + +# Sync changes back to server and update notmuch index. +mbsync -a +notmuch new -- 2.30.2