Skip to content

Commit ec6c62d

Browse files
committed
update
1 parent 44ff079 commit ec6c62d

2 files changed

Lines changed: 33 additions & 9 deletions

File tree

Mailman/Handlers/SMTPDirect.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,14 @@ def bulkdeliver(mlist, msg, msgdata, envsender, failures, conn):
423423
refused = {}
424424
recips = msgdata['recips']
425425
msgid = msg.get('Message-ID', 'n/a')
426+
# Ensure msgid is a string
427+
if isinstance(msgid, bytes):
428+
try:
429+
msgid = msgid.decode('utf-8', 'replace')
430+
except UnicodeDecodeError:
431+
msgid = msgid.decode('latin-1', 'replace')
432+
elif not isinstance(msgid, str):
433+
msgid = str(msgid)
426434
try:
427435
# Send the message
428436
refused = conn.sendmail(envsender, recips, msgtext)
@@ -431,7 +439,7 @@ def bulkdeliver(mlist, msg, msgdata, envsender, failures, conn):
431439
e, msgid)
432440
refused = e.recipients
433441
# Move message to bad queue since all recipients were refused
434-
badq = get_switchboard(mm_cfg.BADQUEUE_DIR)
442+
badq = get_switchboard(Mailman.mm_cfg.BADQUEUE_DIR)
435443
badq.enqueue(msg, msgdata)
436444
except smtplib.SMTPResponseException as e:
437445
mailman_log('smtp-failure', 'SMTP session failure: %s, %s, msgid: %s',
@@ -441,7 +449,7 @@ def bulkdeliver(mlist, msg, msgdata, envsender, failures, conn):
441449
# Permanent failure - add to refused and move to bad queue
442450
for r in recips:
443451
refused[r] = (e.smtp_code, e.smtp_error)
444-
badq = get_switchboard(mm_cfg.BADQUEUE_DIR)
452+
badq = get_switchboard(Mailman.mm_cfg.BADQUEUE_DIR)
445453
badq.enqueue(msg, msgdata)
446454
else:
447455
# Temporary failure - don't add to refused
@@ -453,6 +461,6 @@ def bulkdeliver(mlist, msg, msgdata, envsender, failures, conn):
453461
for r in recips:
454462
refused[r] = (-1, error)
455463
# Move message to bad queue for low level errors
456-
badq = get_switchboard(mm_cfg.BADQUEUE_DIR)
464+
badq = get_switchboard(Mailman.mm_cfg.BADQUEUE_DIR)
457465
badq.enqueue(msg, msgdata)
458466
failures.update(refused)

Mailman/MailList.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,19 +332,19 @@ def InitTempVars(self, name):
332332
# timestamp is newer than the modtime of the config.pck file, we don't
333333
# need to reload, otherwise... we do.
334334
self.__timestamp = 0
335-
self.__lock = LockFile.LockFile(
336-
os.path.join(mm_cfg.LOCK_DIR, name or '<site>') + '.lock',
337-
# TBD: is this a good choice of lifetime?
338-
lifetime = mm_cfg.LIST_LOCK_LIFETIME,
339-
withlogging = mm_cfg.LIST_LOCK_DEBUGGING)
340-
# Ensure name is a string
335+
# Ensure name is a string before using it in os.path.join
341336
if isinstance(name, bytes):
342337
try:
343338
# Try Latin-1 first since that's what we're seeing in the data
344339
name = name.decode('latin-1', 'replace')
345340
except UnicodeDecodeError:
346341
# Fall back to UTF-8 if Latin-1 fails
347342
name = name.decode('utf-8', 'replace')
343+
self.__lock = LockFile.LockFile(
344+
os.path.join(mm_cfg.LOCK_DIR, name or '<site>') + '.lock',
345+
# TBD: is this a good choice of lifetime?
346+
lifetime = mm_cfg.LIST_LOCK_LIFETIME,
347+
withlogging = mm_cfg.LIST_LOCK_DEBUGGING)
348348
self._internal_name = name
349349
if name:
350350
self._full_path = Site.get_listpath(name)
@@ -366,6 +366,14 @@ def InitVars(self, name=None, admin='', crypted_password='',
366366
"""Assign default values - some will be overriden by stored state."""
367367
# Non-configurable list info
368368
if name:
369+
# Ensure name is a string
370+
if isinstance(name, bytes):
371+
try:
372+
# Try Latin-1 first since that's what we're seeing in the data
373+
name = name.decode('latin-1', 'replace')
374+
except UnicodeDecodeError:
375+
# Fall back to UTF-8 if Latin-1 fails
376+
name = name.decode('utf-8', 'replace')
369377
self._internal_name = name
370378

371379
# When was the list created?
@@ -593,6 +601,14 @@ def GetConfigInfo(self, category, subcat=None):
593601
#
594602
def Create(self, name, admin, crypted_password,
595603
langs=None, emailhost=None, urlhost=None):
604+
# Ensure name is a string
605+
if isinstance(name, bytes):
606+
try:
607+
# Try Latin-1 first since that's what we're seeing in the data
608+
name = name.decode('latin-1', 'replace')
609+
except UnicodeDecodeError:
610+
# Fall back to UTF-8 if Latin-1 fails
611+
name = name.decode('utf-8', 'replace')
596612
if name != name.lower():
597613
raise ValueError('List name must be all lower case.')
598614
if Utils.list_exists(name):

0 commit comments

Comments
 (0)