Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Lib/imaplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@
br'"')
# Literal is no longer used; kept for backward compatibility.
Literal = re.compile(br'.*{(?P<size>\d+)}$', re.ASCII)
MapCRLF = re.compile(br'\r\n|\r|\n')

@JulienPalard JulienPalard Sep 13, 2019

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In any cases, please don't remove it, one may be using it, please do as the previous Literal one, keep it but state it's no longer used and kept for backward compatibility.

# We no longer exclude the ']' character from the data portion of the response
# code, even though it violates the RFC. Popular IMAP servers such as Gmail
# allow flags with ']', and there are programs (including imaplib!) that can
Expand Down Expand Up @@ -396,7 +395,7 @@ def append(self, mailbox, flags, date_time, message):
date_time = Time2Internaldate(date_time)
else:
date_time = None
literal = MapCRLF.sub(CRLF, message)
literal = message
if self.utf8_enabled:
literal = b'UTF8 (' + literal + b')'
self.literal = literal
Expand Down
19 changes: 19 additions & 0 deletions Lib/test/test_imaplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,28 @@
CERTFILE = os.path.join(os.path.dirname(__file__) or os.curdir, "keycert3.pem")
CAFILE = os.path.join(os.path.dirname(__file__) or os.curdir, "pycacert.pem")

class DummyIMAP(imaplib.IMAP4):

def __init__(self):
"""Skip connections, for testing."""
self.utf8_enabled = False

def _simple_command(self, name, *args):
"""Return self.literal, for testing methods affecting literal."""
return self.literal


class TestImaplib(unittest.TestCase):

# CR, LF in literal should not be replaced by CRLF, issue 5430
def test_cr_lf_literal_preservation(self):
dummy_imap = DummyIMAP()
msg_string = 'one\rtwo\nthree\r\n'
result = dummy_imap.append(
None, None, None, msg_string.encode('utf-8'))

self.assertEqual(str.encode(msg_string), result)

def test_Internaldate2tuple(self):
t0 = calendar.timegm((2000, 1, 1, 0, 0, 0, -1, -1, -1))
tt = imaplib.Internaldate2tuple(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Preserve LF, CR in the ``imaplib.IMAP4.append`` method.