diff --git a/pkg/message/build_rfc822.go b/pkg/message/build_rfc822.go index ef45110c..d7434097 100644 --- a/pkg/message/build_rfc822.go +++ b/pkg/message/build_rfc822.go @@ -146,6 +146,12 @@ func writeTextPart( return errors.Wrap(ErrDecryptionFailed, err.Error()) } + /* + if len(msg.Attachments) > 0 { + return writeCustomTextPartAsAttachment(w, msg, err) + } + */ + return writeCustomTextPart(w, msg, err) } diff --git a/pkg/message/build_rfc822_custom.go b/pkg/message/build_rfc822_custom.go index e4d40346..89b47b6a 100644 --- a/pkg/message/build_rfc822_custom.go +++ b/pkg/message/build_rfc822_custom.go @@ -27,42 +27,7 @@ import ( "github.com/emersion/go-message" ) -/* writeCustomTextPart writes an armored-PGP text part for a message body that couldn't be decrypted. -The following is an example of such a message: - -Mime-Version: 1.0 -Content-Type: multipart/mixed; - boundary=d8a04ef2e12150946d27f84fc82b9e70a5e314f91a0f2190e38c7aad623466da -Message-Id: -Date: Fri, 26 Mar 2021 14:10:00 +0000 - ---d8a04ef2e12150946d27f84fc82b9e70a5e314f91a0f2190e38c7aad623466da -Content-Type: text/plain - ------BEGIN PGP MESSAGE----- -Version: GopenPGP 2.1.3 -Comment: This message could not be decrypted: gopenpgp: error in reading message: openpgp: incorrect key - -wcBMA1iOyuyBImpHAQf/boKq75jyV5kGzl8ObcjLuaVrVEw5YbrI1M9gAb/5eq+t -Mzd2qK0owYwBmuvYj3pk2b15miOIPfAYlbQVyIaseq/O4XchPvtJZKxh42eDcYhD -zwqHrYxtCLOOBY6b15Aq8tVLORi4+/VCWJrTHtCdKq71UX7bvBdQRaZqOIJ+bUiP -72IkaWjdVmCgLCmzPN3R3VKsmjTNBt1GRMc6vosQyoAeClyf94wgE1sXGsumXBQs -MX69zK9a36Ya67PpQ9AGVR2peEF07s5O+t/PxkStWfFvMwnnOOSgdHfN0PSwkhoL -EIwDA6lh7+2UlbX9pFi908PDl0OuoLgrL+NyleUPtdLAugGUa0U1fn6K1gwFGcsj -DKflgAMXixhf83xpmz4fM3zzM988ecQsXozQcUDrxSTxzdfWXSaWQDWHguCiL0xM -aPkf4kUn4RX3AoZVTC4GXvupzAQUqjJhyd0p7lJGOwIw0Ik77PxeCFNvWiZHJ3W+ -7PYuehSUgyDJJe7q1GFFcMUspnPmuvhbenKIHlKwGfptnXLRIW15sdcca2Etz5i4 -H71rHKwzAPdNHBQVvN0Nmt77RGAIy4Az8fRwz7hD7E92r4BkaaYntrQe9DUXYc50 -HVXyeFcvpfbEaK+fObxk1ljig+Io2liPx7pn/YBFytMy1mlwhjroMPjMUXuTXqje -NHnOJVxnnXMwGh34wUIEwOmTskJoGkQjQbjvixkwNRGnLzIHuD6614pXtgTDtBzc -AKuQssqOky1Q7KjdusMWnoVL7gTbSrIUxXoKChear5XgPzFevQhQNEfTI8DDMbYR -La1Cc6aFtMPUShzNc3Wp3dVLM09WygEUsYZFmA== -=00ma ------END PGP MESSAGE----- ---d8a04ef2e12150946d27f84fc82b9e70a5e314f91a0f2190e38c7aad623466da-- - -. -*/ +// writeCustomTextPart writes an armored-PGP text part for a message body that couldn't be decrypted. func writeCustomTextPart( w *message.Writer, msg *pmapi.Message, @@ -113,11 +78,12 @@ func writeCustomAttachmentPart( return err } + filename := mime.QEncoding.Encode("utf-8", att.Name+".pgp") + var hdr message.Header - hdr.SetContentType("application/pgp-encrypted", map[string]string{"name": mime.QEncoding.Encode("utf-8", att.Name+".pgp")}) - - hdr.SetContentDisposition(att.Disposition, map[string]string{"filename": mime.QEncoding.Encode("utf-8", att.Name+".pgp")}) + hdr.SetContentType("application/octet-stream", map[string]string{"name": filename}) + hdr.SetContentDisposition(att.Disposition, map[string]string{"filename": filename}) part, err := w.CreatePart(hdr) if err != nil { diff --git a/pkg/message/build_test.go b/pkg/message/build_test.go index e39bdf96..bfeab1fb 100644 --- a/pkg/message/build_test.go +++ b/pkg/message/build_test.go @@ -1042,7 +1042,7 @@ func TestBuildCustomMessagePlainWithAttachment(t *testing.T) { expectTransferEncoding(isMissing()) section(t, res, 2). - expectContentType(is(`application/pgp-encrypted`)). + expectContentType(is(`application/octet-stream`)). expectBody(contains(`This attachment could not be decrypted`)). expectBody(decryptsTo(foreignKR, `attachment`)). expectContentTypeParam(`name`, is(`file.png.pgp`)). @@ -1084,7 +1084,7 @@ func TestBuildCustomMessageHTMLWithAttachment(t *testing.T) { expectTransferEncoding(isMissing()) section(t, res, 2). - expectContentType(is(`application/pgp-encrypted`)). + expectContentType(is(`application/octet-stream`)). expectBody(contains(`This attachment could not be decrypted`)). expectBody(decryptsTo(foreignKR, `attachment`)). expectContentTypeParam(`name`, is(`file.png.pgp`)). @@ -1168,7 +1168,7 @@ func TestBuildCustomMessageOnlyAttachmentIsUndecryptable(t *testing.T) { expectTransferEncoding(is(`quoted-printable`)) section(t, res, 2). - expectContentType(is(`application/pgp-encrypted`)). + expectContentType(is(`application/octet-stream`)). expectBody(contains(`This attachment could not be decrypted`)). expectBody(decryptsTo(foreignKR, `attachment`)). expectContentTypeParam(`name`, is(`file.png.pgp`)).