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
26 new_name=$(basename "${f}" | sed -e 's/,U=[0-9]*//')
28 target_path="${target_dir}${new_name}"
29 echo DEBUG0 $target_path
30 if [ ! "${target_path}" = "${f}" ]; then
31 echo "Moving ${f} to ${target_path}."
32 mv "${f}" "${target_path}"
33 # NOTE: if we encounter an error here of ${f} not being findable, run "notmuch reindex tag:${tag}" to fix
36 notmuch tag -"${tag}" tag:"${tag}"
39 # Remove all "deleted"-tagged files from maildirs.
40 notmuch search --output=files tag:deleted | while read f; do
45 # Sync changes back to server and update notmuch index.