diff --git a/go.mod b/go.mod index 762a460..e336452 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/Flaque/filet v0.0.0-20190209224823-fc4d33cfcf93 github.com/PuerkitoBio/goquery v1.5.0 github.com/Skarlso/html-to-markdown v0.0.0-20191210071215-2cf06e949e49 + github.com/cseeger-epages/godown v0.0.0-20180312012330-2e9e17e0ea51 github.com/dsnet/compress v0.0.1 // indirect github.com/emersion/go-imap v1.0.0-rc.2 github.com/emersion/go-message v0.11.0 diff --git a/go.sum b/go.sum index 91d703d..53e2be8 100644 --- a/go.sum +++ b/go.sum @@ -45,6 +45,8 @@ github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8Nz github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/corpix/uarand v0.0.0/go.mod h1:JSm890tOkDN+M1jqN8pUGDKnzJrsVbJwSMHBY4zwz7M= +github.com/cseeger-epages/godown v0.0.0-20180312012330-2e9e17e0ea51 h1:wRkDqYlQratKLUdtdpAeyeRolvJ5y/L/7zeQ3Be8vOw= +github.com/cseeger-epages/godown v0.0.0-20180312012330-2e9e17e0ea51/go.mod h1:YH5dvqBkWk+/05C+IsYsAIsQVkiSRqzgaYp2aogXjIc= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/lib/mattermost.go b/lib/mattermost.go index 6ff2c63..9fc68ca 100644 --- a/lib/mattermost.go +++ b/lib/mattermost.go @@ -1,10 +1,12 @@ package mail2most import ( + "bytes" "encoding/base64" "fmt" "strings" + "github.com/cseeger-epages/godown" "github.com/k3a/html2text" "github.com/mattermost/mattermost-server/model" ) @@ -51,7 +53,12 @@ func (m Mail2Most) PostMattermost(profile int, mail Mail) error { } if m.Config.Profiles[profile].Mattermost.ConvertToMarkdown { - // tbd convert body to markdown + var b bytes.Buffer + err := godown.Convert(&b, strings.NewReader(body), nil) + if err != nil { + return err + } + body = b.String() } else if m.Config.Profiles[profile].Mattermost.StripHTML { body = html2text.HTML2Text(body) mail.Subject = html2text.HTML2Text(mail.Subject)