How it works
getUserLabelByName returns the Priority label if it exists; the `||` falls back to createLabel the first time, so the script is safe to run on a brand-new account.
The search query is scoped with `newer_than:1d -label:Priority` so each run only touches fresh, not-yet-labelled threads — that keeps it idempotent and cheap even on a frequent trigger.
For each thread it adds the label and stars every message. Stars are per-message in Gmail, so the inner loop covers long threads too.