Skip to content

Commit 1b69e85

Browse files
committed
fix(gmail): restore --exclude-labels SPAM,TRASH,DRAFT,SENT in buildGogWatchServeArgs (fixes #56635)
Add excludeLabels field to HooksGmailConfig, HooksGmailSchema, GmailHookRuntimeConfig, and GmailHookOverrides. Default to ['SPAM','TRASH','DRAFT','SENT']. Pass as --exclude-labels flag in buildGogWatchServeArgs() to prevent sent mail and draft saves from triggering webhook notifications. Co-Authored-By: JuniperTheDev <[email protected]>
1 parent dc64a86 commit 1b69e85

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

‎src/config/types.hooks.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ export type HooksGmailConfig = {
6060
/** Optional tailscale serve/funnel target (port, host:port, or full URL). */
6161
target?: string;
6262
};
63+
/** Labels to exclude from webhook notifications. Defaults to ['SPAM','TRASH','DRAFT','SENT']. */
64+
excludeLabels?: string[];
6365
/** Optional model override for Gmail hook processing (provider/model or alias). */
6466
model?: string;
6567
/** Optional thinking level override for Gmail hook processing. */

‎src/config/zod-schema.hooks.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export const HooksGmailSchema = z
121121
maxBytes: z.number().int().positive().optional(),
122122
renewEveryMinutes: z.number().int().positive().optional(),
123123
allowUnsafeExternalContent: z.boolean().optional(),
124+
excludeLabels: z.array(z.string()).optional(),
124125
serve: z
125126
.object({
126127
bind: z.string().optional(),

‎src/hooks/gmail.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const DEFAULT_GMAIL_SERVE_PORT = 8788;
1414
export const DEFAULT_GMAIL_SERVE_PATH = "/gmail-pubsub";
1515
export const DEFAULT_GMAIL_MAX_BYTES = 20_000;
1616
export const DEFAULT_GMAIL_RENEW_MINUTES = 12 * 60;
17+
export const DEFAULT_GMAIL_EXCLUDE_LABELS = ["SPAM", "TRASH", "DRAFT", "SENT"];
1718
export const DEFAULT_HOOKS_PATH = "/hooks";
1819

1920
export type GmailHookOverrides = {
@@ -27,6 +28,7 @@ export type GmailHookOverrides = {
2728
includeBody?: boolean;
2829
maxBytes?: number;
2930
renewEveryMinutes?: number;
31+
excludeLabels?: string[];
3032
serveBind?: string;
3133
servePort?: number;
3234
servePath?: string;
@@ -46,6 +48,7 @@ export type GmailHookRuntimeConfig = {
4648
includeBody: boolean;
4749
maxBytes: number;
4850
renewEveryMinutes: number;
51+
excludeLabels: string[];
4952
serve: {
5053
bind: string;
5154
port: number;
@@ -146,6 +149,8 @@ export function resolveGmailHookRuntimeConfig(
146149
? Math.floor(renewEveryMinutesRaw)
147150
: DEFAULT_GMAIL_RENEW_MINUTES;
148151

152+
const excludeLabels = overrides.excludeLabels ?? gmail?.excludeLabels ?? DEFAULT_GMAIL_EXCLUDE_LABELS;
153+
149154
const serveBind = overrides.serveBind ?? gmail?.serve?.bind ?? DEFAULT_GMAIL_SERVE_BIND;
150155
const servePortRaw = overrides.servePort ?? gmail?.serve?.port;
151156
const servePort =
@@ -191,6 +196,7 @@ export function resolveGmailHookRuntimeConfig(
191196
includeBody,
192197
maxBytes,
193198
renewEveryMinutes,
199+
excludeLabels,
194200
serve: {
195201
bind: serveBind,
196202
port: servePort,
@@ -241,6 +247,9 @@ export function buildGogWatchServeArgs(cfg: GmailHookRuntimeConfig): string[] {
241247
"--hook-token",
242248
cfg.hookToken,
243249
];
250+
if (cfg.excludeLabels.length > 0) {
251+
args.push("--exclude-labels", cfg.excludeLabels.join(","));
252+
}
244253
if (cfg.includeBody) {
245254
args.push("--include-body");
246255
}

0 commit comments

Comments
 (0)