home · contact · privacy
Add w530 setup.
[config] / bullseye / home_files / user / mail_sync.sh
1 #!/bin/sh
2 set -e
3
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
8         continue
9     fi
10     target_dir="${basedir}"$(echo "${tag}" | cut -c5-)"/cur/"
11     if [ ! -d "${target_dir}" ]; then
12         echo "Directory ${target_dir} does not exist."
13         exit 1
14     fi
15 done
16
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
21         continue
22     fi
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          fi
31     done
32     notmuch tag -"${tag}" tag:"${tag}"
33 done
34
35 # Remove all "deleted"-tagged files from maildirs.
36 notmuch search --output=files tag:deleted | while read f; do
37     echo "Deleting ${f}"
38     rm "${f}"
39 done
40
41 # Sync changes back to server and update notmuch index.
42 mbsync -a
43 notmuch new