[issue25553] SMTP.data(msg) function may cause the last CRLF of msg lost if msg is quoted-printable encoding.

Deli Zhang report at bugs.python.org
Thu Nov 5 01:51:55 EST 2015


New submission from Deli Zhang:

It's well known that in quoted-printable encoding the "CRLF" can be encoded to "=CRLF".
For example, in attachment file test.eml, the last line is "test message.=CRLF"
But after the mail is sent via SMTP and received by mail server (e.g. postfix), the last line will become "test message.=", 
then after decoding, you will see the unnecessary char "=" shown following "test message.".

The problem is caused by below code:
------------------------------------------------
class SMTP:
    ...
    def data(self, msg):
        ...
            q = quotedata(msg)
            if q[-2:] != CRLF:
                q = q + CRLF
            q = q + "." + CRLF
            self.send(q)
        ...
------------------------------------------------
Before it sends the message q, it will try to append the end-of-data sequence "<CRLF>.<CRLF>". 
As the implement, it checks whether there is "<CRLF>" in the message end, if yes then just need to append ".<CRLF>".
It looks rigorous and efficient, but it does not consider how mail server handle it.
As we know mail server will remove end-of-data sequence directly, and the left message is treat as mail data.

Thus the corresponding action should be taken on SMTP client side,
it's to say no need to check and just append end-of-data sequence here:
------------------------------------------------
class SMTP:
    ...
    def data(self, msg):
        ...
            q = quotedata(msg)
            q = q + CRLF + "." + CRLF
            self.send(q)
        ...
------------------------------------------------

----------
components: Library (Lib)
files: test.eml
messages: 254086
nosy: Deli Zhang
priority: normal
severity: normal
status: open
title: SMTP.data(msg) function may cause the last CRLF of msg lost if msg is quoted-printable encoding.
type: behavior
versions: Python 2.7
Added file: http://bugs.python.org/file40944/test.eml

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25553>
_______________________________________


More information about the Python-bugs-list mailing list