all repos — navani @ cb68ef039193a74e8c300c33a3f9a19e9f9ef309

forlater's primary mail processing service

Strip signature (best guess) from email
Anirudh Oppiliappan x@icyphox.sh
Wed, 29 Sep 2021 16:32:32 +0530
commit

cb68ef039193a74e8c300c33a3f9a19e9f9ef309

parent

ea8ad151310499d429bb7aa02cdb4acdac813db0

1 files changed, 13 insertions(+), 12 deletions(-)

jump to
M mail/utils.gomail/utils.go

@@ -2,6 +2,7 @@ package mail

import ( "fmt" + "strings" "github.com/microcosm-cc/bluemonday" "mvdan.cc/xurls/v2"

@@ -16,18 +17,18 @@ 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") -// } +// Strips the signature from an email. +func stripSignature(text string) string { + lines := strings.Split(text, "\n") + body := []string{} + for i := range lines { + body = append(body, lines[i]) + if lines[i] == "--" || lines[i] == "-- " { + break + } + } + return strings.Join(body, "\n") +} // Extracts URLs from given text. func ExtractURLs(text string) []string {