all repos — navani @ 8836f20495e17361d15b1da6eb7bc4c6f2cd063c

forlater's primary mail processing service

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
commit

8836f20495e17361d15b1da6eb7bc4c6f2cd063c

parent

f2a4424f62c16474a01d8313cff63d0aa9e9e8fc

2 files changed, 19 insertions(+), 3 deletions(-)

jump to
M mail/utils.gomail/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.gomain.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)