@@ -135,25 +135,31 @@ func mailProcessor(req *Request) error {
135135 return req .TextProto .PrintfLine ("%d %s" , 501 , "MAIL command contained invalid address" )
136136 }
137137
138- // extraxt the from email address
139- from := emailRegExp .FindStringSubmatch (req .Line [1 ][i + 1 :])[1 ]
140- fromParts := strings .SplitN (from , "@" , 2 )
138+ req .MailFromReceived = true
141139
140+ // extract the from email address
141+ fromParts := emailRegExp .FindStringSubmatch (strings .TrimSpace (req .Line [1 ][i + 1 :]))
142+
143+ from := fromParts [1 ]
142144 req .From = from
143- ip , _ , _ := net .SplitHostPort (req .RemoteAddr )
144145
145- // check the spf result
146- req .SPFResult , _ , _ = spf .CheckHost (net .ParseIP (ip ), fromParts [1 ], from )
146+ if from != "" {
147+ ip , _ , _ := net .SplitHostPort (req .RemoteAddr )
148+
149+ // check the spf result
150+ domain := fromParts [3 ]
151+ req .SPFResult , _ , _ = spf .CheckHost (net .ParseIP (ip ), domain , from )
147152
148- // check the mx records of the from hostname
149- mxs , err := net .LookupMX (fromParts [1 ])
150- req .Mailable = (err == nil ) && len (mxs ) > 0
153+ // check the mx records of the from hostname
154+ mxs , err := net .LookupMX (domain )
155+ req .Mailable = (err == nil ) && len (mxs ) > 0
156+ }
151157
152158 return req .TextProto .PrintfLine ("%d %s" , 250 , "Ok" )
153159}
154160
155161func rcptProcessor (req * Request ) error {
156- if req .From == "" {
162+ if ! req .MailFromReceived {
157163 return req .TextProto .PrintfLine ("%d %s" , 503 , "Bad sequence of commands" )
158164 }
159165 if len (req .Line ) < 2 {
@@ -177,7 +183,7 @@ func rcptProcessor(req *Request) error {
177183}
178184
179185func dataProcessor (req * Request ) error {
180- if req .To == nil || req .From == "" || len ( req .To ) == 0 {
186+ if req .To == nil || len ( req .To ) == 0 || ! req .MailFromReceived {
181187 return req .TextProto .PrintfLine ("%d %s" , 503 , "Bad sequence of commands" )
182188 }
183189 err := req .TextProto .PrintfLine ("%d %s" , 354 , "End data with <CR><LF>.<CR><LF>" )
0 commit comments