go-guerrilla icon indicating copy to clipboard operation
go-guerrilla copied to clipboard

Email address parser

Open 4k7 opened this issue 5 years ago • 2 comments

Hi,

If the email address with quotes in the name is parsed (for example, "Gogh Fir" <[email protected]>), then the flag Quoted will be set, indicates then the local-part needs quotes too. As a result, String () will return "tesst" @ test.com.

This is due to the fact that the QcontentSMTP () function is called when parsing the name in quotation marks and mistakenly sets the flag for local part.

Thanks.

package main

import (
	"log"
	"github.com/flashmob/go-guerrilla/mail"
)

func main() {
	addr, err := mail.NewAddress(`"Gogh Fir" <[email protected]>`)
	if err == nil {
		log.Println(addr.DisplayName)
		log.Println(addr.String())
	}
}

Gogh Fir "tesst"@test.com

4k7 avatar Apr 26 '20 01:04 4k7

Thanks for reporting this! It's a bug that needs to be addressed. Would you be interested in submitting a PR?

On Sun, 26 Apr 2020, 10:45 int01, [email protected] wrote:

Hi,

If the email address with quotes in the name is parsed (for example, "Gogh Fir" [email protected]), then the flag Quoted will be set, indicates then the local-part needs quotes too. As a result, String () will return "tesst" @ test.com.

This is due to the fact that the QcontentSMTP () function is called when parsing the name in quotation marks and mistakenly sets the flag for local part.

Thanks.

package main

import ( "log" "github.com/flashmob/go-guerrilla/mail" )

func main() { addr, err := mail.NewAddress("Gogh Fir" <[email protected]>) if err == nil { log.Println(addr.DisplayName) log.Println(addr.String()) } }

Gogh Fir "tesst"@test.com

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/flashmob/go-guerrilla/issues/207, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAE6MP5ZLNSTY4L57W6VDLTROOG3DANCNFSM4MRAEH4Q .

flashmob avatar Apr 26 '20 02:04 flashmob

It seems enough in the file "address.go" in the displayName() function add s.LocalPartQuotes = false.

func (s *RFC5322) displayName() error {
	defer func() {
		if s.accept.Len() > 0 {
			s.addr.DisplayName = s.accept.String()
			s.accept.Reset()
			s.LocalPartQuotes = false // !!! THIS LINE !!!
		}
	}()
	// phrase
	if err := s.word(); err != nil {
		return err
	}
	for {
		err := s.word()
		if err != nil {
			return nil
		}
	}
}

4k7 avatar Apr 26 '20 14:04 4k7