Skip to content

Commit e572022

Browse files
committed
archiver
1 parent 107fe28 commit e572022

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

Mailman/Archiver/Archiver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def __archive_file(self, afn):
150150
"""Open (creating, if necessary) the named archive file."""
151151
omask = os.umask(0o002)
152152
try:
153-
return Mailbox.Mailbox(open(afn, 'a+'))
153+
return Mailbox.Mailbox(open(afn, 'a+b'))
154154
finally:
155155
os.umask(omask)
156156

Mailman/Archiver/HyperArch.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def __init__(self, message=None, sequence=0, keepHeaders=[],
299299
cset_out = Charset(cset).output_charset or cset
300300
if isinstance(cset_out, str):
301301
# email 3.0.1 (python 2.4) doesn't like unicode
302-
cset_out = cset_out.encode('us-ascii')
302+
cset_out = cset_out.encode('us-ascii', 'replace')
303303
charset = message.get_content_charset(cset_out)
304304
if charset:
305305
charset = charset.lower().strip()
@@ -313,14 +313,17 @@ def __init__(self, message=None, sequence=0, keepHeaders=[],
313313
body = None
314314
if body and charset != Utils.GetCharSet(self._lang):
315315
if isinstance(charset, bytes):
316-
charset = charset.decode()
316+
charset = charset.decode('utf-8', 'replace')
317317
# decode body
318318
try:
319319
body = body.decode(charset)
320320
except (UnicodeError, LookupError):
321321
body = None
322322
if body:
323-
self.body = [l.decode() + "\n" if isinstance(l, bytes) else l + "\n" for l in body.splitlines()]
323+
# Handle both bytes and strings properly
324+
if isinstance(body, bytes):
325+
body = body.decode('utf-8', 'replace')
326+
self.body = [l + "\n" for l in body.splitlines()]
324327

325328
self.decode_headers()
326329

@@ -875,7 +878,7 @@ def processListArch(self):
875878
#if the working file is still here, the archiver may have
876879
# crashed during archiving. Save it, log an error, and move on.
877880
try:
878-
wf = open(wname)
881+
wf = open(wname, 'r')
879882
syslog('error',
880883
'Archive working file %s present. '
881884
'Check %s for possibly unarchived msgs',
@@ -895,7 +898,7 @@ def processListArch(self):
895898
except IOError:
896899
pass
897900
os.rename(name,wname)
898-
archfile = open(wname)
901+
archfile = open(wname, 'r')
899902
self.processUnixMailbox(archfile)
900903
archfile.close()
901904
os.unlink(wname)
@@ -1039,7 +1042,7 @@ def open_new_archive(self, archive, archivedir):
10391042
index_html = os.path.join(archivedir, 'index.html')
10401043
try:
10411044
os.unlink(index_html)
1042-
except:
1045+
except (OSError, IOError):
10431046
pass
10441047
os.symlink(self.DEFAULTINDEX+'.html',index_html)
10451048

@@ -1144,7 +1147,7 @@ def update_archive(self, archive):
11441147
oldgzip = os.path.join(self.basedir, '%s.old.txt.gz' % archive)
11451148
try:
11461149
# open the plain text file
1147-
archt = open(txtfile)
1150+
archt = open(txtfile, 'r')
11481151
except IOError:
11491152
return
11501153
try:

0 commit comments

Comments
 (0)