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

@@ -135,7 +135,7 @@ func TestWrongMailParsing(t *testing.T) {
c := mustDial(t, false)
defer c.Close()
addrs := []string{"", "from", "a b c", "a @ b", "<x>", "<x y>", "><"}
addrs := []string{"from", "a b c", "a @ b", "<x>", "<x y>", "><"}
for _, addr := range addrs {
if err := c.Mail(addr); err == nil {
@@ -158,7 +158,7 @@ func TestNullMailFrom(t *testing.T) {
c := mustDial(t, false)
defer c.Close()
addrs := []string{"<>", " <>", " < > "}
addrs := []string{"", "<>", " <>", " < > "}
for _, addr := range addrs {
if err := c.Text.PrintfLine(addr); err != nil {
t.Fatalf("MAIL FROM failed with addr %q: %v", addr, err)