Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: missing email cause error
  • Loading branch information
unliar committed Feb 27, 2025
commit 4900d3dd69362334c51c05f10b83e8eff4e1c19d
16 changes: 13 additions & 3 deletions rss.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package feeds
import (
"encoding/xml"
"fmt"
"net/mail"
"time"
)

Expand Down Expand Up @@ -135,9 +136,13 @@ func (r *Rss) RssFeed() *RssFeed {
build := anyTimeFormat(time.RFC1123Z, r.Updated)
author := ""
if r.Author != nil {
author = r.Author.Email
if len(r.Author.Name) > 0 {
author = fmt.Sprintf("%s (%s)", r.Author.Email, r.Author.Name)
// check if email is valid
email := r.Author.Email
if isValidEmail(email) {
author = email
if len(r.Author.Name) > 0 {
author = fmt.Sprintf("%s (%s)", r.Author.Email, r.Author.Name)
}
}
}

Expand Down Expand Up @@ -181,3 +186,8 @@ func (r *RssFeed) FeedXml() interface{} {
ContentNamespace: "http://purl.org/rss/1.0/modules/content/",
}
}

func isValidEmail(email string) bool {
_, err := mail.ParseAddress(email)
return err == nil
}
Loading