Skip to content

Instantly share code, notes, and snippets.

@Excedrin
Excedrin / gmail-header-filter.gs
Last active July 16, 2026 00:01
Filter gmail messages using app script based on mail headers
// To deploy: paste into a new project at script.google.com, adjust the RULES, run
// installTrigger() once, and approve the Gmail OAuth prompt.
// ==== Debug ====
// Logs go to the Executions view (left sidebar in the Apps Script editor).
var DEBUG_LOG = false; // note: JS lowercase false, not False
// ==== Rules ====
// header -> value regex -> list of actions.
// Regexes are unanchored (use ^...$ to match the whole value) and