forked from Silverfish/proton-bridge
GODT-213: Use application/octet-stream for encrypted parts
This commit is contained in:
@ -146,6 +146,12 @@ func writeTextPart(
|
|||||||
return errors.Wrap(ErrDecryptionFailed, err.Error())
|
return errors.Wrap(ErrDecryptionFailed, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
if len(msg.Attachments) > 0 {
|
||||||
|
return writeCustomTextPartAsAttachment(w, msg, err)
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
return writeCustomTextPart(w, msg, err)
|
return writeCustomTextPart(w, msg, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -27,42 +27,7 @@ import (
|
|||||||
"github.com/emersion/go-message"
|
"github.com/emersion/go-message"
|
||||||
)
|
)
|
||||||
|
|
||||||
/* writeCustomTextPart writes an armored-PGP text part for a message body that couldn't be decrypted.
|
// 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: <messageID@protonmail.internalid>
|
|
||||||
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--
|
|
||||||
|
|
||||||
.
|
|
||||||
*/
|
|
||||||
func writeCustomTextPart(
|
func writeCustomTextPart(
|
||||||
w *message.Writer,
|
w *message.Writer,
|
||||||
msg *pmapi.Message,
|
msg *pmapi.Message,
|
||||||
@ -113,11 +78,12 @@ func writeCustomAttachmentPart(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
filename := mime.QEncoding.Encode("utf-8", att.Name+".pgp")
|
||||||
|
|
||||||
var hdr message.Header
|
var hdr message.Header
|
||||||
|
|
||||||
hdr.SetContentType("application/pgp-encrypted", map[string]string{"name": 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})
|
||||||
hdr.SetContentDisposition(att.Disposition, map[string]string{"filename": mime.QEncoding.Encode("utf-8", att.Name+".pgp")})
|
|
||||||
|
|
||||||
part, err := w.CreatePart(hdr)
|
part, err := w.CreatePart(hdr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -1042,7 +1042,7 @@ func TestBuildCustomMessagePlainWithAttachment(t *testing.T) {
|
|||||||
expectTransferEncoding(isMissing())
|
expectTransferEncoding(isMissing())
|
||||||
|
|
||||||
section(t, res, 2).
|
section(t, res, 2).
|
||||||
expectContentType(is(`application/pgp-encrypted`)).
|
expectContentType(is(`application/octet-stream`)).
|
||||||
expectBody(contains(`This attachment could not be decrypted`)).
|
expectBody(contains(`This attachment could not be decrypted`)).
|
||||||
expectBody(decryptsTo(foreignKR, `attachment`)).
|
expectBody(decryptsTo(foreignKR, `attachment`)).
|
||||||
expectContentTypeParam(`name`, is(`file.png.pgp`)).
|
expectContentTypeParam(`name`, is(`file.png.pgp`)).
|
||||||
@ -1084,7 +1084,7 @@ func TestBuildCustomMessageHTMLWithAttachment(t *testing.T) {
|
|||||||
expectTransferEncoding(isMissing())
|
expectTransferEncoding(isMissing())
|
||||||
|
|
||||||
section(t, res, 2).
|
section(t, res, 2).
|
||||||
expectContentType(is(`application/pgp-encrypted`)).
|
expectContentType(is(`application/octet-stream`)).
|
||||||
expectBody(contains(`This attachment could not be decrypted`)).
|
expectBody(contains(`This attachment could not be decrypted`)).
|
||||||
expectBody(decryptsTo(foreignKR, `attachment`)).
|
expectBody(decryptsTo(foreignKR, `attachment`)).
|
||||||
expectContentTypeParam(`name`, is(`file.png.pgp`)).
|
expectContentTypeParam(`name`, is(`file.png.pgp`)).
|
||||||
@ -1168,7 +1168,7 @@ func TestBuildCustomMessageOnlyAttachmentIsUndecryptable(t *testing.T) {
|
|||||||
expectTransferEncoding(is(`quoted-printable`))
|
expectTransferEncoding(is(`quoted-printable`))
|
||||||
|
|
||||||
section(t, res, 2).
|
section(t, res, 2).
|
||||||
expectContentType(is(`application/pgp-encrypted`)).
|
expectContentType(is(`application/octet-stream`)).
|
||||||
expectBody(contains(`This attachment could not be decrypted`)).
|
expectBody(contains(`This attachment could not be decrypted`)).
|
||||||
expectBody(decryptsTo(foreignKR, `attachment`)).
|
expectBody(decryptsTo(foreignKR, `attachment`)).
|
||||||
expectContentTypeParam(`name`, is(`file.png.pgp`)).
|
expectContentTypeParam(`name`, is(`file.png.pgp`)).
|
||||||
|
|||||||
Reference in New Issue
Block a user