def test_no_sender(self): # The message won't be bounced if it has no discernible sender. self._msg.sender = None bounce_message(self._mlist, self._msg) items = get_queue_messages('virgin') # Nothing in the virgin queue means nothing's been bounced. self.assertEqual(items, [])
def test_no_sender(self): # The message won't be bounced if it has no discernible sender. del self._msg['from'] bounce_message(self._mlist, self._msg) items = get_queue_messages('virgin') # Nothing in the virgin queue means nothing's been bounced. self.assertEqual(items, [])
def _process(self, mlist, msg, msgdata): """See `TerminalChainBase`.""" # Start by decorating the message with a header that contains a list # of all the rules that matched. These metadata could be None or an # empty list. rule_hits = msgdata.get('rule_hits') if rule_hits: msg['X-Mailman-Rule-Hits'] = SEMISPACE.join(rule_hits) rule_misses = msgdata.get('rule_misses') if rule_misses: msg['X-Mailman-Rule-Misses'] = SEMISPACE.join(rule_misses) reasons = msgdata.get('moderation_reasons') if reasons is None: error = None else: error = RejectMessage(_(""" Your message to the {list_name} mailing-list was rejected for the following reasons: {reasons} The original message as received by Mailman is attached. """).format( list_name=mlist.display_name, # noqa reasons=NEWLINE.join(reasons) # noqa )) bounce_message(mlist, msg, error) log.info('REJECT: %s', msg.get('message-id', 'n/a')) notify(RejectEvent(mlist, msg, msgdata, self))
def _process(self, mlist, msg, msgdata): """See `TerminalChainBase`.""" # Start by decorating the message with a header that contains a list # of all the rules that matched. These metadata could be None or an # empty list. rule_hits = msgdata.get('rule_hits') if rule_hits: msg['X-Mailman-Rule-Hits'] = SEMISPACE.join(rule_hits) rule_misses = msgdata.get('rule_misses') if rule_misses: msg['X-Mailman-Rule-Misses'] = SEMISPACE.join(rule_misses) # XXX Exception/reason bounce_message(mlist, msg) log.info('REJECT: %s', msg.get('message-id', 'n/a')) notify(RejectNotification(mlist, msg, msgdata, self))
def _process(self, mlist, msg, msgdata): """See `TerminalChainBase`.""" # Start by decorating the message with a header that contains a list # of all the rules that matched. These metadata could be None or an # empty list. rule_hits = msgdata.get('rule_hits') if rule_hits: msg['X-Mailman-Rule-Hits'] = SEMISPACE.join(rule_hits) rule_misses = msgdata.get('rule_misses') if rule_misses: msg['X-Mailman-Rule-Misses'] = SEMISPACE.join(rule_misses) # XXX Exception/reason bounce_message(mlist, msg) log.info('REJECT: %s', msg.get('message-id', 'n/a')) notify(RejectEvent(mlist, msg, msgdata, self))
def process(mlist, msg, msgdata, pipeline_name='built-in'): """Process the message through the given pipeline. :param mlist: the IMailingList for this message. :param msg: The Message object. :param msgdata: The message metadata dictionary. :param pipeline_name: The name of the pipeline to process through. """ message_id = msg.get('message-id', 'n/a') pipeline = config.pipelines[pipeline_name] for handler in pipeline: dlog.debug('{} pipeline {} processing: {}'.format( message_id, pipeline_name, handler.name)) try: handler.process(mlist, msg, msgdata) except DiscardMessage as error: vlog.info('{} discarded by "{}" pipeline handler "{}": {}'.format( message_id, pipeline_name, handler.name, error.message)) except RejectMessage as error: vlog.info('{} rejected by "{}" pipeline handler "{}": {}'.format( message_id, pipeline_name, handler.name, str(error))) bounce_message(mlist, msg, error)
def _process(self, mlist, msg, msgdata): """See `TerminalChainBase`.""" # Start by decorating the message with a header that contains a list # of all the rules that matched. These metadata could be None or an # empty list. rule_hits = msgdata.get('rule_hits') if rule_hits: msg['X-Mailman-Rule-Hits'] = SEMISPACE.join(rule_hits) rule_misses = msgdata.get('rule_misses') if rule_misses: msg['X-Mailman-Rule-Misses'] = SEMISPACE.join(rule_misses) reasons = msgdata.get('moderation_reasons') if reasons is None: error = None else: template = getUtility(ITemplateLoader).get( 'list:user:notice:rejected', mlist) error = RejectMessage(template, reasons, dict(listname=mlist.display_name)) bounce_message(mlist, msg, error) log.info('REJECT: %s', msg.get('message-id', 'n/a')) notify(RejectEvent(mlist, msg, msgdata, self))
def process(mlist, msg, msgdata, pipeline_name='built-in'): """Process the message through the given pipeline. :param mlist: the IMailingList for this message. :param msg: The Message object. :param msgdata: The message metadata dictionary. :param pipeline_name: The name of the pipeline to process through. """ message_id = msg.get('message-id', 'n/a') pipeline = config.pipelines[pipeline_name] for handler in pipeline: dlog.debug('{0} pipeline {1} processing: {2}'.format( message_id, pipeline_name, handler.name)) try: handler.process(mlist, msg, msgdata) except errors.DiscardMessage as error: vlog.info( '{0} discarded by "{1}" pipeline handler "{2}": {3}'.format( message_id, pipeline_name, handler.name, error.message)) except errors.RejectMessage as error: vlog.info( '{0} rejected by "{1}" pipeline handler "{2}": {3}'.format( message_id, pipeline_name, handler.name, error.message)) bounce_message(mlist, msg, error)
def test_no_sender(self): # The message won't be bounced if it has no discernible sender. del self._msg['from'] bounce_message(self._mlist, self._msg) # Nothing in the virgin queue means nothing's been bounced. get_queue_messages('virgin', expected_count=0)