Skip to content

Commit 637e391

Browse files
feat: html2text
1 parent 642c8b2 commit 637e391

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ smtpbridge --version
3535

3636
## Config
3737

38-
Config file is loaded from one of the following locations.
38+
Config file is loaded from one of the following locations.
3939

4040
- `config.yaml`
4141
- `config.yml`

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require (
1111
github.com/emersion/go-smtp v0.16.0
1212
github.com/gofiber/fiber/v2 v2.47.0
1313
github.com/gofiber/template/html/v2 v2.0.4
14+
github.com/jaytaylor/html2text v0.0.0-20200412013138-3577fbdbcff7
1415
github.com/jhillyerd/enmime v1.0.0
1516
github.com/labstack/gommon v0.4.0
1617
github.com/rs/zerolog v1.29.1
@@ -29,7 +30,6 @@ require (
2930
github.com/gofiber/utils v1.1.0 // indirect
3031
github.com/gogs/chardet v0.0.0-20191104214054-4b6791f73a28 // indirect
3132
github.com/google/uuid v1.3.0 // indirect
32-
github.com/jaytaylor/html2text v0.0.0-20200412013138-3577fbdbcff7 // indirect
3333
github.com/jinzhu/inflection v1.0.0 // indirect
3434
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
3535
github.com/klauspost/compress v1.16.3 // indirect

internal/envelope/message.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"time"
55

66
"github.com/ItsNotGoodName/smtpbridge/pkg/pagination"
7+
"github.com/jaytaylor/html2text"
78
"github.com/samber/lo"
89
)
910

@@ -17,12 +18,21 @@ type CreateMessage struct {
1718
}
1819

1920
func NewMessage(r CreateMessage) *Message {
21+
text := r.Text
22+
if isHTML(r.Text) {
23+
var err error
24+
text, err = html2text.FromString(r.Text)
25+
if err != nil {
26+
text = r.Text
27+
}
28+
}
29+
2030
return &Message{
2131
From: r.From,
2232
To: lo.Uniq(r.To),
2333
CreatedAt: time.Now(),
2434
Subject: r.Subject,
25-
Text: r.Text,
35+
Text: text,
2636
HTML: r.HTML,
2737
Date: r.Date,
2838
}

internal/envelope/utils.go

+4
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ func fileExtension(name string, mimeT string) string {
3434
}
3535
return extension
3636
}
37+
38+
func isHTML(maybeHTML string) bool {
39+
return strings.HasPrefix(maybeHTML, "<!DOCTYPE html>")
40+
}

0 commit comments

Comments
 (0)