1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-17 14:37:02 +00:00

chasquid: Make "MAIL FROM" ignore extra parameters

MAIL FROM commands usually come in the form of:

  MAIL FROM:<from@from> BODY=8BITMIME

Note that there's extra parameters after the address, which for now we want to
ignore.

The current parser doesn't ignore them, and relies on mail.ParseAddress doing
so (that is, on mail.ParseAddress("<from> BODY=8BITMIME") working).
However, in go 1.7, the parser will get more strict and start to fail these
cases.

To fix this, we change the way we parse the line to use fmt.Sprintf, which is
much nicer than splitting by hand, and is more readable as well.
This commit is contained in:
Alberto Bertogli
2016-07-20 00:47:45 +01:00
parent 9d172a6ea0
commit ae1c246bde
2 changed files with 14 additions and 8 deletions

View File

@@ -474,23 +474,29 @@ func (c *Conn) NOOP(params string) (code int, msg string) {
}
func (c *Conn) MAIL(params string) (code int, msg string) {
// params should be: "FROM:<name@host>"
// First, get rid of the "FROM:" part (but check it, it's mandatory).
sp := strings.SplitN(strings.ToLower(params), ":", 2)
if len(sp) != 2 || sp[0] != "from" {
// params should be: "FROM:<name@host>", and possibly followed by
// "BODY=8BITMIME" (which we ignore).
// Check that it begins with "FROM:" first, otherwise it's pointless.
if !strings.HasPrefix(strings.ToLower(params), "from:") {
return 500, "unknown command"
}
addr := ""
_, err := fmt.Sscanf(params[5:], "%s ", &addr)
if err != nil {
return 500, "malformed command - " + err.Error()
}
// 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) == "<>" {
if strings.Replace(addr, " ", "", -1) == "<>" {
e.Address = "<>"
} else {
var err error
e, err = mail.ParseAddress(sp[1])
e, err = mail.ParseAddress(addr)
if err != nil || e.Address == "" {
return 501, "malformed address"
}