def dispose(mlist, msg, msgdata, why): if mlist.filter_action is FilterAction.reject: # Bounce the message to the original author. raise RejectMessage(why) elif mlist.filter_action is FilterAction.forward: # Forward it on to the list moderators. text = _("""\ The attached message matched the $mlist.display_name mailing list's content filtering rules and was prevented from being forwarded on to the list membership. You are receiving the only remaining copy of the discarded message. """) subject = _('Content filter message notification') notice = OwnerNotification(mlist, subject, roster=mlist.moderators) notice.set_type('multipart/mixed') notice.attach(MIMEText(text)) notice.attach(MIMEMessage(msg)) notice.send(mlist) # Let this fall through so the original message gets discarded. elif mlist.filter_action is FilterAction.preserve: if as_boolean(config.mailman.filtered_messages_are_preservable): # This is just like discarding the message except that a copy is # placed in the 'bad' queue should the site administrator want to # inspect the message. filebase = config.switchboards['bad'].enqueue(msg, msgdata) log.info('{} preserved in file base {}'.format( msg.get('message-id', 'n/a'), filebase)) else: log.error('{} invalid FilterAction: {}. Treating as discard'.format( mlist.fqdn_listname, mlist.filter_action.name)) # Most cases also discard the message raise DiscardMessage(why)
def dispose(mlist, msg, msgdata, why): if mlist.filter_action is FilterAction.reject: # Bounce the message to the original author. raise errors.RejectMessage(why) elif mlist.filter_action is FilterAction.forward: # Forward it on to the list moderators. text=_("""\ The attached message matched the $mlist.display_name mailing list's content filtering rules and was prevented from being forwarded on to the list membership. You are receiving the only remaining copy of the discarded message. """) subject=_('Content filter message notification') notice = OwnerNotification(mlist, subject, roster=mlist.moderators) notice.set_type('multipart/mixed') notice.attach(MIMEText(text)) notice.attach(MIMEMessage(msg)) notice.send(mlist) # Let this fall through so the original message gets discarded. elif mlist.filter_action is FilterAction.preserve: if as_boolean(config.mailman.filtered_messages_are_preservable): # This is just like discarding the message except that a copy is # placed in the 'bad' queue should the site administrator want to # inspect the message. filebase = config.switchboards['bad'].enqueue(msg, msgdata) log.info('{0} preserved in file base {1}'.format( msg.get('message-id', 'n/a'), filebase)) else: log.error( '{1} invalid FilterAction: {0}. Treating as discard'.format( mlist.fqdn_listname, mlist.filter_action.name)) # Most cases also discard the message raise errors.DiscardMessage(why)
def maybe_forward(mlist, msg): """Possibly forward bounce messages with no recognizable addresses. :param mlist: The mailing list. :type mlist: `IMailingList` :param msg: The bounce message to scan. :type msg: `Message` """ message_id = msg['message-id'] if (mlist.forward_unrecognized_bounces_to is UnrecognizedBounceDisposition.discard): blog.error('Discarding unrecognized bounce: {0}'.format(message_id)) return # The notification is either going to go to the list's administrators # (owners and moderators), or to the site administrators. Most of the # notification is exactly the same in either case. subject = _('Uncaught bounce notification') template = getUtility(ITemplateLoader).get( 'list:admin:notice:unrecognized', mlist) text = expand(template, mlist) text_part = MIMEText(text, _charset=mlist.preferred_language.charset) attachment = MIMEMessage(msg) if (mlist.forward_unrecognized_bounces_to is UnrecognizedBounceDisposition.administrators): keywords = dict(roster=mlist.administrators) elif (mlist.forward_unrecognized_bounces_to is UnrecognizedBounceDisposition.site_owner): keywords = {} else: raise AssertionError('Invalid forwarding disposition: {0}'.format( mlist.forward_unrecognized_bounces_to)) # Create the notification and send it. notice = OwnerNotification(mlist, subject, **keywords) notice.set_type('multipart/mixed') notice.attach(text_part) notice.attach(attachment) notice.send(mlist)
def maybe_forward(mlist, msg): """Possibly forward bounce messages with no recognizable addresses. :param mlist: The mailing list. :type mlist: `IMailingList` :param msg: The bounce message to scan. :type msg: `Message` """ message_id = msg['message-id'] if (mlist.forward_unrecognized_bounces_to is UnrecognizedBounceDisposition.discard): blog.error('Discarding unrecognized bounce: {0}'.format(message_id)) return # The notification is either going to go to the list's administrators # (owners and moderators), or to the site administrators. Most of the # notification is exactly the same in either case. adminurl = mlist.script_url('admin') + '/bounce' subject = _('Uncaught bounce notification') text = MIMEText( make('unrecognized.txt', mlist, adminurl=adminurl), _charset=mlist.preferred_language.charset) attachment = MIMEMessage(msg) if (mlist.forward_unrecognized_bounces_to is UnrecognizedBounceDisposition.administrators): keywords = dict(roster=mlist.administrators) elif (mlist.forward_unrecognized_bounces_to is UnrecognizedBounceDisposition.site_owner): keywords = {} else: raise AssertionError('Invalid forwarding disposition: {0}'.format( mlist.forward_unrecognized_bounces_to)) # Create the notification and send it. notice = OwnerNotification(mlist, subject, **keywords) notice.set_type('multipart/mixed') notice.attach(text) notice.attach(attachment) notice.send(mlist)