diff options
Diffstat (limited to 'plugins/base')
-rw-r--r-- | plugins/base/routes.go | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/plugins/base/routes.go b/plugins/base/routes.go index 2107abb..0345189 100644 --- a/plugins/base/routes.go +++ b/plugins/base/routes.go @@ -14,12 +14,13 @@ import ( "git.sr.ht/~emersion/alps" "github.com/emersion/go-imap" - imapmove "github.com/emersion/go-imap-move" - imapclient "github.com/emersion/go-imap/client" "github.com/emersion/go-message" "github.com/emersion/go-message/mail" "github.com/emersion/go-smtp" "github.com/labstack/echo/v4" + "jaytaylor.com/html2text" + imapclient "github.com/emersion/go-imap/client" + imapmove "github.com/emersion/go-imap-move" ) func registerRoutes(p *alps.GoPlugin) { @@ -759,17 +760,25 @@ func handleReply(ctx *alps.Context) error { return fmt.Errorf("failed to parse part Content-Type: %v", err) } - if !strings.EqualFold(mimeType, "text/plain") { - err := fmt.Errorf("cannot reply to %q part", mimeType) + if mimeType == "text/plain" { + msg.Text, err = quote(part.Body) + if err != nil { + return err + } + } else if mimeType == "text/html" { + text, err := html2text.FromReader(part.Body, html2text.Options{}) + if err != nil { + return err + } + msg.Text, err = quote(strings.NewReader(text)) + if err != nil { + return nil + } + } else { + err := fmt.Errorf("cannot forward %q part", mimeType) return echo.NewHTTPError(http.StatusBadRequest, err) } - // TODO: strip HTML tags if text/html - msg.Text, err = quote(part.Body) - if err != nil { - return err - } - msg.MessageID = mail.GenerateMessageID() msg.InReplyTo = inReplyTo.Envelope.MessageId // TODO: populate From from known user addresses and inReplyTo.Envelope.To @@ -819,16 +828,21 @@ func handleForward(ctx *alps.Context) error { return fmt.Errorf("failed to parse part Content-Type: %v", err) } - if !strings.EqualFold(mimeType, "text/plain") { + if mimeType == "text/plain" { + msg.Text, err = quote(part.Body) + if err != nil { + return err + } + } else if mimeType == "text/html" { + msg.Text, err = html2text.FromReader(part.Body, html2text.Options{}) + if err != nil { + return err + } + } else { err := fmt.Errorf("cannot forward %q part", mimeType) return echo.NewHTTPError(http.StatusBadRequest, err) } - msg.Text, err = quote(part.Body) - if err != nil { - return err - } - msg.MessageID = mail.GenerateMessageID() msg.Subject = source.Envelope.Subject if !strings.HasPrefix(strings.ToLower(msg.Subject), "fwd:") && |