@@ -7,12 +7,12 @@ import { setProfile, getProfile } from '../config/config-manager';
77import { createProfileCommands } from '../utils/profile-commands' ;
88import { performOAuthFlow } from '../auth/oauth' ;
99import { GmailClient } from '../services/gmail/client' ;
10- import { printMessageList , printMessage , printSendResult , printDraftResult , printArchived , printMarked , printAttachmentList , printAttachmentDownloaded , printLabelList , printLabelCreated , printLabelDeleted , printLabelRenamed , printLabelModified , printBatchProgress , printBatchSummary , printBatchDryRun , raw } from '../utils/output' ;
10+ import { printMessageList , printMessage , printSendResult , printDraftResult , printArchived , printMarked , printAttachmentList , printAttachmentDownloaded , printLabelList , printLabelCreated , printLabelDeleted , printLabelRenamed , printLabelModified , printBatchProgress , printBatchSummary , printBatchDryRun , printFilterList , printFilter , printFilterCreated , printFilterDeleted , raw } from '../utils/output' ;
1111import { CliError , handleError } from '../utils/errors' ;
1212import { readStdin } from '../utils/stdin' ;
1313import { enforceWriteAccess } from '../utils/read-only' ;
1414import { addExamples } from '../utils/command-tree' ;
15- import type { GmailAttachment , GmailSendOptions } from '../types/gmail' ;
15+ import type { GmailAttachment , GmailSendOptions , GmailFilterCriteria , GmailFilterAction } from '../types/gmail' ;
1616
1717function addComposeOptions ( cmd : Command ) : Command {
1818 return cmd
@@ -172,6 +172,11 @@ function parseChunkOpts(options: Record<string, unknown>): { chunkSize: number;
172172 return { chunkSize, maxRetries, dryRun } ;
173173}
174174
175+ async function buildLabelNamesById ( client : GmailClient ) : Promise < Map < string , string > > {
176+ const labels = await client . listLabels ( ) ;
177+ return new Map ( labels . map ( ( l ) => [ l . id , l . name ] ) ) ;
178+ }
179+
175180export function registerGmailCommands ( program : Command ) : void {
176181 const gmail = program
177182 . command ( 'gmail' )
@@ -559,6 +564,60 @@ Combine with spaces (AND), OR, or - to negate.`,
559564 agentio gmail labels rename receipts auto/receipts` ,
560565 ) ;
561566
567+ const filters = gmail
568+ . command ( 'filters' )
569+ . description ( 'Manage Gmail filters' ) ;
570+
571+ addExamples (
572+ filters
573+ . command ( 'list' )
574+ . description ( 'List all filters' )
575+ . option ( '--profile <name>' , 'Profile name (optional if only one profile exists)' )
576+ . action ( async ( options ) => {
577+ try {
578+ const { client } = await getGmailClient ( options . profile ) ;
579+ const [ filterList , labelNamesById ] = await Promise . all ( [
580+ client . listFilters ( ) ,
581+ buildLabelNamesById ( client ) ,
582+ ] ) ;
583+ printFilterList ( filterList , labelNamesById ) ;
584+ } catch ( error ) {
585+ handleError ( error ) ;
586+ }
587+ } ) ,
588+ `Examples:
589+
590+ # list every filter
591+ agentio gmail filters list
592+
593+ # list filters for a specific profile
594+ agentio gmail filters list --profile alice@example.com` ,
595+ ) ;
596+
597+ addExamples (
598+ filters
599+ . command ( 'get' )
600+ . argument ( '<id>' , 'Filter ID' )
601+ . description ( 'Get a filter' )
602+ . option ( '--profile <name>' , 'Profile name (optional if only one profile exists)' )
603+ . action ( async ( id : string , options ) => {
604+ try {
605+ const { client } = await getGmailClient ( options . profile ) ;
606+ const [ filter , labelNamesById ] = await Promise . all ( [
607+ client . getFilter ( id ) ,
608+ buildLabelNamesById ( client ) ,
609+ ] ) ;
610+ printFilter ( filter , labelNamesById ) ;
611+ } catch ( error ) {
612+ handleError ( error ) ;
613+ }
614+ } ) ,
615+ `Examples:
616+
617+ # show full filter details
618+ agentio gmail filters get ANe1BmgABCDEF1234567890` ,
619+ ) ;
620+
562621 addExamples (
563622 gmail
564623 . command ( 'label' )
0 commit comments