Pipe html into w3m for plaintext
Anirudh Oppiliappan x@icyphox.sh
Tue, 14 Sep 2021 17:15:27 +0530
2 files changed,
20 insertions(+),
1 deletions(-)
M
mail/send.go
→
mail/send.go
@@ -31,12 +31,14 @@ if err != nil {
return err } + plainContent, err := reader.MakePlaintext(htmlContent) + email := mail.New() email.Encryption = mail.EncryptionTLS email.SetFrom(fmt.Sprintf("saved forlater <%s>", EMAIL_FROM)) email.AddTo(to) email.SetSubject(article.Title) - email.SetBody("text/plain", article.TextContent) + email.SetBody("text/plain", string(plainContent)) email.AddAlternative("text/html", string(htmlContent)) email.Username = EMAIL_USER_SECRET email.Password = EMAIL_PASSWORD
A
reader/plain.go
@@ -0,0 +1,17 @@
+package reader + +import ( + "os/exec" + "strings" +) + +func MakePlaintext(html []byte) ([]byte, error) { + args := []string{"-T", "text/html", "-dump"} + cmd := exec.Command("w3m", args...) + cmd.Stdin = strings.NewReader(string(html)) + out, err := cmd.Output() + if err != nil { + return nil, err + } + return out, nil +}