allow publishing of text/html emails
This commit is contained in:
parent
5f75e98861
commit
893360da28
4 changed files with 89 additions and 3 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"github.com/emersion/go-smtp"
|
||||
"github.com/k3a/html2text"
|
||||
"io"
|
||||
"mime"
|
||||
"mime/multipart"
|
||||
|
@ -218,6 +219,8 @@ func readMailBody(body io.Reader, header mail.Header) (string, error) {
|
|||
}
|
||||
if strings.ToLower(contentType) == "text/plain" {
|
||||
return readPlainTextMailBody(body, header.Get("Content-Transfer-Encoding"))
|
||||
} else if strings.ToLower(contentType) == "text/html" {
|
||||
return readHTMLMailBody(body, header.Get("Content-Transfer-Encoding"))
|
||||
} else if strings.HasPrefix(strings.ToLower(contentType), "multipart/") {
|
||||
return readMultipartMailBody(body, params, 0)
|
||||
}
|
||||
|
@ -257,3 +260,15 @@ func readPlainTextMailBody(reader io.Reader, transferEncoding string) (string, e
|
|||
}
|
||||
return string(body), nil
|
||||
}
|
||||
|
||||
func readHTMLMailBody(reader io.Reader, transferEncoding string) (string, error) {
|
||||
if strings.ToLower(transferEncoding) == "base64" {
|
||||
reader = base64.NewDecoder(base64.StdEncoding, reader)
|
||||
}
|
||||
html, err := io.ReadAll(reader)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
body := html2text.HTML2Text(string(html))
|
||||
return string(body), nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue