#14269: smtpd now conforms to the RFC and requires HELO before MAIL.
This is a backward incompatible change, but since it is an RFC conformance bug
and all real mail servers that I know of do conform to the RFC in this regard,
I believe it is an acceptable change for a feature release.
Patch by Jason Killen.
diff --git a/Lib/smtpd.py b/Lib/smtpd.py
index d66b0d7..748fcae 100755
--- a/Lib/smtpd.py
+++ b/Lib/smtpd.py
@@ -374,6 +374,10 @@
return address
def smtp_MAIL(self, arg):
+ if not self.seen_greeting:
+ self.push('503 Error: send HELO first');
+ return
+
print('===> MAIL', arg, file=DEBUGSTREAM)
address = self.__getaddr('FROM:', arg) if arg else None
if not address:
@@ -387,6 +391,10 @@
self.push('250 Ok')
def smtp_RCPT(self, arg):
+ if not self.seen_greeting:
+ self.push('503 Error: send HELO first');
+ return
+
print('===> RCPT', arg, file=DEBUGSTREAM)
if not self.mailfrom:
self.push('503 Error: need MAIL command')
@@ -411,6 +419,10 @@
self.push('250 Ok')
def smtp_DATA(self, arg):
+ if not self.seen_greeting:
+ self.push('503 Error: send HELO first');
+ return
+
if not self.rcpttos:
self.push('503 Error: need RCPT command')
return