all repos — navani @ 8fa6f8f5661a8f116048e75a54e07db69e3f8f7a

forlater's primary mail processing service

Pipe html into w3m for plaintext
Anirudh Oppiliappan x@icyphox.sh
Tue, 14 Sep 2021 17:15:27 +0530
commit

8fa6f8f5661a8f116048e75a54e07db69e3f8f7a

parent

a19bec824e09eb9de02066e7ea79e6a8c4342b6b

2 files changed, 20 insertions(+), 1 deletions(-)

jump to
M mail/send.gomail/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 +}