diff --git a/pkg/message/parser.go b/pkg/message/parser.go index bb4b331f..22b6c58c 100644 --- a/pkg/message/parser.go +++ b/pkg/message/parser.go @@ -44,12 +44,6 @@ func Parse(r io.Reader, key, keyName string) (m *pmapi.Message, mimeBody, plainB return } - if key != "" { - if err = attachPublicKey(p.Root(), key, keyName); err != nil { - return - } - } - m = pmapi.NewMessage() if err = parseMessageHeader(m, p.Root().Header); err != nil { @@ -68,6 +62,15 @@ func Parse(r io.Reader, key, keyName string) (m *pmapi.Message, mimeBody, plainB return } + // We only attach the public key manually to the MIME body for + // signed/encrypted external recipients. It's not important for it to be + // collected as an attachment; that's already done when we upload the draft. + if key != "" { + if err = attachPublicKey(p.Root(), key, keyName); err != nil { + return + } + } + mimeBodyBuffer := new(bytes.Buffer) if err = p.NewWriter().Write(mimeBodyBuffer); err != nil { diff --git a/pkg/message/parser_test.go b/pkg/message/parser_test.go index 0bed73c0..01f3e6bb 100644 --- a/pkg/message/parser_test.go +++ b/pkg/message/parser_test.go @@ -322,7 +322,9 @@ func TestParseWithAttachedPublicKey(t *testing.T) { assert.Equal(t, "body", m.Body) assert.Equal(t, "body", plainBody) - require.Len(t, attReaders, 1) + // The pubkey should not be collected as an attachment. + // We upload the pubkey when creating the draft. + require.Len(t, attReaders, 0) } func TestParseTextHTMLWithEmbeddedForeignEncoding(t *testing.T) {