GODT-2142: Also permit split by comma in References header

This commit is contained in:
James Houlahan
2022-11-22 19:08:03 +01:00
parent cb81175fa0
commit 555453bc1a
4 changed files with 51 additions and 8 deletions

View File

@ -163,8 +163,7 @@ func sendWithKey( //nolint:funlen
authAddrID string,
addrMode vault.AddressMode,
settings liteapi.MailSettings,
userKR *crypto.KeyRing,
addrKR *crypto.KeyRing,
userKR, addrKR *crypto.KeyRing,
emails []string,
from string,
to []string,
@ -177,7 +176,8 @@ func sendWithKey( //nolint:funlen
var decBody string
switch message.MIMEType { //nolint:exhaustive
// nolint:exhaustive
switch message.MIMEType {
case rfc822.TextHTML:
decBody = string(message.RichBody)

View File

@ -30,7 +30,6 @@ import (
"github.com/ProtonMail/go-rfc5322"
"github.com/ProtonMail/proton-bridge/v2/pkg/message/parser"
pmmime "github.com/ProtonMail/proton-bridge/v2/pkg/mime"
"github.com/bradenaw/juniper/xslices"
"github.com/emersion/go-message"
"github.com/jaytaylor/html2text"
"github.com/pkg/errors"
@ -497,9 +496,11 @@ func parseMessageHeader(h message.Header) (Message, error) { //nolint:funlen
m.InReplyTo = regexp.MustCompile("<(.*)>").ReplaceAllString(fields.Value(), "$1")
case "references":
m.References = append(m.References, xslices.Map(strings.Fields(fields.Value()), func(ref string) string {
return strings.Trim(ref, "<>")
})...)
for _, ref := range strings.Fields(fields.Value()) {
for _, ref := range strings.Split(ref, ",") {
m.References = append(m.References, strings.Trim(ref, "<>"))
}
}
}
}

View File

@ -587,7 +587,22 @@ func TestParseMessageReferences(t *testing.T) {
m, err := Parse(f)
require.NoError(t, err)
assert.Len(t, m.References, 2)
assert.ElementsMatch(t, m.References, []string{
`PMZV4VZMRM@something.com`,
`OEUOEUEOUOUOU770B9QNZWFVGM@protonmail.ch`,
})
}
func TestParseMessageReferencesComma(t *testing.T) {
f := getFileReader("references-comma.eml")
m, err := Parse(f)
require.NoError(t, err)
assert.ElementsMatch(t, m.References, []string{
`PMZV4VZMRM@something.com`,
`OEUOEUEOUOUOU770B9QNZWFVGM@protonmail.ch`,
})
}
func TestParsePanic(t *testing.T) {

View File

@ -0,0 +1,27 @@
Content-Type: multipart/mixed;
boundary=987c7102dcaf02d01860ce777b465f86d39ec16a3b4e12605eb6b0eb200a
X-Original-To: someone@protonmail.com
Delivered-To: someone@protonmail.com
Date: Sun, 04 Aug 2019 13:03:26 +0000
From: ProtonVPN <support@protonvpn.something.com>
Reply-To: ProtonVPN <support+id493949@protonvpn.something.com>
To: someone <someone@protonmail.com>
Message-Id: <OEUOEUOUOU_5d46d79df036f_1d78b3fd8f42bcf2014719e_sprut@something.com>
In-Reply-To: <OEUOEUEOUOUOU770B9QNZWFVGM@protonmail.ch>
References: <PMZV4VZMRM@something.com>,<OEUOEUEOUOUOU770B9QNZWFVGM@protonmail.ch>
Subject: Some test subject
Mime-Version: 1.0
--987c7102dcaf02d01860ce777b465f86d39ec16a3b4e12605eb6b0eb200a
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=utf-8
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.=
w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
test test test
</body>
</html>
--987c7102dcaf02d01860ce777b465f86d39ec16a3b4e12605eb6b0eb200a--