From 3499fbd75823e14b80a6d1bde5a8688cb27dfea5 Mon Sep 17 00:00:00 2001 From: Leander Beernaert Date: Fri, 16 Dec 2022 14:26:59 +0100 Subject: [PATCH] Other: Do not decode message body during send record hashing When calculating the hash for the body to match against sent email to avoid duplicate addition to the sent folder, do not decode the actual contents of the body. It is possible that certain attachments are not formed correctly but can still accepted by the backend. Trimming spaces and \r characters is enough to hash the message and match it later on. This also speeds the process up as we no longer have to perform encoding conversions. --- internal/user/send_recorder.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/internal/user/send_recorder.go b/internal/user/send_recorder.go index 969a97fb..5c57f763 100644 --- a/internal/user/send_recorder.go +++ b/internal/user/send_recorder.go @@ -275,12 +275,10 @@ func getMessageHash(b []byte) (string, error) { return err } - body, err := section.DecodedBody() - if err != nil { - return err - } - - if _, err := h.Write(bytes.TrimSpace(body)); err != nil { + body := section.Body() + body = bytes.ReplaceAll(body, []byte{'\r'}, nil) + body = bytes.TrimSpace(body) + if _, err := h.Write(body); err != nil { return err }