summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-02-06 19:16:54 (GMT)
committerGitHub <noreply@github.com>2024-02-06 19:16:54 (GMT)
commita04dc431486f20b1c4f7f12a27ca2269329c41bf (patch)
treeb4aaf38cfcab967af62e113053e8c30b3b8d09a3
parent350d1d09c543f8d117420a5cca4b23cd24fd9c10 (diff)
downloadcpython-a04dc431486f20b1c4f7f12a27ca2269329c41bf.zip
cpython-a04dc431486f20b1c4f7f12a27ca2269329c41bf.tar.gz
cpython-a04dc431486f20b1c4f7f12a27ca2269329c41bf.tar.bz2
[3.11] GH-gh-75705: Set unixfrom envelope in mailbox._mboxMMDF (GH-107117) (GH-115099)
(cherry picked from commit 76108b8b05040fc49a6bc50eb2e990576595c57c) Co-authored-by: Matthieu Caneill <matthieucan@users.noreply.github.com>
-rw-r--r--Lib/mailbox.py5
-rw-r--r--Lib/test/test_mailbox.py12
-rw-r--r--Misc/NEWS.d/next/Library/2023-07-23-12-28-26.gh-issue-75705.aB2-Ww.rst1
3 files changed, 15 insertions, 3 deletions
diff --git a/Lib/mailbox.py b/Lib/mailbox.py
index 70da07e..334c7d5 100644
--- a/Lib/mailbox.py
+++ b/Lib/mailbox.py
@@ -778,10 +778,11 @@ class _mboxMMDF(_singlefileMailbox):
"""Return a Message representation or raise a KeyError."""
start, stop = self._lookup(key)
self._file.seek(start)
- from_line = self._file.readline().replace(linesep, b'')
+ from_line = self._file.readline().replace(linesep, b'').decode('ascii')
string = self._file.read(stop - self._file.tell())
msg = self._message_factory(string.replace(linesep, b'\n'))
- msg.set_from(from_line[5:].decode('ascii'))
+ msg.set_unixfrom(from_line)
+ msg.set_from(from_line[5:])
return msg
def get_string(self, key, from_=False):
diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py
index 90642a9..3a53144 100644
--- a/Lib/test/test_mailbox.py
+++ b/Lib/test/test_mailbox.py
@@ -1027,12 +1027,14 @@ class _TestMboxMMDF(_TestSingleFile):
# Add a string starting with 'From ' to the mailbox
key = self._box.add('From foo@bar blah\nFrom: foo\n\n0\n')
self.assertEqual(self._box[key].get_from(), 'foo@bar blah')
+ self.assertEqual(self._box[key].get_unixfrom(), 'From foo@bar blah')
self.assertEqual(self._box[key].get_payload(), '0\n')
def test_add_from_bytes(self):
# Add a byte string starting with 'From ' to the mailbox
key = self._box.add(b'From foo@bar blah\nFrom: foo\n\n0\n')
self.assertEqual(self._box[key].get_from(), 'foo@bar blah')
+ self.assertEqual(self._box[key].get_unixfrom(), 'From foo@bar blah')
self.assertEqual(self._box[key].get_payload(), '0\n')
def test_add_mbox_or_mmdf_message(self):
@@ -1545,18 +1547,23 @@ class _TestMboxMMDFMessage:
msg = mailbox.Message(_sample_message)
msg.set_unixfrom('From foo@bar blah')
msg = mailbox.mboxMessage(msg)
- self.assertEqual(msg.get_from(), 'foo@bar blah', msg.get_from())
+ self.assertEqual(msg.get_from(), 'foo@bar blah')
+ self.assertEqual(msg.get_unixfrom(), 'From foo@bar blah')
def test_from(self):
# Get and set "From " line
msg = mailbox.mboxMessage(_sample_message)
self._check_from(msg)
+ self.assertIsNone(msg.get_unixfrom())
msg.set_from('foo bar')
self.assertEqual(msg.get_from(), 'foo bar')
+ self.assertIsNone(msg.get_unixfrom())
msg.set_from('foo@bar', True)
self._check_from(msg, 'foo@bar')
+ self.assertIsNone(msg.get_unixfrom())
msg.set_from('blah@temp', time.localtime())
self._check_from(msg, 'blah@temp')
+ self.assertIsNone(msg.get_unixfrom())
def test_flags(self):
# Use get_flags(), set_flags(), add_flag(), remove_flag()
@@ -1744,6 +1751,7 @@ class TestMessageConversion(TestBase, unittest.TestCase):
self.assertEqual(msg.get_flags(), result)
self.assertEqual(msg.get_from(), 'MAILER-DAEMON %s' %
time.asctime(time.gmtime(0.0)))
+ self.assertIsNone(msg.get_unixfrom())
msg_maildir.set_subdir('cur')
self.assertEqual(class_(msg_maildir).get_flags(), 'RODFA')
@@ -1792,10 +1800,12 @@ class TestMessageConversion(TestBase, unittest.TestCase):
msg_mboxMMDF = class_(_sample_message)
msg_mboxMMDF.set_flags('RODFA')
msg_mboxMMDF.set_from('foo@bar')
+ self.assertIsNone(msg_mboxMMDF.get_unixfrom())
for class2_ in (mailbox.mboxMessage, mailbox.MMDFMessage):
msg2 = class2_(msg_mboxMMDF)
self.assertEqual(msg2.get_flags(), 'RODFA')
self.assertEqual(msg2.get_from(), 'foo@bar')
+ self.assertIsNone(msg2.get_unixfrom())
def test_mboxmmdf_to_mh(self):
# Convert mboxMessage and MMDFMessage to MHMessage
diff --git a/Misc/NEWS.d/next/Library/2023-07-23-12-28-26.gh-issue-75705.aB2-Ww.rst b/Misc/NEWS.d/next/Library/2023-07-23-12-28-26.gh-issue-75705.aB2-Ww.rst
new file mode 100644
index 0000000..272e31d
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-07-23-12-28-26.gh-issue-75705.aB2-Ww.rst
@@ -0,0 +1 @@
+Set unixfrom envelope in :class:`mailbox.mbox` and :class:`mailbox.MMDF`.