From 0612003f309394789ec11a65580374866f74076c Mon Sep 17 00:00:00 2001 From: bwarsaw Date: Fri, 25 Oct 2002 19:06:33 +0000 Subject: pending_requests(): The requests.pck database may have Unicode strings in them, say if an encoded name appeared in a From header. But maketext() may return byte strings with non-ascii characters in them, and concatenating these two types of strings is a no no. The local fix (implemented here) is to make sure that pending_requests() returns a byte string with no characters that are illegal in the list's preferred language's charset. The longer term fix probably ought to be that we use Unicode everywhere and that maketext() returns a Unicode. --- cron/checkdbs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'cron') diff --git a/cron/checkdbs b/cron/checkdbs index 7bd409663..66ba85d9d 100755 --- a/cron/checkdbs +++ b/cron/checkdbs @@ -22,6 +22,8 @@ list moderators if necessary. import sys import time +from types import UnicodeType +from email.Charset import Charset import paths # mm_cfg must be imported before the other modules, due to the side-effect of @@ -42,6 +44,9 @@ NL = '\n' _ = i18n._ i18n.set_language(mm_cfg.DEFAULT_SERVER_LANGUAGE) +def _isunicode(s): + return isinstance(s, UnicodeType) + def main(): @@ -87,6 +92,7 @@ def main(): def pending_requests(mlist): + # Must return a byte string pending = [] first = 1 for id in mlist.GetSubscriptionIds(): @@ -108,7 +114,19 @@ def pending_requests(mlist): pending.append(_( ' From: %(sender)s on %(date)s\n Cause: %(reason)s')) pending.append('') - return NL.join(pending) + # Make sure that the text we return from here can be encoded to a byte + # string in the charset of the list's language. This could fail if for + # example, the request was pended while the list's language was French, + # but then it was changed to English before checkdbs ran. + text = NL.join(pending) + charset = Charset(Utils.GetCharSet(mlist.preferred_language)) + incodec = charset.input_codec or 'ascii' + outcodec = charset.output_codec or 'ascii' + if _isunicode(text): + return text.encode(outcodec, 'replace') + # Be sure this is a byte string encodeable in the list's charset + utext = unicode(text, incodec, 'replace') + return utext.encode(outcodec, 'replace') -- cgit v1.2.3-70-g09d2