Issue 29860: smtplib.py doesn't capitalize EHLO. (original) (raw)

Created on 2017-03-20 14:32 by Lord Anton Hvornum, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (7)
msg289886 - (view) Author: Lord Anton Hvornum (Lord Anton Hvornum) Date: 2017-03-20 14:32
``` File "mail.py", line 9, in smtp_server.starttls(context) File "/usr/lib/python3.6/smtplib.py", line 748, in starttls self.ehlo_or_helo_if_needed() File "/usr/lib/python3.6/smtplib.py", line 600, in ehlo_or_helo_if_needed (code, resp) = self.helo() File "/usr/lib/python3.6/smtplib.py", line 429, in helo (code, msg) = self.getreply() File "/usr/lib/python3.6/smtplib.py", line 393, in getreply raise SMTPServerDisconnected("Connection unexpectedly closed") ``` This happens due to the server expecting commands (like EHLO, STARTTLS) being strict upper-case. And when the SMTP command isn't, it drops us. This is a rare edge case since most mail servers handles shady client data in numerous different ways (such as gmail never sending QUIT for instance). I don't know of a work-around for this and the documentation states `EHLO` is being sent (https://docs.python.org/3/library/smtplib.html), so I guess the lib assumes that's the case as well.
msg289888 - (view) Author: Lord Anton Hvornum (Lord Anton Hvornum) Date: 2017-03-20 14:59
Turns out, this goes for a lot more commands, such as: ``` Traceback (most recent call last): File "mail.py", line 12, in smtp_server.sendmail(fromaddr, toaddrs, msg) File "/usr/lib/python3.6/smtplib.py", line 866, in sendmail raise SMTPSenderRefused(code, resp, from_addr) ``` The command that the server refused was: mail FROM:<my_mail@gmail.com> size=11 Again, this is mostly because traditionally server commands are upper case (even tho RFC 821 defines that they can be any syntax, such as `mAiL FroM`). But it would be nice if Python could keep consistency in it's syntax IMHO.
msg289889 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-03-20 15:07
It is interesting that in all the years smtplib has been in use, this is the first time (as far as I know) this has been reported as a problem. I don't see any reason to object to changing it to send the commands in upper case, but the server you are talking to is definitely out of spec with the RFC :)
msg289890 - (view) Author: Lord Anton Hvornum (Lord Anton Hvornum) Date: 2017-03-20 15:10
Seeing as I'm the one who built the server, it sure is out of spec :) I could also quickly correct for this "issue" server-side. So this is more of a "style guideline" change client-side - If no one opposes of keeping commands stylistically the same.
msg289891 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-03-20 16:51
On the other hand, the current mixed case sending found a bug in your code, so it has some value. I'm neither in favor nor in objection to the change, at this point.
msg289907 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2017-03-20 23:16
Is EHLO the only command sent in lower case? I think it might not be. I suppose I'm a solid ±0 on changing this (how's that for a completely neutral endorsement?). I won't do the change myself, but I'd review a pull request.
msg410916 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-01-18 23:47
It's been 5 years, it's not really a bug, and nobody seems to be interested enough to submit a patch so I'm closing this. Feel free to reopen if you want to pursue this.
History
Date User Action Args
2022-04-11 14:58:44 admin set github: 74046
2022-01-18 23:47:55 iritkatriel set status: open -> closednosy: + iritkatrielmessages: + resolution: not a bugstage: resolved
2020-12-22 15:24:00 rahul-kumi set nosy: + rahul-kumi
2017-04-04 20:09:22 maciej.szulik set nosy: + maciej.szulik
2017-03-20 23:16:41 barry set messages: +
2017-03-20 16:51:41 r.david.murray set messages: +
2017-03-20 15:10:53 Lord Anton Hvornum set messages: +
2017-03-20 15:07:54 r.david.murray set nosy: + barry, r.david.murraymessages: + components: + email
2017-03-20 14:59:16 Lord Anton Hvornum set messages: +
2017-03-20 14:32:53 Lord Anton Hvornum create