mhale / smtpd

An SMTP server package written in Go, in the style of the built-in HTTP server.
The Unlicense
397 stars 92 forks source link

From and To addresses with leading spaces #18

Closed patrick-acst closed 4 years ago

patrick-acst commented 4 years ago

We found that two of our systems are unable to send emails to our service that uses smtpd as the smtp handler. Tracking it down to the errors for 'invalid FROM parameter' and 'invalid TO parameter'. Found that updating the regex to allow for a single space handles this and then trimmed the addresses as they were added. I was hoping this could be evaluated and added so that we don't have to use a custom fork. Had issues making a PR so adding the code changes here. Thank you.

26:rcptToRE = regexp.MustCompile(`[Tt][Oo]:\s?<(.+)>`) 27:mailFromRE = regexp.MustCompile(`[Ff][Rr][Oo][Mm]:\s?<(.*)>(\s(.*))?`) // Delivery Status Notifications are sent with "MAIL FROM:<>" 294:from = strings.TrimSpace(match[1]) 334:to = append(to, strings.TrimSpace(match[1]))

Ruxton commented 4 years ago

Just wanted to point out that your two systems are not adhering to the specification.

You should probably be fixing it at that end.

mhale commented 4 years ago

I agree with @Ruxton that it is better to fix this in the sending code.

However, since you provided a patch and asked nicely, I've made the regex changes and added test coverage. Double spaces will still be rejected. Trimming the strings is unnecessary since the space is not part of the subpattern.

patrick-acst commented 4 years ago

I figured it was an issue with the software since it's the only two out of many that have issues but unfortunately we don't have control over how they send out email since they are purchased software packages. I appreciate the update.