summaryrefslogtreecommitdiff
path: root/src/mailman/model/messagestore.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman/model/messagestore.py')
-rw-r--r--src/mailman/model/messagestore.py21
1 files changed, 6 insertions, 15 deletions
diff --git a/src/mailman/model/messagestore.py b/src/mailman/model/messagestore.py
index 12b2aef46..05069119c 100644
--- a/src/mailman/model/messagestore.py
+++ b/src/mailman/model/messagestore.py
@@ -17,9 +17,6 @@
"""Model for message stores."""
-from __future__ import absolute_import, print_function, unicode_literals
-
-__metaclass__ = type
__all__ = [
'MessageStore',
]
@@ -28,16 +25,15 @@ __all__ = [
import os
import errno
import base64
+import pickle
import hashlib
-import cPickle as pickle
-
-from zope.interface import implementer
from mailman.config import config
from mailman.database.transaction import dbconnection
from mailman.interfaces.messages import IMessageStore
from mailman.model.message import Message
from mailman.utilities.filesystem import makedirs
+from zope.interface import implementer
# It could be very bad if you have already stored files and you change this
@@ -68,8 +64,8 @@ class MessageStore:
raise ValueError(
'Message ID already exists in message store: {0}'.format(
message_id))
- shaobj = hashlib.sha1(message_id)
- hash32 = base64.b32encode(shaobj.digest())
+ shaobj = hashlib.sha1(message_id.encode('utf-8'))
+ hash32 = base64.b32encode(shaobj.digest()).decode('utf-8')
del message['X-Message-ID-Hash']
message['X-Message-ID-Hash'] = hash32
# Calculate the path on disk where we're going to store this message
@@ -94,7 +90,7 @@ class MessageStore:
# them and try again.
while True:
try:
- with open(path, 'w') as fp:
+ with open(path, 'wb') as fp:
# -1 says to use the highest protocol available.
pickle.dump(message, fp, -1)
break
@@ -106,7 +102,7 @@ class MessageStore:
def _get_message(self, row):
path = os.path.join(config.MESSAGES_DIR, row.path)
- with open(path) as fp:
+ with open(path, 'rb') as fp:
return pickle.load(fp)
@dbconnection
@@ -118,11 +114,6 @@ class MessageStore:
@dbconnection
def get_message_by_hash(self, store, message_id_hash):
- # It's possible the hash came from a message header, in which case it
- # will be a Unicode. However when coming from source code, it may be
- # bytes object. Coerce to the latter if necessary; it must be ASCII.
- if not isinstance(message_id_hash, bytes):
- message_id_hash = message_id_hash.encode('ascii')
row = store.query(Message).filter_by(
message_id_hash=message_id_hash).first()
if row is None: