Skip to content

Commit fcb6d6a

Browse files
committed
#17443: Fix buffering in IMAP4_stream.
In Python2 Popen uses *FILE objects, which wind up buffering even though subprocess defaults to no buffering. In Python3, subprocess streams really are unbuffered by default, but the imaplib code assumes read is buffered. This patch uses the default buffer size from the io module to get buffered streams from Popen. Much debugging work and patch by Diane Trout. The imap protocol is too complicated to write a test for this simple change with our current level of test infrastructure.
1 parent ae4ef4d commit fcb6d6a

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

Lib/imaplib.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
__version__ = "2.58"
2424

2525
import binascii, errno, random, re, socket, subprocess, sys, time, calendar
26+
from io import DEFAULT_BUFFER_SIZE
2627

2728
try:
2829
import ssl
@@ -1237,6 +1238,7 @@ def open(self, host = None, port = None):
12371238
self.sock = None
12381239
self.file = None
12391240
self.process = subprocess.Popen(self.command,
1241+
bufsize=DEFAULT_BUFFER_SIZE,
12401242
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
12411243
shell=True, close_fds=True)
12421244
self.writefile = self.process.stdin

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,7 @@ Richard Townsend
10981098
Nathan Trapuzzano
10991099
Laurence Tratt
11001100
John Tromp
1101+
Diane Trout
11011102
Jason Trowbridge
11021103
Brent Tubbs
11031104
Anthony Tuininga

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ Core and Builtins
233233
Library
234234
-------
235235

236+
- Issue #17443: impalib.IMAP4_stream was using the default unbuffered IO
237+
in subprocess, but the imap code assumes buffered IO. In Python2 this
238+
worked by accident. IMAP4_stream now explicitly uses buffered IO.
239+
236240
- Issue #17476: Fixed regression relative to Python2 in undocumented pydoc
237241
'allmethods'; it was missing unbound methods on the class.
238242

0 commit comments

Comments
 (0)