summaryrefslogtreecommitdiff
path: root/src/mailman/model
diff options
context:
space:
mode:
authorBarry Warsaw2016-03-08 23:01:14 -0500
committerBarry Warsaw2016-03-08 23:01:14 -0500
commitcb8ddd1671e424478f002e527871f0c5839425d9 (patch)
treeff8845ca998b2b4ea2f67a908c862d79f664f6d7 /src/mailman/model
parent47b4d1f987a91e1a2ce9b1e533c166ca21c2477e (diff)
downloadmailman-cb8ddd1671e424478f002e527871f0c5839425d9.tar.gz
mailman-cb8ddd1671e424478f002e527871f0c5839425d9.tar.zst
mailman-cb8ddd1671e424478f002e527871f0c5839425d9.zip
Fix cross-posting held on more than one list.
Closes #176 Also: * IMessageStore no longer raises a ValueError if the Message-ID already exists in the store; it just returns None. * The internal handle_message() function no longer takes a `preserve` argument, since messages are never removed from the IMessageStore.
Diffstat (limited to 'src/mailman/model')
-rw-r--r--src/mailman/model/messagestore.py6
-rw-r--r--src/mailman/model/tests/test_messagestore.py19
2 files changed, 21 insertions, 4 deletions
diff --git a/src/mailman/model/messagestore.py b/src/mailman/model/messagestore.py
index f247f94c2..9d0cfbc76 100644
--- a/src/mailman/model/messagestore.py
+++ b/src/mailman/model/messagestore.py
@@ -56,13 +56,11 @@ class MessageStore:
message_id = message_ids[0]
if isinstance(message_id, bytes):
message_id = message_id.decode('ascii')
- # Complain if the Message-ID already exists in the storage.
+ # If the Message-ID already exists in the store, don't store it again.
existing = store.query(Message).filter(
Message.message_id == message_id).first()
if existing is not None:
- raise ValueError(
- 'Message ID already exists in message store: {0}'.format(
- message_id))
+ return None
hash32 = add_message_hash(message)
# Calculate the path on disk where we're going to store this message
# object, in pickled format.
diff --git a/src/mailman/model/tests/test_messagestore.py b/src/mailman/model/tests/test_messagestore.py
index 6e3142536..998fa36c0 100644
--- a/src/mailman/model/tests/test_messagestore.py
+++ b/src/mailman/model/tests/test_messagestore.py
@@ -137,3 +137,22 @@ X-Message-ID-Hash: abc
self.assertEqual(len(x_message_id_hashes), 1)
self.assertEqual(x_message_id_hashes[0],
'MS6QLWERIJLGCRF44J7USBFDELMNT2BW')
+
+ def test_add_message_duplicate_okay(self):
+ msg = mfs("""\
+Subject: Once
+Message-ID: <ant>
+
+""")
+ hash32 = self._store.add(msg)
+ stored_msg = self._store.get_message_by_id('<ant>')
+ self.assertEqual(msg['subject'], stored_msg['subject'])
+ self.assertEqual(msg['message-id-hash'], hash32)
+ # A second insertion, even if headers change, does not store the
+ # message twice.
+ del msg['subject']
+ msg['Subject'] = 'Twice'
+ hash32 = self._store.add(msg)
+ stored_msg = self._store.get_message_by_id('<ant>')
+ self.assertNotEqual(msg['subject'], stored_msg['subject'])
+ self.assertIsNone(hash32)