@@ -9,6 +9,7 @@ interface CliOptions {
99 attachmentSize : 'small' | 'large' ;
1010 format : FileFormat ;
1111 testEmail ?: string ;
12+ isPlaintext : boolean ;
1213}
1314
1415async function getCliOptions ( fileManager : TestFileManager ) : Promise < CliOptions > {
@@ -51,42 +52,48 @@ async function getCliOptions(fileManager: TestFileManager): Promise<CliOptions>
5152 message : 'Recipient email address:' ,
5253 default : process . env . TEST_EMAIL || '' ,
5354 validate : ( input : string ) => input . includes ( '@' ) || 'Please enter a valid email address'
55+ } ,
56+ {
57+ type : 'confirm' ,
58+ name : 'isPlaintext' ,
59+ message : 'Send as plaintext (no HTML rendering)?' ,
60+ default : false
5461 }
5562 ] ) ;
5663
5764 return answers as CliOptions ;
5865}
5966
6067async function runExample ( examples : SendAttachmentsExamples , fileManager : TestFileManager , options : CliOptions ) : Promise < void > {
61- const { format, testEmail, attachmentSize } = options ;
68+ const { format, testEmail, attachmentSize, isPlaintext } = options ;
6269
6370 if ( ! testEmail ) {
6471 console . log ( chalk . yellow ( '⚠️ No email provided. Skipping send.' ) ) ;
6572 return ;
6673 }
6774
6875 try {
69- console . log ( chalk . blue ( `\n📤 Running ${ format } attachment example (${ attachmentSize } files)...\n` ) ) ;
76+ console . log ( chalk . blue ( `\n📤 Running ${ format } attachment example (${ attachmentSize } files)${ isPlaintext ? ' in plaintext mode' : '' } ...\n` ) ) ;
7077
7178 let result : NylasResponse < Message > ;
7279 const isLarge = attachmentSize === 'large' ;
7380
7481 // Route to the appropriate example based on format
7582 switch ( format ) {
7683 case 'file' :
77- result = await examples . sendFilePathAttachments ( fileManager , testEmail , isLarge ) ;
84+ result = await examples . sendFilePathAttachments ( fileManager , testEmail , isLarge , isPlaintext ) ;
7885 break ;
7986 case 'stream' :
80- result = await examples . sendStreamAttachments ( fileManager , testEmail , isLarge ) ;
87+ result = await examples . sendStreamAttachments ( fileManager , testEmail , isLarge , isPlaintext ) ;
8188 break ;
8289 case 'buffer' :
83- result = await examples . sendBufferAttachments ( fileManager , testEmail , isLarge ) ;
90+ result = await examples . sendBufferAttachments ( fileManager , testEmail , isLarge , isPlaintext ) ;
8491 break ;
8592 case 'string' :
86- result = await examples . sendStringAttachments ( fileManager , testEmail , isLarge ) ;
93+ result = await examples . sendStringAttachments ( fileManager , testEmail , isLarge , isPlaintext ) ;
8794 break ;
8895 default :
89- result = await examples . sendAttachmentsByFormat ( fileManager , format , testEmail , attachmentSize ) ;
96+ result = await examples . sendAttachmentsByFormat ( fileManager , format , testEmail , attachmentSize , isPlaintext ) ;
9097 }
9198
9299 console . log ( chalk . green . bold ( '\n✅ Message sent successfully!' ) ) ;
@@ -103,11 +110,12 @@ async function runExample(examples: SendAttachmentsExamples, fileManager: TestFi
103110 }
104111}
105112
106- async function runBatchMode ( examples : SendAttachmentsExamples , fileManager : TestFileManager , size : 'small' | 'large' , format : FileFormat , email ?: string ) : Promise < void > {
113+ async function runBatchMode ( examples : SendAttachmentsExamples , fileManager : TestFileManager , size : 'small' | 'large' , format : FileFormat , email ?: string , isPlaintext : boolean = false ) : Promise < void > {
107114 const options : CliOptions = {
108115 attachmentSize : size ,
109116 format,
110- testEmail : email
117+ testEmail : email ,
118+ isPlaintext
111119 } ;
112120
113121 console . log ( chalk . blue . bold ( '\n🚀 Nylas Send Attachments (Batch Mode)\n' ) ) ;
@@ -137,17 +145,19 @@ export async function startCli(examples: SendAttachmentsExamples, fileManager: T
137145 . description ( 'Send small attachments' )
138146 . option ( '-f, --format <format>' , 'format (file|stream|buffer|string)' , 'file' )
139147 . option ( '-e, --email <email>' , 'recipient email' )
148+ . option ( '--plaintext' , 'send as plaintext' , false )
140149 . action ( async ( options ) => {
141- await runBatchMode ( examples , fileManager , 'small' , options . format as FileFormat , options . email || testEmail ) ;
150+ await runBatchMode ( examples , fileManager , 'small' , options . format as FileFormat , options . email || testEmail , Boolean ( options . plaintext ) ) ;
142151 } ) ;
143152
144153 program
145154 . command ( 'large' )
146155 . description ( 'Send large attachment' )
147156 . option ( '-f, --format <format>' , 'format (file|stream|buffer|string)' , 'file' )
148157 . option ( '-e, --email <email>' , 'recipient email' )
158+ . option ( '--plaintext' , 'send as plaintext' , false )
149159 . action ( async ( options ) => {
150- await runBatchMode ( examples , fileManager , 'large' , options . format as FileFormat , options . email || testEmail ) ;
160+ await runBatchMode ( examples , fileManager , 'large' , options . format as FileFormat , options . email || testEmail , Boolean ( options . plaintext ) ) ;
151161 } ) ;
152162
153163 program
0 commit comments