@@ -5,9 +5,18 @@ export default {
55 ...common ,
66 key : "microsoft_outlook-new-email" ,
77 name : "New Email Event (Instant)" ,
8- description : "Emit new event when an email received" ,
9- version : "0.0.9 " ,
8+ description : "Emit new event when an email is received in specified folders. " ,
9+ version : "0.0.10 " ,
1010 type : "source" ,
11+ props : {
12+ ...common . props ,
13+ folderIds : {
14+ type : "string[]" ,
15+ label : "Folder IDs to Monitor" ,
16+ description : "Specify the folder IDs or names in Outlook that you want to monitor for new emails. Leave empty to monitor all folders." ,
17+ optional : true ,
18+ } ,
19+ } ,
1120 hooks : {
1221 ...common . hooks ,
1322 async activate ( ) {
@@ -23,17 +32,28 @@ export default {
2332 methods : {
2433 ...common . methods ,
2534 async getSampleEvents ( { pageSize } ) {
26- return this . microsoftOutlook . listMessages ( {
27- params : {
28- $top : pageSize ,
29- $orderby : "createdDateTime desc" ,
30- } ,
31- } ) ;
35+ const folders = this . folderIds ?. length
36+ ? this . folderIds . map ( ( id ) => `/me/mailFolders/${ id } /messages` )
37+ : [ "/me/messages" ] ;
38+
39+ const results = [ ] ;
40+ for ( const folder of folders ) {
41+ const messages = await this . microsoftOutlook . listMessages ( {
42+ resource : folder ,
43+ params : {
44+ $top : pageSize ,
45+ $orderby : "createdDateTime desc" ,
46+ } ,
47+ } ) ;
48+ results . push ( ...messages ) ;
49+ }
50+ return results ;
3251 } ,
3352 emitEvent ( item ) {
34- this . $emit ( {
35- email : item ,
36- } , this . generateMeta ( item ) ) ;
53+ this . $emit (
54+ { email : item } ,
55+ this . generateMeta ( item )
56+ ) ;
3757 } ,
3858 generateMeta ( item ) {
3959 return {
@@ -44,15 +64,22 @@ export default {
4464 } ,
4565 } ,
4666 async run ( event ) {
47- await this . run ( {
48- event,
49- emitFn : async ( { resourceId } = { } ) => {
50- const item = await this . microsoftOutlook . getMessage ( {
51- messageId : resourceId ,
52- } ) ;
53- this . emitEvent ( item ) ;
54- } ,
55- } ) ;
67+ const folders = this . folderIds ?. length
68+ ? this . folderIds . map ( ( id ) => `/me/mailFolders/${ id } /messages` )
69+ : [ "/me/messages" ] ;
70+
71+ for ( const folder of folders ) {
72+ await this . run ( {
73+ event,
74+ emitFn : async ( { resourceId } = { } ) => {
75+ const item = await this . microsoftOutlook . getMessage ( {
76+ resource : folder ,
77+ messageId : resourceId ,
78+ } ) ;
79+ this . emitEvent ( item ) ;
80+ } ,
81+ } ) ;
82+ }
5683 } ,
5784 sampleEmit,
5885} ;
0 commit comments