diff --git a/crypto/message.go b/crypto/message.go index ccdb5d3..d6072fe 100644 --- a/crypto/message.go +++ b/crypto/message.go @@ -202,7 +202,7 @@ func (msg *PlainMessage) GetBinary() []byte { // GetString returns the content of the message as a string. func (msg *PlainMessage) GetString() string { - return strings.ReplaceAll(string(msg.Data), "\r\n", "\n") + return sanitizeString(strings.ReplaceAll(string(msg.Data), "\r\n", "\n")) } // GetBase64 returns the base-64 encoded binary content of the message as a diff --git a/crypto/mime.go b/crypto/mime.go index 4d55cd0..d756dfc 100644 --- a/crypto/mime.go +++ b/crypto/mime.go @@ -49,7 +49,8 @@ func (keyRing *KeyRing) DecryptMIMEMessage( callbacks.OnVerified(constants.SIGNATURE_OK) } bodyContent, bodyMimeType := body.GetBody() - callbacks.OnBody(bodyContent, bodyMimeType) + bodyContentSanitized := sanitizeString(bodyContent) + callbacks.OnBody(bodyContentSanitized, bodyMimeType) for i := 0; i < len(attachments); i++ { callbacks.OnAttachment(attachmentHeaders[i], []byte(attachments[i])) } diff --git a/crypto/sanitize_string.go b/crypto/sanitize_string.go new file mode 100644 index 0000000..94aa81c --- /dev/null +++ b/crypto/sanitize_string.go @@ -0,0 +1,8 @@ +//go:build !ios +// +build !ios + +package crypto + +func sanitizeString(input string) string { + return input +} diff --git a/crypto/sanitize_string_ios.go b/crypto/sanitize_string_ios.go new file mode 100644 index 0000000..561414b --- /dev/null +++ b/crypto/sanitize_string_ios.go @@ -0,0 +1,10 @@ +//go:build ios +// +build ios + +package crypto + +import "strings" + +func sanitizeString(input string) string { + return strings.ToValidUTF8(input, "\ufffd") +}