File: //usr/local/sbin/maildir_gunzip_in_tree.sh
#!/usr/bin/env bash
set -euo pipefail
ROOT="${1:-}"
if [[ -z "$ROOT" || ! -d "$ROOT" ]]; then
echo "Usage: $0 /path/to/maildir_root"; exit 1
fi
echo "[*] Scan & decompress if gzip (magic 1f8b)..."
# note: nama file Maildir harus tetap — hanya kontennya yang diganti.
while IFS= read -r -d '' f; do
# Baca 2 byte pertama
magic=$(head -c2 "$f" | od -An -tx1 | tr -d ' \n')
if [[ "$magic" == "1f8b" ]]; then
tmp="$f.__tmp__"
if gzip -cd -- "$f" > "$tmp" 2>/dev/null; then
mv -f -- "$tmp" "$f"
echo "unzipped: $f"
else
rm -f -- "$tmp" 2>/dev/null || true
echo "WARN: gagal unzip (biarkan apa adanya): $f"
fi
fi
done < <(find "$ROOT" -type f -print0)
echo "[*] Done."