summaryrefslogtreecommitdiff
path: root/Mailman/Handlers/SMTPDirect.py
diff options
context:
space:
mode:
authorbwarsaw2002-10-04 21:08:49 +0000
committerbwarsaw2002-10-04 21:08:49 +0000
commitcb8c40cf68e70afcd36d6e6c55ec4d1d1dbcdb73 (patch)
treef9e08d8a5eee3eeb721b7a10402fe9b0bb6d357f /Mailman/Handlers/SMTPDirect.py
parent9447ff68aa82ea696844e3a73f5ae79373dd5a9d (diff)
downloadmailman-cb8c40cf68e70afcd36d6e6c55ec4d1d1dbcdb73.tar.gz
mailman-cb8c40cf68e70afcd36d6e6c55ec4d1d1dbcdb73.tar.zst
mailman-cb8c40cf68e70afcd36d6e6c55ec4d1d1dbcdb73.zip
verpdeliver(): I think I've (finally!) nailed the full name encoding
problem reported a few weeks ago. We do here largely what we do in CookHeaders.py for encoding non-ascii Subject prefixes. First, we convert the string to Unicode (possibly throwing out characters if necessary), then we use the Header class to properly RFC 2047 encode the name.
Diffstat (limited to 'Mailman/Handlers/SMTPDirect.py')
-rw-r--r--Mailman/Handlers/SMTPDirect.py34
1 files changed, 18 insertions, 16 deletions
diff --git a/Mailman/Handlers/SMTPDirect.py b/Mailman/Handlers/SMTPDirect.py
index fc725eb21..ce974931e 100644
--- a/Mailman/Handlers/SMTPDirect.py
+++ b/Mailman/Handlers/SMTPDirect.py
@@ -28,6 +28,7 @@ for a threaded implementation.
import time
import socket
import smtplib
+from types import UnicodeType
from Mailman import mm_cfg
from Mailman import Utils
@@ -39,6 +40,7 @@ from Mailman.SafeDict import MsgSafeDict
import email
from email.Utils import formataddr
from email.Header import Header
+from email.Charset import Charset
DOT = '.'
@@ -281,22 +283,22 @@ def verpdeliver(mlist, msg, msgdata, envsender, failures, conn):
del msgcopy['to']
if mlist.isMember(recip):
name = mlist.getMemberName(recip)
- # If there are non-ASCII characters in the name, attempt to
- # encode the name in the outgoing character set.
- try:
- name.encode('us-ascii')
- except UnicodeError:
- charset = Utils.GetCharSet(mlist.getMemberLanguage(recip))
- # We want non-ASCII characters to be allowed in English
- # lists, without changing the English charset to
- # iso-8859-1. See Utils.canonstr() for details.
- if charset == 'us-ascii':
- charset = 'iso-8859-1'
- name = Header(name, charset).encode()
- # And now ensure that it actually /is/ ASCII. E.g. the
- # user's preferred language is English, but they have a
- # funny character in their name.
- name = name.encode('us-ascii', 'replace')
+ # Convert the name to an email-safe representation. If the
+ # name is a byte string, convert it first to Unicode, given
+ # the character set of the member's language, replacing bad
+ # characters for which we can do nothing about. Once we have
+ # the name as Unicode, we can create a Header instance for it
+ # so that it's properly encoded for email transport.
+ charset = Utils.GetCharSet(mlist.getMemberLanguage(recip))
+ if charset == 'us-ascii':
+ # Since Header already tries both us-ascii and utf-8,
+ # let's add something a bit more useful.
+ charset = 'iso-8859-1'
+ charset = Charset(charset)
+ if not isinstance(name, UnicodeType):
+ name = unicode(name, charset.get_output_charset(),
+ 'replace')
+ name = Header(name, charset).encode()
msgcopy['To'] = formataddr((name, recip))
else:
msgcopy['To'] = recip