Other: preserve message header in PGP/MIME passthrough message

This commit is contained in:
James Houlahan
2021-04-22 16:30:29 +02:00
parent ebf724412b
commit 4038752a9a
2 changed files with 6 additions and 3 deletions

View File

@ -219,7 +219,7 @@ func buildExternallyEncryptedRFC822(kr *crypto.KeyRing, msg *pmapi.Message, opts
return nil, errors.Wrap(ErrDecryptionFailed, err.Error()) return nil, errors.Wrap(ErrDecryptionFailed, err.Error())
} }
return buildPGPMIMERFC822(msg) return buildPGPMIMERFC822(msg, opts)
} }
hdr := getMessageHeader(msg, opts) hdr := getMessageHeader(msg, opts)
@ -254,8 +254,8 @@ func buildExternallyEncryptedRFC822(kr *crypto.KeyRing, msg *pmapi.Message, opts
return buf.Bytes(), nil return buf.Bytes(), nil
} }
func buildPGPMIMERFC822(msg *pmapi.Message) ([]byte, error) { func buildPGPMIMERFC822(msg *pmapi.Message, opts JobOptions) ([]byte, error) {
var hdr message.Header hdr := getMessageHeader(msg, opts)
hdr.SetContentType("multipart/encrypted", map[string]string{ hdr.SetContentType("multipart/encrypted", map[string]string{
"boundary": newBoundary(msg.ID).gen(), "boundary": newBoundary(msg.ID).gen(),

View File

@ -1023,6 +1023,8 @@ func TestBuildCustomMessageEncrypted(t *testing.T) {
foreignKR := tests.MakeKeyRing(t) foreignKR := tests.MakeKeyRing(t)
msg := newTestMessage(t, foreignKR, "messageID", "addressID", "multipart/mixed", body, time.Date(2020, time.January, 1, 0, 0, 0, 0, time.UTC)) msg := newTestMessage(t, foreignKR, "messageID", "addressID", "multipart/mixed", body, time.Date(2020, time.January, 1, 0, 0, 0, 0, time.UTC))
msg.Subject = "this is a subject to make sure we preserve subject"
// Tell the job to ignore decryption errors; a custom message will be returned instead of an error. // Tell the job to ignore decryption errors; a custom message will be returned instead of an error.
res, err := b.NewJobWithOptions( res, err := b.NewJobWithOptions(
context.Background(), context.Background(),
@ -1033,6 +1035,7 @@ func TestBuildCustomMessageEncrypted(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
section(t, res). section(t, res).
expectHeader(`Subject`, is(msg.Subject)).
expectContentType(is(`multipart/encrypted`)). expectContentType(is(`multipart/encrypted`)).
expectContentTypeParam(`protocol`, is(`application/pgp-encrypted`)) expectContentTypeParam(`protocol`, is(`application/pgp-encrypted`))