all repos — navani @ ba43e00509525ff19367de917574a8270a4a836c

forlater's primary mail processing service

Offload SPF checking to rspamd
Anirudh Oppiliappan x@icyphox.sh
Mon, 20 Sep 2021 11:43:03 +0530
commit

ba43e00509525ff19367de917574a8270a4a836c

parent

ab5222b70d5cb9f64cffeb0485a283040a1a657d

1 files changed, 23 insertions(+), 32 deletions(-)

jump to
M main.gomain.go

@@ -21,46 +21,37 @@ log.Printf("using body as is: %v\n", err)

body = m.Body } - spf, err := mail.VerifySPF(m.From) - if err != nil { - log.Printf("verify spf: %v", err) + urls := mail.ExtractURLs(body) + if len(urls) == 0 { + log.Printf("no urls found") } + for _, u := range distinct(urls) { + log.Printf("url: %s\n", u) + parsedURL, err := url.Parse(u) + if err != nil { + log.Printf("url parse: %v\n", err) + } - if spf { - urls := mail.ExtractURLs(body) - if len(urls) == 0 { - log.Printf("no urls found") + f, err := reader.Fetch(parsedURL.String()) + if err != nil { + log.Printf("reader fetch: %v\n", err) } - for _, u := range distinct(urls) { - log.Printf("url: %s\n", u) - parsedURL, err := url.Parse(u) + + article, err := reader.Readable(f, parsedURL) + if err == nil { + err = mail.SendArticle(&article, m.From, true) if err != nil { - log.Printf("url parse: %v\n", err) + log.Printf("error sending mail to: %s: %v\n", m.From, err) + } else { + log.Printf("sent mail to %s: %s\n", m.From, article.Title) } - - f, err := reader.Fetch(parsedURL.String()) + } else { + log.Printf("not readable: %s\n", err) + err := mail.SendArticle(&article, m.From, false) if err != nil { - log.Printf("reader fetch: %v\n", err) - } - - article, err := reader.Readable(f, parsedURL) - if err == nil { - err = mail.SendArticle(&article, m.From, true) - if err != nil { - log.Printf("error sending mail to: %s: %v\n", m.From, err) - } else { - log.Printf("sent mail to %s: %s\n", m.From, article.Title) - } - } else { - log.Printf("not readable: %s\n", err) - err := mail.SendArticle(&article, m.From, false) - if err != nil { - log.Printf("error sending mail to: %s: %v\n", m.From, err) - } + log.Printf("error sending mail to: %s: %v\n", m.From, err) } } - } else { - log.Printf("bad spf: %s", m.From) } w.WriteHeader(204) })