|  | 
| 34 | 34 | import time | 
| 35 | 35 | from datetime import datetime, timezone, timedelta | 
| 36 | 36 | from io import DEFAULT_BUFFER_SIZE | 
|  | 37 | +import warnings | 
| 37 | 38 | 
 | 
| 38 | 39 | try: | 
| 39 | 40 |     import ssl | 
| @@ -323,7 +324,22 @@ def open(self, host='', port=IMAP4_PORT, timeout=None): | 
| 323 | 324 |         self.host = host | 
| 324 | 325 |         self.port = port | 
| 325 | 326 |         self.sock = self._create_socket(timeout) | 
| 326 |  | -        self.file = self.sock.makefile('rb') | 
|  | 327 | +        self._file = self.sock.makefile('rb') | 
|  | 328 | + | 
|  | 329 | + | 
|  | 330 | +    @property | 
|  | 331 | +    def file(self): | 
|  | 332 | +        # The old 'file' attribute is no longer used now that we do our own | 
|  | 333 | +        # read() and readline() buffering, with which it conflicts. | 
|  | 334 | +        # As an undocumented interface, it should never have been accessed by | 
|  | 335 | +        # external code, and therefore does not warrant deprecation. | 
|  | 336 | +        # Nevertheless, we provide this property for now, to avoid suddenly | 
|  | 337 | +        # breaking any code in the wild that might have been using it in a | 
|  | 338 | +        # harmless way. | 
|  | 339 | +        warnings.warn( | 
|  | 340 | +            'IMAP4.file is unsupported, can cause errors, and may be removed.', | 
|  | 341 | +            RuntimeWarning) | 
|  | 342 | +        return self._file | 
| 327 | 343 | 
 | 
| 328 | 344 | 
 | 
| 329 | 345 |     def read(self, size): | 
| @@ -383,7 +399,7 @@ def send(self, data): | 
| 383 | 399 | 
 | 
| 384 | 400 |     def shutdown(self): | 
| 385 | 401 |         """Close I/O established in "open".""" | 
| 386 |  | -        self.file.close() | 
|  | 402 | +        self._file.close() | 
| 387 | 403 |         try: | 
| 388 | 404 |             self.sock.shutdown(socket.SHUT_RDWR) | 
| 389 | 405 |         except OSError as exc: | 
| @@ -883,7 +899,7 @@ def starttls(self, ssl_context=None): | 
| 883 | 899 |         if typ == 'OK': | 
| 884 | 900 |             self.sock = ssl_context.wrap_socket(self.sock, | 
| 885 | 901 |                                                 server_hostname=self.host) | 
| 886 |  | -            self.file = self.sock.makefile('rb') | 
|  | 902 | +            self._file = self.sock.makefile('rb') | 
| 887 | 903 |             self._tls_established = True | 
| 888 | 904 |             self._get_capabilities() | 
| 889 | 905 |         else: | 
| @@ -1629,7 +1645,7 @@ def open(self, host=None, port=None, timeout=None): | 
| 1629 | 1645 |         self.host = None        # For compatibility with parent class | 
| 1630 | 1646 |         self.port = None | 
| 1631 | 1647 |         self.sock = None | 
| 1632 |  | -        self.file = None | 
|  | 1648 | +        self._file = None | 
| 1633 | 1649 |         self.process = subprocess.Popen(self.command, | 
| 1634 | 1650 |             bufsize=DEFAULT_BUFFER_SIZE, | 
| 1635 | 1651 |             stdin=subprocess.PIPE, stdout=subprocess.PIPE, | 
|  | 
0 commit comments