Use the mail body as is if no Content-Type is found
Anirudh Oppiliappan x@icyphox.sh
Fri, 17 Sep 2021 11:09:27 +0530
2 files changed,
19 insertions(+),
3 deletions(-)
M
mail/utils.go
→
mail/utils.go
@@ -11,8 +11,23 @@ type Mail struct {
From string Date string ReplyTo string + Body string Parts map[string]string } + +// TODO +// // Strips the signature from an email. +// func stripSignature(text string) string { +// lines := strings.Split(text, "\n") +// stripped := []string{} +// for i := len(lines) - 1; i >= 0; i-- { +// if lines[i] == "--" || lines[i] == "-- " { +// break +// } +// stripped = append(stripped, lines[i]) +// } +// return strings.Join(stripped, "\n") +// } // Extracts URLs from given text. func ExtractURLs(text string) []string {
M
main.go
→
main.go
@@ -17,7 +17,8 @@ json.NewDecoder(r.Body).Decode(&m)
body, err := mail.MailBody(m.Parts) log.Printf("recieved webhook: %v\n", m.From) if err != nil { - log.Println(err) + log.Printf("using body as is: %v\n", err) + body = m.Body } urls := mail.ExtractURLs(body)@@ -28,12 +29,12 @@ for _, u := range distinct(urls) {
log.Printf("url: %s\n", u) parsedURL, err := url.Parse(u) if err != nil { - log.Printf("url parse: %s\n", err) + log.Printf("url parse: %v\n", err) } f, err := reader.Fetch(parsedURL.String()) if err != nil { - log.Printf("reader fetch: %s\n", err) + log.Printf("reader fetch: %v\n", err) } article, err := reader.Readable(f, parsedURL)