def _sendToChain(self, chain, currentDepth, sendargs, matchargs): """Send mail. matchargs is just for _matchRuleForSend function """ currentDepth = currentDepth + 1 chain = self._getChain(chain) posargs = [sendargs[x] for x in ('messageText','mto','mfrom','subject', 'encode', 'immediate', 'charset', 'msg_type')] for rule in chain: if not self._matchRuleForSend(rule, matchargs): continue log.info("rule %s matched. send and continue" % rule) action = rule['action'] if rule['mailhost'] == 'default': send = self.aq_parent.MailHost._old_send #elif rule['mailhost'] in self.objectIds(): # send = self.get(rule['mailhost']).send else: view = self.unrestrictedTraverse(rule['mailhost']) if IMailHost.providedBy(view): send = view.send elif view is not None: #assume its a callable send = view else: send = None if action == 'send and continue': send(*posargs) elif action == 'send and stop': send(*posargs) raise MultiMailChainStop() elif action == 'stop': raise MultiMailChainStop() elif action == 'send and return': raise NotImplemented() send(*posargs) return elif action == 'jump': raise NotImplemented() self._sendToChain(rule['chain'], currentDepth, sendargs, matchargs) elif action == 'return': raise NotImplemented() return else: raise Exception("Invalid action") log.info("end of chain reached" % rule)
def _sendToChain(self, chain, currentDepth, sendargs): """Send mail. """ currentDepth = currentDepth + 1 chain = self._getChain(chain) for rule in chain: if not self._matchRuleForSend (rule, sendargs): continue action = rule['action'] if rule['mailhost'] == 'default': send = self.aq_parent.MailHost._old_send #elif rule['mailhost'] in self.objectIds(): # send = self.get(rule['mailhost']).send else: view = self.unrestrictedTraverse(rule['mailhost']) if IMailHost.providedBy(view): send = view.send elif view is not None: #assume its a callable send = view else: send = None if action == 'send and continue': send(**sendargs) elif action == 'send and stop': send(**sendargs) raise MultiMailChainStop() elif action == 'stop': raise MultiMailChainStop() elif action == 'send and return': raise NotImplemented() send(**sendargs) return elif action == 'jump': raise NotImplemented() self._sendToChain(rule['chain'], currentDepth, sendargs) elif action == 'return': raise NotImplemented() return else: raise Exception("Invalid action")
def test_getMailHost(self): self.assertTrue(IMailHost.providedBy(self.tool.getMailHost()))