From d0bd1d07a472db4b897ddf81c04ae3602cba9297 Mon Sep 17 00:00:00 2001 From: bwarsaw Date: Thu, 31 May 2007 05:01:00 +0000 Subject: Add doctest for Replybot handler. The test in test_handlers.py didn't really do anything. The doctest needs to have some way of testing the grace period, but it's still more tests of the module than there every was before. Update the Replyboty handler to use $-strings internally. Eliminate the use of %-strings in auto-response textsy. Only $-strings can be used, which allows us to get rid of another use of SafeDict. --- Mailman/Handlers/Replybot.py | 41 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 27 deletions(-) (limited to 'Mailman/Handlers/Replybot.py') diff --git a/Mailman/Handlers/Replybot.py b/Mailman/Handlers/Replybot.py index d63169eb2..18fc83ced 100644 --- a/Mailman/Handlers/Replybot.py +++ b/Mailman/Handlers/Replybot.py @@ -20,13 +20,16 @@ import time import logging +from string import Template + from Mailman import Message from Mailman import Utils from Mailman.i18n import _ -from Mailman.SafeDict import SafeDict log = logging.getLogger('mailman.error') +__i18n_templates__ = True + def process(mlist, msg, msgdata): @@ -69,42 +72,26 @@ def process(mlist, msg, msgdata): quiet_until = mlist.postings_responses.get(sender, 0) if quiet_until > now: return - # # Okay, we know we're going to auto-respond to this sender, craft the # message, send it, and update the database. realname = mlist.real_name subject = _( - 'Auto-response for your message to the "%(realname)s" mailing list') - # Do string interpolation - d = SafeDict({'listname' : realname, - 'listurl' : mlist.GetScriptURL('listinfo'), - 'requestemail': mlist.GetRequestEmail(), - # BAW: Deprecate adminemail; it's not advertised but still - # supported for backwards compatibility. - 'adminemail' : mlist.GetBouncesEmail(), - 'owneremail' : mlist.GetOwnerEmail(), - }) - # Just because we're using a SafeDict doesn't mean we can't get all sorts - # of other exceptions from the string interpolation. Let's be ultra - # conservative here. + 'Auto-response for your message to the "$realname" mailing list') + # Do string interpolation into the autoresponse text + d = dict(listname = realname, + listurl = mlist.GetScriptURL('listinfo'), + requestemail = mlist.request_address, + owneremail = mlist.owner_address, + ) if toadmin: rtext = mlist.autoresponse_admin_text elif torequest: rtext = mlist.autoresponse_request_text else: rtext = mlist.autoresponse_postings_text - # Using $-strings? - if getattr(mlist, 'use_dollar_strings', 0): - rtext = Utils.to_percent(rtext) - try: - text = rtext % d - except Exception: - log.error('Bad autoreply text for list: %s\n%s', - mlist.internal_name(), rtext) - text = rtext - # Wrap the response. - text = Utils.wrap(text) - outmsg = Message.UserNotification(sender, mlist.GetBouncesEmail(), + # Interpolation and Wrap the response text. + text = Utils.wrap(Template(rtext).safe_substitute(d)) + outmsg = Message.UserNotification(sender, mlist.bounces_address, subject, text, mlist.preferred_language) outmsg['X-Mailer'] = _('The Mailman Replybot') # prevent recursions and mail loops! -- cgit v1.2.3-70-g09d2