Merge pull request #163 from cathugger/master
srnd: properly parse email addresses
This commit is contained in:
commit
22eb29c8ee
@ -295,12 +295,20 @@ func (self *nntpArticle) Newsgroup() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *nntpArticle) Name() string {
|
func (self *nntpArticle) Name() string {
|
||||||
from := self.headers.Get("From", "anonymous <a@no.n>")
|
const defname = "Anonymous"
|
||||||
idx := strings.Index(from, "<")
|
from := strings.TrimSpace(self.headers.Get("From", ""))
|
||||||
if idx > 1 {
|
if from == "" {
|
||||||
return from[:idx]
|
return defname
|
||||||
}
|
}
|
||||||
return "[Invalid From header]"
|
a, e := mail.ParseAddress(from)
|
||||||
|
if e != nil {
|
||||||
|
return fmt.Sprintf("[Invalid From header: %v]", e)
|
||||||
|
}
|
||||||
|
name := strings.TrimSpace(a.Name)
|
||||||
|
if name == "" {
|
||||||
|
return defname
|
||||||
|
}
|
||||||
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *nntpArticle) Addr() (addr string) {
|
func (self *nntpArticle) Addr() (addr string) {
|
||||||
@ -327,13 +335,15 @@ func (self *nntpArticle) Addr() (addr string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *nntpArticle) Email() string {
|
func (self *nntpArticle) Email() string {
|
||||||
from := self.headers.Get("From", "anonymous <a@no.n>")
|
from := strings.TrimSpace(self.headers.Get("From", ""))
|
||||||
idx := strings.Index(from, "<")
|
if from == "" {
|
||||||
if idx > 2 {
|
return ""
|
||||||
return from[:idx-2]
|
|
||||||
}
|
}
|
||||||
return "[Invalid From header]"
|
a, e := mail.ParseAddress(from)
|
||||||
|
if e != nil {
|
||||||
|
return fmt.Sprintf("[Invalid From header: %v]", e)
|
||||||
|
}
|
||||||
|
return a.Address
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *nntpArticle) Subject() string {
|
func (self *nntpArticle) Subject() string {
|
||||||
|
Reference in New Issue
Block a user