1
0
mirror of https://github.com/axllent/mailpit.git synced 2025-07-15 01:25:10 +02:00

Fix: Disable automatic HTML/Text character detection when charset is provided (#348)

This commit is contained in:
Ralph Slooten
2024-09-01 18:35:42 +12:00
parent 259d71122b
commit be1d2bcb28
5 changed files with 18 additions and 8 deletions

2
go.mod
View File

@ -11,7 +11,7 @@ require (
github.com/gomarkdown/markdown v0.0.0-20240730141124-034f12af3bf6
github.com/gorilla/mux v1.8.1
github.com/gorilla/websocket v1.5.3
github.com/jhillyerd/enmime v1.2.0
github.com/jhillyerd/enmime v1.3.0
github.com/klauspost/compress v1.17.9
github.com/kovidgoyal/imaging v1.6.3
github.com/leporo/sqlf v1.4.0

4
go.sum
View File

@ -42,8 +42,8 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jaytaylor/html2text v0.0.0-20230321000545-74c2419ad056 h1:iCHtR9CQyktQ5+f3dMVZfwD2KWJUgm7M0gdL9NGr8KA=
github.com/jaytaylor/html2text v0.0.0-20230321000545-74c2419ad056/go.mod h1:CVKlgaMiht+LXvHG173ujK6JUhZXKb2u/BQtjPDIvyk=
github.com/jhillyerd/enmime v1.2.0 h1:dIu1IPEymQgoT2dzuB//ttA/xcV40NMPpQtmd4wslHk=
github.com/jhillyerd/enmime v1.2.0/go.mod h1:FRFuUPCLh8PByQv+8xRcLO9QHqaqTqreYhopv5eyk4I=
github.com/jhillyerd/enmime v1.3.0 h1:LV5kzfLidiOr8qRGIpYYmUZCnhrPbcFAnAFUnWn99rw=
github.com/jhillyerd/enmime v1.3.0/go.mod h1:6c6jg5HdRRV2FtvVL69LjiX1M8oE0xDX9VEhV3oy4gs=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/kovidgoyal/imaging v1.6.3 h1:iNPpv7ygiaB/NOztc6APMT7yr9UwBS+rOZwIbAdtyY8=

View File

@ -27,8 +27,10 @@ import (
// Store will save an email to the database tables.
// Returns the database ID of the saved message.
func Store(body *[]byte) (string, error) {
parser := enmime.NewParser(enmime.DisableCharacterDetection(true))
// Parse message body with enmime
env, err := enmime.ReadEnvelope(bytes.NewReader(*body))
env, err := parser.ReadEnvelope(bytes.NewReader(*body))
if err != nil {
logger.Log().Warnf("[message] %s", err.Error())
return "", nil
@ -245,7 +247,9 @@ func GetMessage(id string) (*Message, error) {
r := bytes.NewReader(raw)
env, err := enmime.ReadEnvelope(r)
parser := enmime.NewParser(enmime.DisableCharacterDetection(true))
env, err := parser.ReadEnvelope(r)
if err != nil {
return nil, err
}
@ -396,7 +400,9 @@ func GetAttachmentPart(id, partID string) (*enmime.Part, error) {
r := bytes.NewReader(raw)
env, err := enmime.ReadEnvelope(r)
parser := enmime.NewParser(enmime.DisableCharacterDetection(true))
env, err := parser.ReadEnvelope(r)
if err != nil {
return nil, err
}

View File

@ -49,6 +49,8 @@ func ReindexAll() {
Metadata string
}
parser := enmime.NewParser(enmime.DisableCharacterDetection(true))
for _, ids := range chunks {
updates := []updateStruct{}
@ -61,7 +63,7 @@ func ReindexAll() {
r := bytes.NewReader(raw)
env, err := enmime.ReadEnvelope(r)
env, err := parser.ReadEnvelope(r)
if err != nil {
logger.Log().Errorf("[message] %s", err.Error())
continue

View File

@ -559,7 +559,9 @@ func HTMLCheck(w http.ResponseWriter, r *http.Request) {
e := bytes.NewReader(raw)
msg, err := enmime.ReadEnvelope(e)
parser := enmime.NewParser(enmime.DisableCharacterDetection(true))
msg, err := parser.ReadEnvelope(e)
if err != nil {
httpError(w, err.Error())
return