FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.14] gh-49680: Test imaplib.IMAP4.append line-ending normalization (GH-152877) by miss-islington · Pull Request #152878 · python/cpython · GitHub

/ cpython Public
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
34 changes: 28 additions & 6 deletions Lib/test/test_imaplib.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import calendar
import threading
import re
import select
import socket

from test.support import verbose, run_with_tz, run_with_locale, cpython_only
Expand Down Expand Up @@ -90,6 +91,18 @@ class Handler(SimpleIMAPHandler):
return Handler


def _read_literal(handler, marker):
# Read one literal, a raw octet sequence, by its count from the marker
# ('{N}', or '(~{N}' in UTF8 mode).
size = int(re.search(r'\{(\d+)\}', marker).group(1))
# The client must wait for the continuation, so nothing should be readable.
if select.select([handler.connection], [], [], 0)[0]:
raise AssertionError('client sent the literal before the '
'continuation request')
handler._send_textline('+')
return handler.rfile.read(size)


class TestImaplib(unittest.TestCase):

def test_Internaldate2tuple(self):
Expand Down Expand Up @@ -475,10 +488,8 @@ def cmd_AUTHENTICATE(self, tag, args):
self.server.response = yield
self._send_tagged(tag, 'OK', 'FAKEAUTH successful')
def cmd_APPEND(self, tag, args):
self._send_textline('+')
self.server.response = args
literal = yield
self.server.response.append(literal)
self.server.response.append(_read_literal(self, args[-1]))
literal = yield
self.server.response.append(literal)
self._send_tagged(tag, 'OK', 'okay')
Expand Down Expand Up @@ -743,6 +754,19 @@ def test_login(self):
self.assertEqual(data[0], b'LOGIN completed')
self.assertEqual(client.state, 'AUTH')

def test_append_line_endings(self):
# append() normalizes bare CR and LF in the message to CRLF.
class AppendHandler(SimpleIMAPHandler):
def cmd_APPEND(self, tag, args):
self.server.response = _read_literal(self, args[-1])
yield # read the trailer line
self._send_tagged(tag, 'OK', 'APPEND completed')
client, server = self._setup(AppendHandler)
client.login('user', 'pass')
message = b'a\rb\nc\r\nd'
client.append('INBOX', None, None, message)
self.assertEqual(server.response, b'a\r\nb\r\nc\r\nd')

def test_login_capabilities(self):
# A server may advertise new capabilities after login (as an
# untagged CAPABILITY response); imaplib must refresh its cached
Expand Down Expand Up @@ -1651,10 +1675,8 @@ def test_enable_UTF8_True_append(self):

class UTF8AppendServer(self.UTF8Server):
def cmd_APPEND(self, tag, args):
self._send_textline('+')
self.server.response = args
literal = yield
self.server.response.append(literal)
self.server.response.append(_read_literal(self, args[-1]))
literal = yield
self.server.response.append(literal)
self._send_tagged(tag, 'OK', 'okay')
Expand Down
Loading

Back | FazBrowse Home | New Git URL