Adds a GET-only Microsoft Graph source to bin/mail/sync (client-credentials, delta query). Wires it into the CLI (--source m365), the worker pool and the compose stack: - m365.go: M365Client (token cache, delta pagination, message normalization, attachment download) + m365Source adapter (per-mailbox folders + delta link) - sync.go: M365Credentials in SyncConfig; Committer interface so delta links only advance after a fully successful run (no skips on failure) - cli.go: --source m365 with M365_/MS_ env passthrough - Dockerfile: mail-build stage produces /mail-sync into the index image - docker-entrypoint: mail-sync loop (sync -> import -> index, default 10s) - compose.yaml: mail-sync service (index image, kb-var volume, secrets ro)
59 lines
2.0 KiB
Bash
Executable File
59 lines
2.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# bin/docker-entrypoint - run 2dph tools inside the container.
|
|
#
|
|
# API image (Zig CGO binaries):
|
|
# serve | search | watch
|
|
# Index image (Python write path, compose profile `index`):
|
|
# index | extract | audit | search (deprecated python wrapper)
|
|
# mail-sync [N] pull loop: sync -> import -> index every N s (default 10)
|
|
#
|
|
# Usage comment starts at line 2 (self-describing convention).
|
|
set -euo pipefail
|
|
|
|
CMD="${1:-shell}"
|
|
shift || true
|
|
|
|
if [ -x /usr/local/bin/brain-serve ]; then
|
|
case "$CMD" in
|
|
shell) exec bash ;;
|
|
serve) exec /usr/local/bin/brain-serve "$@" ;;
|
|
search) exec /usr/local/bin/brain-search "$@" ;;
|
|
watch) exec /usr/local/bin/brain-watch "$@" ;;
|
|
index)
|
|
echo "index is the Python sidecar: docker compose --profile index run --rm index" >&2
|
|
exit 2
|
|
;;
|
|
*) echo "unknown command: $CMD (api: serve|search|watch)" >&2; exit 2 ;;
|
|
esac
|
|
fi
|
|
|
|
case "$CMD" in
|
|
shell) exec bash ;;
|
|
search) exec "$KB_PY" /app/bin/kb/search "$@" ;;
|
|
index) exec "$KB_PY" /app/bin/kb/index --with-mail "$@" ;;
|
|
watch) exec /app/bin/watch "$@" ;;
|
|
serve) exec /app/bin/serve "$@" ;;
|
|
extract) exec "$KB_PY" /app/bin/facts/extract "$@" ;;
|
|
audit) exec "$KB_PY" /app/bin/facts/audit "$@" ;;
|
|
mail-sync)
|
|
# loop: pull mail (M365/OnlyOffice/Gmail) every N s, convert to md,
|
|
# rebuild the brain index. Index only when something new arrived.
|
|
interval="${1:-10}"
|
|
[ "$interval" -gt 0 ] 2>/dev/null || interval=10
|
|
: "${MAIL_SYNC_ENV:=/secret/m365.env}"
|
|
: "${MAIL_SYNC_SRC:=m365}"
|
|
: "${MAIL_SYNC_OUT:=/app/var/mail}"
|
|
while true; do
|
|
out="$("/app/bin/mail-sync" --source "$MAIL_SYNC_SRC" --env "$MAIL_SYNC_ENV" --out "$MAIL_SYNC_OUT" 2>&1)"
|
|
echo "$out"
|
|
new="$(printf '%s\n' "$out" | sed -n 's/.*new=\([0-9]*\).*/\1/p' | tail -1)"
|
|
if [ -n "$new" ] && [ "$new" -gt 0 ] 2>/dev/null; then
|
|
"$KB_PY" /app/bin/mail/import --from-raw "$MAIL_SYNC_OUT" 2>&1 | tail -1
|
|
"$KB_PY" /app/bin/kb/index --rebuild --with-mail 2>&1 | tail -1
|
|
fi
|
|
sleep "$interval"
|
|
done
|
|
;;
|
|
*) echo "unknown command: $CMD" >&2; exit 2 ;;
|
|
esac
|