@@ -24,6 +24,7 @@ import {Rule} from './Rule';
2424export class Processor {
2525
2626 private static processThread ( session_data : SessionData , thread_data : ThreadData ) {
27+ let thread_matched_a_rule = false ;
2728 for ( const message_data of thread_data . message_data_list ) {
2829 // Apply each rule until matching a rule with a DONE action or matching a rule with
2930 // FINISH_STAGE and then exhausting all other rules in that stage.
@@ -37,8 +38,10 @@ export class Processor {
3738 break ;
3839 }
3940 if ( rule . condition . match ( message_data ) ) {
41+ thread_matched_a_rule = true ;
4042 console . log ( `rule ${ rule } matches message ${ message_data } , apply action ${ rule . thread_action } ` ) ;
4143 thread_data . thread_action . mergeFrom ( rule . thread_action ) ;
44+ console . log ( `Thread action after merging: ${ thread_data . thread_action } ` ) ;
4245 let endThread = false ;
4346 switch ( rule . thread_action . action_after_match ) {
4447 case ActionAfterMatchType . DONE :
@@ -69,7 +72,13 @@ export class Processor {
6972 // }
7073
7174 }
72- thread_data . validateActions ( ) ;
75+ if ( ! thread_matched_a_rule ) {
76+ const last_message = thread_data . getLatestMessage ( ) ;
77+ const from = last_message . getFrom ( ) ;
78+ const to = last_message . getTo ( ) ;
79+ const first_message_subject = thread_data . getFirstMessageSubject ( ) ;
80+ throw `Thread "${ first_message_subject } " from ${ from } to ${ to } has no action, does it match any rule?` ;
81+ }
7382 }
7483
7584 public static processAllUnprocessedThreads ( ) {
@@ -171,19 +180,23 @@ export class Processor {
171180 expect ( thread_data . thread_action . move_to ) . toBe ( InboxActionType . DEFAULT ) ;
172181 expect ( thread_data . thread_action . read ) . toBe ( BooleanActionType . DEFAULT ) ;
173182 } )
174- it ( 'Throws error when message matches action but has no actions' , ( ) => {
175- expect ( ( ) => {
176- test_proc ( [
177- {
178- conditions : '(sender xyz@gmail.com)' ,
179- stage : '5' ,
180- } ,
181- ] , [
182- {
183- getFrom : ( ) => 'xyz@gmail.com' ,
184- }
185- ] )
186- } ) . toThrow ( ) ;
183+ it ( 'Does nothing to message that matches rule with no actions' , ( ) => {
184+ const thread_data = test_proc ( [
185+ {
186+ conditions : '(sender xyz@gmail.com)' ,
187+ stage : '5' ,
188+ } ,
189+ ] , [
190+ {
191+ getFrom : ( ) => 'xyz@gmail.com' ,
192+ }
193+ ] ) ;
194+
195+ expect ( thread_data . thread_action . action_after_match ) . toBe ( ActionAfterMatchType . DEFAULT ) ;
196+ expect ( thread_data . thread_action . important ) . toBe ( BooleanActionType . DEFAULT ) ;
197+ expect ( thread_data . thread_action . label_names ) . toEqual ( new Set ( ) ) ;
198+ expect ( thread_data . thread_action . move_to ) . toBe ( InboxActionType . DEFAULT ) ;
199+ expect ( thread_data . thread_action . read ) . toBe ( BooleanActionType . DEFAULT ) ;
187200 } )
188201 }
189202}
0 commit comments