11import re
2+ from email .message import Message
3+ from typing import Optional
4+
25from sifter .grammar .command import Command
36from sifter .grammar .string import expand_variables
47from sifter .validators .stringlist import StringList
58from sifter .validators .tag import Tag
69from sifter .grammar .rule import RuleSyntaxError
710from sifter .extensions import ExtensionRegistry
11+ from sifter .grammar .state import EvaluationState
12+ from sifter .grammar .actions import Actions
813
914
1015# RFC 5435
@@ -21,39 +26,39 @@ class CommandNotify(Command):
2126 StringList (length = 1 )
2227 ]
2328
24- def __init__ (self , arguments = None , tests = None , block = None ):
25- super (CommandNotify , self ).__init__ (arguments , tests , block )
26-
27- self .notify_from = self .notify_importance = self .notify_message = None
28- self .notify_options = []
29+ def evaluate (self , message : Message , state : EvaluationState ) -> Optional [Actions ]:
30+ notify_from = notify_importance = self .notify_message = None
31+ notify_options = [] # type: ignore
2932 if 'from' in self .tagged_args :
30- self . notify_from = self .tagged_args ['from' ][1 ][0 ]
33+ notify_from = self .tagged_args ['from' ][1 ][0 ] # type: ignore
3134 if 'importance' in self .tagged_args :
32- self . notify_importance = self .tagged_args ['importance' ][1 ][0 ]
35+ notify_importance = self .tagged_args ['importance' ][1 ][0 ] # type: ignore
3336 if 'options' in self .tagged_args :
34- self .notify_options = self .tagged_args ['options' ][1 ]
37+ notify_options = self .tagged_args ['options' ][1 ] # type: ignore
38+ notify_message = None
3539 if 'message' in self .tagged_args :
36- self . notify_message = self .tagged_args ['message' ][1 ][0 ] # type: ignore
37- self . notify_method = self .positional_args [0 ][0 ] # type: ignore
40+ notify_message = self .tagged_args ['message' ][1 ][0 ] # type: ignore
41+ notify_method = self .positional_args [0 ][0 ] # type: ignore
3842
39- def evaluate (self , message , state ):
4043 state .check_required_extension ('enotify' , 'NOTIFY' )
41- notify_from = expand_variables (self . notify_from , state )
42- notify_importance = expand_variables (self . notify_importance , state )
43- notify_options = map (lambda s : expand_variables (s , state ), self . notify_options )
44- notify_message = expand_variables (self . notify_message , state )
45- notify_method = expand_variables (self . notify_method , state )
44+ notify_from = expand_variables (notify_from , state ) # type: ignore
45+ notify_importance = expand_variables (notify_importance , state ) # type: ignore
46+ notify_options = list ( map (lambda s : expand_variables (s , state ), notify_options ) )
47+ notify_message = expand_variables (notify_message , state ) # type: ignore
48+ notify_method = expand_variables (notify_method , state )
4649
4750 m = re .match ('^([A-Za-z][A-Za-z0-9.+-]*):' , notify_method )
4851 if not m :
4952 raise RuleSyntaxError ("Notification method must be an URI, e.g. 'mailto:email@example.com'" )
5053 if notify_importance and notify_importance not in ["1" , "2" , "3" ]:
51- raise RuleSyntaxError ("Illegal notify importance '%s' encountered" % self . notify_importance )
54+ raise RuleSyntaxError ("Illegal notify importance '%s' encountered" % notify_importance )
5255 notify_method_cls = ExtensionRegistry .get_notification_method (m .group (1 ).lower ())
5356 if not notify_method_cls :
5457 raise RuleSyntaxError ("Unsupported notification method '%s'" % m .group (1 ))
5558 (res , msg ) = notify_method_cls .test_valid (notify_method )
5659 if not res :
5760 raise RuleSyntaxError (msg )
5861
59- state .actions .append ('notify' , (notify_method , notify_from , notify_importance , notify_options , notify_message ))
62+ state .actions .append ('notify' , (notify_method , notify_from , notify_importance , notify_options , notify_message )) # type: ignore
63+
64+ return None
0 commit comments