#!/bin/bash

echo "=== Syncing all mailboxes ==="

# 1. Sync emails bidirectionally (includes deletions)
mbsync -a

# 2. Index each account separately (runs post-new hook)
for account in phil spam; do
  echo "Indexing $account..."
  NOTMUCH_CONFIG=~/Mail/$account/.notmuch-config notmuch new
done

# 3. Optional: Sync back any tag changes to IMAP flags
for account in phil spam; do
  NOTMUCH_CONFIG=~/Mail/$account/.notmuch-config notmuch tag --batch < /dev/null
done

echo "=== Sync complete ==="
