summaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
authorPetri Lehtinen <petri@digip.org>2012-08-15 14:22:46 +0300
committerPetri Lehtinen <petri@digip.org>2012-08-15 14:25:41 +0300
commit2d44ceeada8840185217c7de826622d8372ceb00 (patch)
tree320a05c67d0bfb63661aa4aee5f9c39d0bf3a390 /Lib
parentbecfcc0a6bbfa507049260b29d8ffc2f334dfcc0 (diff)
downloadcpython-git-2d44ceeada8840185217c7de826622d8372ceb00.tar.gz
#11062: Fix adding a message from file to Babyl mailbox
Diffstat (limited to 'Lib')
-rw-r--r--Lib/mailbox.py2
-rw-r--r--Lib/test/test_mailbox.py13
2 files changed, 14 insertions, 1 deletions
diff --git a/Lib/mailbox.py b/Lib/mailbox.py
index 61683674ff..3fe0ce4288 100644
--- a/Lib/mailbox.py
+++ b/Lib/mailbox.py
@@ -1386,9 +1386,9 @@ class Babyl(_singlefileMailbox):
line = message.readline()
self._file.write(line.replace('\n', os.linesep))
if line == '\n' or line == '':
- self._file.write('*** EOOH ***' + os.linesep)
if first_pass:
first_pass = False
+ self._file.write('*** EOOH ***' + os.linesep)
message.seek(original_pos)
else:
break
diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py
index d479bf85f1..5069aac77d 100644
--- a/Lib/test/test_mailbox.py
+++ b/Lib/test/test_mailbox.py
@@ -8,6 +8,7 @@ import email.message
import re
import shutil
import StringIO
+import tempfile
from test import test_support
import unittest
import mailbox
@@ -75,6 +76,18 @@ class TestMailbox(TestBase):
for i in (1, 2, 3, 4):
self._check_sample(self._box[keys[i]])
+ def test_add_file(self):
+ with tempfile.TemporaryFile('w+') as f:
+ f.write(_sample_message)
+ f.seek(0)
+ key = self._box.add(f)
+ self.assertEqual(self._box.get_string(key).split('\n'),
+ _sample_message.split('\n'))
+
+ def test_add_StringIO(self):
+ key = self._box.add(StringIO.StringIO(self._template % "0"))
+ self.assertEqual(self._box.get_string(key), self._template % "0")
+
def test_remove(self):
# Remove messages using remove()
self._test_remove_or_delitem(self._box.remove)