From 77c6ba381ebeb5cc3195d697d7524a67d8b3dbaf Mon Sep 17 00:00:00 2001 From: James Houlahan Date: Thu, 13 Aug 2020 11:21:37 +0200 Subject: [PATCH] fix: mime type --- internal/smtp/preferences_test.go | 36 +++++++++++++++---------------- internal/smtp/user.go | 1 + internal/smtp/utils.go | 2 ++ pkg/pmapi/settings.go | 4 ++-- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/internal/smtp/preferences_test.go b/internal/smtp/preferences_test.go index f36133d4..410a9abb 100644 --- a/internal/smtp/preferences_test.go +++ b/internal/smtp/preferences_test.go @@ -51,7 +51,7 @@ func TestPreferencesBuilder(t *testing.T) { contactMeta: &ContactMetadata{}, receivedKeys: []pmapi.PublicKey{{PublicKey: testPublicKey}}, isInternal: true, - mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage}, + mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage, ComposerMode: pmapi.ComposerModeNormal}, wantEncrypt: true, wantSign: true, @@ -66,7 +66,7 @@ func TestPreferencesBuilder(t *testing.T) { contactMeta: &ContactMetadata{MIMEType: "text/plain"}, receivedKeys: []pmapi.PublicKey{{PublicKey: testPublicKey}}, isInternal: true, - mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage}, + mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage, ComposerMode: pmapi.ComposerModeNormal}, wantEncrypt: true, wantSign: true, @@ -81,7 +81,7 @@ func TestPreferencesBuilder(t *testing.T) { contactMeta: &ContactMetadata{Keys: []string{testContactKey}}, receivedKeys: []pmapi.PublicKey{{PublicKey: testPublicKey}}, isInternal: true, - mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage}, + mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage, ComposerMode: pmapi.ComposerModeNormal}, wantEncrypt: true, wantSign: true, @@ -97,7 +97,7 @@ func TestPreferencesBuilder(t *testing.T) { contactMeta: &ContactMetadata{Keys: []string{testOtherContactKey}}, receivedKeys: []pmapi.PublicKey{{PublicKey: testPublicKey}}, isInternal: true, - mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage}, + mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage, ComposerMode: pmapi.ComposerModeNormal}, wantEncrypt: true, wantSign: true, @@ -112,7 +112,7 @@ func TestPreferencesBuilder(t *testing.T) { contactMeta: &ContactMetadata{}, receivedKeys: []pmapi.PublicKey{{PublicKey: testPublicKey}}, isInternal: false, - mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage}, + mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage, ComposerMode: pmapi.ComposerModeNormal}, wantEncrypt: true, wantSign: true, @@ -127,7 +127,7 @@ func TestPreferencesBuilder(t *testing.T) { contactMeta: &ContactMetadata{MIMEType: "text/plain"}, receivedKeys: []pmapi.PublicKey{{PublicKey: testPublicKey}}, isInternal: false, - mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage}, + mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage, ComposerMode: pmapi.ComposerModeNormal}, wantEncrypt: true, wantSign: true, @@ -142,7 +142,7 @@ func TestPreferencesBuilder(t *testing.T) { contactMeta: &ContactMetadata{}, receivedKeys: []pmapi.PublicKey{{PublicKey: testPublicKey}}, isInternal: false, - mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPInlinePackage}, + mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPInlinePackage, ComposerMode: pmapi.ComposerModeNormal}, wantEncrypt: true, wantSign: true, @@ -157,7 +157,7 @@ func TestPreferencesBuilder(t *testing.T) { contactMeta: &ContactMetadata{Scheme: pgpInline}, receivedKeys: []pmapi.PublicKey{{PublicKey: testPublicKey}}, isInternal: false, - mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage}, + mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage, ComposerMode: pmapi.ComposerModeNormal}, wantEncrypt: true, wantSign: true, @@ -172,7 +172,7 @@ func TestPreferencesBuilder(t *testing.T) { contactMeta: &ContactMetadata{Scheme: pgpMIME}, receivedKeys: []pmapi.PublicKey{{PublicKey: testPublicKey}}, isInternal: false, - mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPInlinePackage}, + mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPInlinePackage, ComposerMode: pmapi.ComposerModeNormal}, wantEncrypt: true, wantSign: true, @@ -187,7 +187,7 @@ func TestPreferencesBuilder(t *testing.T) { contactMeta: &ContactMetadata{Keys: []string{testContactKey}}, receivedKeys: []pmapi.PublicKey{{PublicKey: testPublicKey}}, isInternal: false, - mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage}, + mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage, ComposerMode: pmapi.ComposerModeNormal}, wantEncrypt: true, wantSign: true, @@ -203,7 +203,7 @@ func TestPreferencesBuilder(t *testing.T) { contactMeta: &ContactMetadata{Keys: []string{testOtherContactKey}}, receivedKeys: []pmapi.PublicKey{{PublicKey: testPublicKey}}, isInternal: false, - mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage}, + mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage, ComposerMode: pmapi.ComposerModeNormal}, wantEncrypt: true, wantSign: true, @@ -218,7 +218,7 @@ func TestPreferencesBuilder(t *testing.T) { contactMeta: &ContactMetadata{}, receivedKeys: []pmapi.PublicKey{}, isInternal: false, - mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage}, + mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage, ComposerMode: pmapi.ComposerModeNormal}, wantEncrypt: false, wantSign: false, @@ -232,7 +232,7 @@ func TestPreferencesBuilder(t *testing.T) { contactMeta: &ContactMetadata{MIMEType: "text/plain"}, receivedKeys: []pmapi.PublicKey{}, isInternal: false, - mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage}, + mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage, ComposerMode: pmapi.ComposerModeNormal}, wantEncrypt: false, wantSign: false, @@ -246,7 +246,7 @@ func TestPreferencesBuilder(t *testing.T) { contactMeta: &ContactMetadata{Sign: true}, receivedKeys: []pmapi.PublicKey{}, isInternal: false, - mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage}, + mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage, ComposerMode: pmapi.ComposerModeNormal}, wantEncrypt: false, wantSign: true, @@ -260,7 +260,7 @@ func TestPreferencesBuilder(t *testing.T) { contactMeta: &ContactMetadata{Keys: []string{testContactKey}}, receivedKeys: []pmapi.PublicKey{}, isInternal: false, - mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage}, + mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage, ComposerMode: pmapi.ComposerModeNormal}, wantEncrypt: false, wantSign: false, @@ -275,7 +275,7 @@ func TestPreferencesBuilder(t *testing.T) { contactMeta: &ContactMetadata{Keys: []string{testContactKey}, Encrypt: true, Sign: true}, receivedKeys: []pmapi.PublicKey{}, isInternal: false, - mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage}, + mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage, ComposerMode: pmapi.ComposerModeNormal}, wantEncrypt: true, wantSign: true, @@ -290,7 +290,7 @@ func TestPreferencesBuilder(t *testing.T) { contactMeta: &ContactMetadata{Keys: []string{testContactKey}, Encrypt: true, Sign: true, Scheme: pgpInline}, receivedKeys: []pmapi.PublicKey{}, isInternal: false, - mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage}, + mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPMIMEPackage, ComposerMode: pmapi.ComposerModeNormal}, wantEncrypt: true, wantSign: true, @@ -305,7 +305,7 @@ func TestPreferencesBuilder(t *testing.T) { contactMeta: &ContactMetadata{Keys: []string{testContactKey}, Encrypt: true, Sign: true}, receivedKeys: []pmapi.PublicKey{}, isInternal: false, - mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPInlinePackage}, + mailSettings: pmapi.MailSettings{PGPScheme: pmapi.PGPInlinePackage, ComposerMode: pmapi.ComposerModeNormal}, wantEncrypt: true, wantSign: true, diff --git a/internal/smtp/user.go b/internal/smtp/user.go index 5c8416fb..cb74f0fc 100644 --- a/internal/smtp/user.go +++ b/internal/smtp/user.go @@ -364,6 +364,7 @@ func (su *smtpUser) Send(from string, to []string, messageReader io.Reader) (err if plainPkg != nil { req.Packages = append(req.Packages, plainPkg) } + htmlPkg := buildPackage(htmlAddressMap, htmlSharedScheme, pmapi.ContentTypeHTML, htmlData, htmlKey, attkeysEncoded) if htmlPkg != nil { req.Packages = append(req.Packages, htmlPkg) diff --git a/internal/smtp/utils.go b/internal/smtp/utils.go index 1fa295db..36b98171 100644 --- a/internal/smtp/utils.go +++ b/internal/smtp/utils.go @@ -102,12 +102,14 @@ func buildPackage( if len(addressMap) == 0 { return nil } + pkg = &pmapi.MessagePackage{ Body: base64.StdEncoding.EncodeToString(bodyData), Addresses: addressMap, MIMEType: mimeType, Type: sharedScheme, } + if sharedScheme|pmapi.ClearPackage > 0 { pkg.BodyKey.Key = bodyKey.GetBase64Key() pkg.BodyKey.Algorithm = bodyKey.Algo diff --git a/pkg/pmapi/settings.go b/pkg/pmapi/settings.go index b06aeffd..32102f09 100644 --- a/pkg/pmapi/settings.go +++ b/pkg/pmapi/settings.go @@ -98,8 +98,8 @@ type MailSettings struct { } const ( - ComposerModeNormal = 0 - ComposerModePlain = 1 + ComposerModePlain = 0 + ComposerModeNormal = 1 ) // GetMailSettings gets contact details specified by contact ID.