Skip to content
Snippets Groups Projects
Commit 84bd61aa authored by Stuart Gathman's avatar Stuart Gathman
Browse files

Wrap @noreply callbacks to return NOREPLY only when so negotiated.

parent 372fad6a
Branches
Tags
No related merge requests found
...@@ -46,11 +46,15 @@ def nocallback(func): ...@@ -46,11 +46,15 @@ def nocallback(func):
def noreply(func): def noreply(func):
try: try:
func.milter_protocol = OPTIONAL_CALLBACKS[func.__name__][0] nr_mask = func.milter_protocol = OPTIONAL_CALLBACKS[func.__name__][0]
except KeyErro: except KeyErro:
raise ValueError( raise ValueError(
'@noreply applied to non-optional method: '+func.__name__) '@noreply applied to non-optional method: '+func.__name__)
return func def wrapper(self,*args):
rc = func(self,*args)
if self._protocol & nr_mask: return NOREPLY
return rc
return wrapper
class DisabledAction(RuntimeError): class DisabledAction(RuntimeError):
pass pass
...@@ -64,6 +68,7 @@ class Base(object): ...@@ -64,6 +68,7 @@ class Base(object):
def _setctx(self,ctx): def _setctx(self,ctx):
self._ctx = ctx self._ctx = ctx
self._actions = CURR_ACTS # all actions enabled by default self._actions = CURR_ACTS # all actions enabled by default
self._protocol = 0 # no protocol options by default
if ctx: if ctx:
ctx.setpriv(self) ctx.setpriv(self)
def log(self,*msg): pass def log(self,*msg): pass
...@@ -89,7 +94,7 @@ class Base(object): ...@@ -89,7 +94,7 @@ class Base(object):
def abort(self): return CONTINUE def abort(self): return CONTINUE
def close(self): return CONTINUE def close(self): return CONTINUE
# Return mask of SMFIP_N.. protocol bits to clear for this class # Return mask of SMFIP_N.. protocol option bits to clear for this class
@classmethod @classmethod
def protocol_mask(klass): def protocol_mask(klass):
try: try:
...@@ -109,7 +114,8 @@ class Base(object): ...@@ -109,7 +114,8 @@ class Base(object):
def negotiate(self,opts): def negotiate(self,opts):
try: try:
self._actions,p,f1,f2 = opts self._actions,p,f1,f2 = opts
opts[1] = p & ~self.protocol_mask() & ~P_RCPT_REJ & ~P_HDR_LEADSPC opts[1] = self._protocol = \
p & ~self.protocol_mask() & ~P_RCPT_REJ & ~P_HDR_LEADSPC
opts[2] = 0 opts[2] = 0
opts[3] = 0 opts[3] = 0
self.log("Negotiated:",opts) self.log("Negotiated:",opts)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment