π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Fix email encoding
vishnukvmd1490eea78838
diff --git a/server/pkg/utils/email/email.go b/server/pkg/utils/email/email.goindex 0186842f2b..b077066c50 100644--- a/server/pkg/utils/email/email.go+++ b/server/pkg/utils/email/email.go@@ -11,6 +11,7 @@ import ("encoding/json""fmt""html/template"+ "mime/quotedprintable""net/http""net/smtp""path"@@ -90,6 +91,21 @@ func wrapToMaxLineLength(s string, maxLen int) string {return b.String()}+func buildHTMLMIMEPart(htmlBody string) (string, error) {+ var encodedBody bytes.Buffer+ writer := quotedprintable.NewWriter(&encodedBody)+ if _, err := writer.Write([]byte(htmlBody)); err != nil {+ return "", err+ }+ if err := writer.Close(); err != nil {+ return "", err+ }++ return "Content-Type: text/html; charset=utf-8\n" ++ "Content-Transfer-Encoding: quoted-printable\n\n" ++ encodedBody.String() + "\n", nil+}+// Send sends an emailfunc Send(toEmails []string, fromName string, fromEmail string, subject string, htmlBody string, inlineImages []map[string]interface{}) error {smtpHost := viper.GetString("smtp.host")@@ -159,7 +175,10 @@ func sendViaSMTP(toEmails []string, fromName string, fromEmail string, subject s"MIME-Version: 1.0\n" +"Content-Type: multipart/related; boundary=boundary\n\n" +"--boundary\n"- htmlContent := "Content-Type: text/html; charset=us-ascii\n\n" + htmlBody + "\n"+ htmlContent, err := buildHTMLMIMEPart(htmlBody)+ if err != nil {+ return stacktrace.Propagate(err, "failed to encode html body")+ }emailMessage = header + htmlContentdiff --git a/server/pkg/utils/email/email_test.go b/server/pkg/utils/email/email_test.goindex bdcf3b3df9..08a7dd17b2 100644--- a/server/pkg/utils/email/email_test.go+++ b/server/pkg/utils/email/email_test.go@@ -1,11 +1,34 @@package emailimport (+ "io"+ "mime/quotedprintable"+ "strings""testing""github.com/stretchr/testify/assert")+func TestBuildHTMLMIMEPartPreservesUnicode(t *testing.T) {+ htmlBody := "<p>Hello β emoji π</p>"++ part, err := buildHTMLMIMEPart(htmlBody)+ assert.NoError(t, err)+ assert.Contains(t, part, "Content-Type: text/html; charset=utf-8")+ assert.Contains(t, part, "Content-Transfer-Encoding: quoted-printable")+ assert.Contains(t, part, "=E2=80=93")+ assert.Contains(t, part, "=F0=9F=98=8A")++ sections := strings.SplitN(part, "\n\n", 2)+ if assert.Len(t, sections, 2) {+ decodedBody, err := io.ReadAll(+ quotedprintable.NewReader(strings.NewReader(strings.TrimSuffix(sections[1], "\n"))),+ )+ assert.NoError(t, err)+ assert.Equal(t, htmlBody, string(decodedBody))+ }+}+func TestGetMaskedEmailForPublic(t *testing.T) {tests := []struct {name string