home · contact · privacy
d20690d3606374f618f2d070c0ca14b730522274
[config] / buster / home_files / user_eeepc / mail_sync.sh
1 #!/bin/sh
2 set -e
3
4 # Ensure all "dir:*"-tagged mails are in proper directories.
5 basedir="/home/plom/test_mbsync/maildir/"
6 for tag in $(notmuch search --output=tags '*'); do
7     if [ ! $(echo "${tag}" | cut -c-4) = "dir:" ]; then
8         continue
9     fi
10     target_dir="${basedir}"$(echo "${tag}" | cut -c5-)"/cur/"
11     for f in $(notmuch search --output=files tag:"${tag}"); do
12          new_name=$(basename "${f}" | sed -e 's/,U=[0-9]*//')
13          target_path="${target_dir}${new_name}"
14          if [ ! "${target_path}" = "${f}" ]; then
15              echo "Moving ${f} to ${target_path}."
16              mv "${f}" "${target_path}"
17          fi
18     done
19 done
20
21 # Remove all "deleted"-tagged files from maildirs.
22 notmuch search --output=files tag:deleted | while read f; do
23     echo "Deleting ${f}"
24     rm "${f}"
25 done
26
27 # Sync changes back to server and update notmuch index.
28 mbsync -a
29 notmuch new