4 basedir="/home/plom/mail/maildir/"
5 # Ensure directories exist for all "dir:*" tags.
6 for tag in $(notmuch search --output=tags '*'); do
7 if [ ! $(echo "${tag}" | cut -c-4) = "dir:" ]; then
10 target_dir="${basedir}"$(echo "${tag}" | cut -c5-)"/cur/"
11 if [ ! -d "${target_dir}" ]; then
12 echo "Directory ${target_dir} does not exist."
17 # Ensure all "dir:*"-tagged mails are in proper directories,
18 # remove all "dir:*" tags.
19 for tag in $(notmuch search --output=tags '*'); do
20 if [ ! $(echo "${tag}" | cut -c-4) = "dir:" ]; then
23 target_dir="${basedir}"$(echo "${tag}" | cut -c5-)"/cur/"
24 for f in $(notmuch search --output=files tag:"${tag}"); do
25 new_name=$(basename "${f}" | sed -e 's/,U=[0-9]*//')
26 target_path="${target_dir}${new_name}"
27 if [ ! "${target_path}" = "${f}" ]; then
28 echo "Moving ${f} to ${target_path}."
29 mv "${f}" "${target_path}"
30 # NOTE: if we encounter an error here of ${f} not being findable, run "notmuch reindex tag:${tag}" to fix
33 notmuch tag -"${tag}" tag:"${tag}"
36 # Remove all "deleted"-tagged files from maildirs.
37 notmuch search --output=files tag:deleted | while read f; do
42 # Sync changes back to server and update notmuch index.