From ca9c366087b8891d98a4f1b34d655f491b13bb87 Mon Sep 17 00:00:00 2001 From: Alberto Bertogli Date: Mon, 26 Oct 2015 02:30:25 +0000 Subject: [PATCH] Handle null reverse paths ("MAIL FROM:<>") Null reverse paths are explicitly allowed, and used when sending delivery notifications (https://tools.ietf.org/html/rfc2821#section-4.5.5). --- chasquid.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/chasquid.go b/chasquid.go index 24e6cbb..12822c0 100644 --- a/chasquid.go +++ b/chasquid.go @@ -263,14 +263,27 @@ func (c *Conn) MAIL(params string) (code int, msg string) { return 500, "unknown command" } - e, err := mail.ParseAddress(sp[1]) - if err != nil || e.Address == "" { - return 501, "malformed address" + // Special case a null reverse-path, which is explicitly allowed and used + // for notification messages. + // It should be written "<>", we check for that and remove spaces just to + // be more flexible. + e := &mail.Address{} + if strings.Replace(sp[1], " ", "", -1) == "<>" { + e.Address = "<>" + } else { + var err error + e, err = mail.ParseAddress(sp[1]) + if err != nil || e.Address == "" { + return 501, "malformed address" + } + + if !strings.Contains(e.Address, "@") { + return 501, "sender address must contain a domain" + } } - if !strings.Contains(e.Address, "@") { - return 501, "sender address must contain a domain" - } + // Note some servers check (and fail) if we had a previous MAIL command, + // but that's not according to the RFC. We reset the envelope instead. c.resetEnvelope() c.mail_from = e.Address