mirror of
https://github.com/python/cpython.git
synced 2025-12-09 02:35:14 +00:00
[Bug #1633678] Improve pattern used for mbox 'From' lines; add a simple test
This commit is contained in:
parent
a0a133bea8
commit
f446a9b00a
2 changed files with 38 additions and 3 deletions
|
|
@ -1974,8 +1974,10 @@ class UnixMailbox(_Mailbox):
|
||||||
# necessary. For convenience, we've added a PortableUnixMailbox class
|
# necessary. For convenience, we've added a PortableUnixMailbox class
|
||||||
# which does no checking of the format of the 'From' line.
|
# which does no checking of the format of the 'From' line.
|
||||||
|
|
||||||
_fromlinepattern = r"From \s*[^\s]+\s+\w\w\w\s+\w\w\w\s+\d?\d\s+" \
|
_fromlinepattern = (r"From \s*[^\s]+\s+\w\w\w\s+\w\w\w\s+\d?\d\s+"
|
||||||
r"\d?\d:\d\d(:\d\d)?(\s+[^\s]+)?\s+\d\d\d\d\s*$"
|
r"\d?\d:\d\d(:\d\d)?(\s+[^\s]+)?\s+\d\d\d\d\s*"
|
||||||
|
r"[^\s]*\s*"
|
||||||
|
"$")
|
||||||
_regexp = None
|
_regexp = None
|
||||||
|
|
||||||
def _strict_isrealfromline(self, line):
|
def _strict_isrealfromline(self, line):
|
||||||
|
|
|
||||||
|
|
@ -109,11 +109,44 @@ class MaildirTestCase(unittest.TestCase):
|
||||||
self.assertEqual(len(str(msg)), len(FROM_)+len(DUMMY_MESSAGE))
|
self.assertEqual(len(str(msg)), len(FROM_)+len(DUMMY_MESSAGE))
|
||||||
self.assertEqual(n, 1)
|
self.assertEqual(n, 1)
|
||||||
|
|
||||||
|
class MboxTestCase(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
# create a new maildir mailbox to work with:
|
||||||
|
self._path = test_support.TESTFN
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
os.unlink(self._path)
|
||||||
|
|
||||||
|
def test_from_regex (self):
|
||||||
|
# Testing new regex from bug #1633678
|
||||||
|
f = open(self._path, 'w')
|
||||||
|
f.write("""From fred@example.com Mon May 31 13:24:50 2004 +0200
|
||||||
|
Subject: message 1
|
||||||
|
|
||||||
|
body1
|
||||||
|
From fred@example.com Mon May 31 13:24:50 2004 -0200
|
||||||
|
Subject: message 2
|
||||||
|
|
||||||
|
body2
|
||||||
|
From fred@example.com Mon May 31 13:24:50 2004
|
||||||
|
Subject: message 3
|
||||||
|
|
||||||
|
body3
|
||||||
|
From fred@example.com Mon May 31 13:24:50 2004
|
||||||
|
Subject: message 4
|
||||||
|
|
||||||
|
body4
|
||||||
|
""")
|
||||||
|
f.close()
|
||||||
|
box = mailbox.UnixMailbox(open(self._path, 'r'))
|
||||||
|
self.assert_(len(list(iter(box))) == 4)
|
||||||
|
|
||||||
|
|
||||||
# XXX We still need more tests!
|
# XXX We still need more tests!
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
test_support.run_unittest(MaildirTestCase)
|
test_support.run_unittest(MaildirTestCase, MboxTestCase)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue