Python mailbox.UnixMailbox() Examples

The following are 7 code examples of mailbox.UnixMailbox(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module mailbox , or try the search function .
Example #1
Source File: test_old_mailbox.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_from_regex (self):
        # Testing new regex from bug #1633678
        with open(self._path, 'w') as f:
            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
""")
        with open(self._path, 'r') as f:
            box = mailbox.UnixMailbox(f)
            self.assertTrue(len(list(iter(box))) == 4)


    # XXX We still need more tests! 
Example #2
Source File: test_old_mailbox.py    From BinderFilter with MIT License 5 votes vote down vote up
def test_from_regex (self):
        # Testing new regex from bug #1633678
        with open(self._path, 'w') as f:
            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
""")
        with open(self._path, 'r') as f:
            box = mailbox.UnixMailbox(f)
            self.assertTrue(len(list(iter(box))) == 4)


    # XXX We still need more tests! 
Example #3
Source File: test_old_mailbox.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_from_regex (self):
        # Testing new regex from bug #1633678
        with open(self._path, 'w') as f:
            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
""")
        with open(self._path, 'r') as f:
            box = mailbox.UnixMailbox(f)
            self.assertTrue(len(list(iter(box))) == 4)


    # XXX We still need more tests! 
Example #4
Source File: test_old_mailbox.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_from_regex (self):
        # Testing new regex from bug #1633678
        with open(self._path, 'w') as f:
            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
""")
        with open(self._path, 'r') as f:
            box = mailbox.UnixMailbox(f)
            self.assertTrue(len(list(iter(box))) == 4)


    # XXX We still need more tests! 
Example #5
Source File: test_old_mailbox.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
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'))
        messages = list(iter(box))
        self.assert_(len(messages) == 4)
        for message in messages:
            message.fp.close()


    # XXX We still need more tests! 
Example #6
Source File: test_old_mailbox.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
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, 'rb'))
        messages = list(iter(box))
        self.assert_(len(messages) == 4)
        for message in messages:
            message.fp.close()
        box.fp.close() # Jython addition: explicit close needed

    # XXX We still need more tests! 
Example #7
Source File: test_old_mailbox.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
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, 'rb'))
        messages = list(iter(box))
        self.assert_(len(messages) == 4)
        for message in messages:
            message.fp.close()
        box.fp.close() # Jython addition: explicit close needed

    # XXX We still need more tests!