fix(GODT-2638): Validate messages before import.

Ensure messages have required header fields and adhere to the rfc5322
spec before import.
This commit is contained in:
Leander Beernaert
2023-05-24 07:56:00 +02:00
parent 7d54e6907d
commit bc5de2b884
11 changed files with 31 additions and 4 deletions

2
go.mod
View File

@ -5,7 +5,7 @@ go 1.20
require (
github.com/0xAX/notificator v0.0.0-20220220101646-ee9b8921e557
github.com/Masterminds/semver/v3 v3.2.0
github.com/ProtonMail/gluon v0.16.1-0.20230523090642-633e61ce9bc2
github.com/ProtonMail/gluon v0.16.1-0.20230523142312-75fd429e0dc9
github.com/ProtonMail/go-autostart v0.0.0-20210130080809-00ed301c8e9a
github.com/ProtonMail/go-proton-api v0.4.1-0.20230523092337-ea8de5f674b7
github.com/ProtonMail/gopenpgp/v2 v2.7.1-proton

2
go.sum
View File

@ -28,8 +28,6 @@ github.com/ProtonMail/bcrypt v0.0.0-20211005172633-e235017c1baf h1:yc9daCCYUefEs
github.com/ProtonMail/bcrypt v0.0.0-20211005172633-e235017c1baf/go.mod h1:o0ESU9p83twszAU8LBeJKFAAMX14tISa0yk4Oo5TOqo=
github.com/ProtonMail/docker-credential-helpers v1.1.0 h1:+kvUIpwWcbtP3WFv5sSvkFn/XLzSqPOB5AAthuk9xPk=
github.com/ProtonMail/docker-credential-helpers v1.1.0/go.mod h1:mK0aBveCxhnQ756AmaTfXMZDeULvheYVhF/MWMErN5g=
github.com/ProtonMail/gluon v0.16.1-0.20230523090642-633e61ce9bc2 h1:EFmaapQ2BM5OZ16+/c03108+wAt5nq1m/eCzHMl2Vg4=
github.com/ProtonMail/gluon v0.16.1-0.20230523090642-633e61ce9bc2/go.mod h1:ERZikuN+2i/oTeSwS5fq7J0Fms76uUcBlTAwT4KaEAk=
github.com/ProtonMail/go-autostart v0.0.0-20210130080809-00ed301c8e9a h1:D+aZah+k14Gn6kmL7eKxoo/4Dr/lK3ChBcwce2+SQP4=
github.com/ProtonMail/go-autostart v0.0.0-20210130080809-00ed301c8e9a/go.mod h1:oTGdE7/DlWIr23G0IKW3OXK9wZ5Hw1GGiaJFccTvZi4=
github.com/ProtonMail/go-crypto v0.0.0-20230321155629-9a39f2531310/go.mod h1:8TI4H3IbrackdNgv+92dI+rhpCaLqM0IfpgCgenFvRE=

View File

@ -151,7 +151,7 @@ func TestBridge_SendDraftFlags(t *testing.T) {
defer imapClient.Logout() //nolint:errcheck
// The message to send.
const message = `Subject: Test\r\n\r\nHello world!`
message := fmt.Sprintf("From: %v\r\nDate: 01 Jan 1980 00:00:00 +0000\r\nSubject: Test\r\n\r\nHello world!", userInfo.Addresses[0])
// Save a draft.
require.NoError(t, imapClient.Append("Drafts", []string{imap.DraftFlag}, time.Now(), strings.NewReader(message)))

View File

@ -9,6 +9,8 @@ Feature: IMAP Draft messages
And IMAP client "1" selects "Drafts"
When IMAP client "1" appends the following message to "Drafts":
"""
From: foo@bar.com
Date: 01 Jan 1980 00:00:00 +0000
This is a dra
"""
@ -25,6 +27,8 @@ Feature: IMAP Draft messages
And it succeeds
And IMAP client "1" appends the following message to "Drafts":
"""
From: foo@bar.com
Date: 01 Jan 1980 00:00:00 +0000
Subject: Basic Draft
Content-Type: text/plain
To: someone@example.com

View File

@ -12,6 +12,7 @@ Feature: IMAP import messages
When IMAP client "1" appends the following message to "INBOX":
"""
From: Bridge Test <bridgetest@pm.test>
Date: 01 Jan 1980 00:00:00 +0000
To: Internal Bridge <bridgetest@example.com>
Received: by 2002:0:0:0:0:0:0:0 with SMTP id 0123456789abcdef; Wed, 30 Dec 2020 01:23:45 0000
Subject: Basic text/plain message
@ -28,6 +29,7 @@ Feature: IMAP import messages
When IMAP client "1" appends the following message to "INBOX":
"""
From: Bridge Test <bridgetest@pm.test>
Date: 01 Jan 1980 00:00:00 +0000
To: Internal Bridge <bridgetest@example.com>
Subject: Message with double charset in content type
Content-Type: text/plain; charset=utf-8; charset=utf-8
@ -46,6 +48,7 @@ Feature: IMAP import messages
When IMAP client "1" appends the following message to "INBOX":
"""
From: Bridge Test <bridgetest@pm.test>
Date: 01 Jan 1980 00:00:00 +0000
To: Internal Bridge <bridgetest@protonmail.com>
Subject: Message with attachment name encoded by RFC 2047 without quoting
Content-type: multipart/mixed; boundary="boundary"
@ -96,6 +99,7 @@ Feature: IMAP import messages
When IMAP client "1" appends the following message to "Sent":
"""
From: Foo <foo@example.com>
Date: 01 Jan 1980 00:00:00 +0000
To: Bridge Test <bridgetest@pm.test>
Subject: Hello
Received: by 2002:0:0:0:0:0:0:0 with SMTP id 0123456789abcdef; Wed, 30 Dec 2020 01:23:45 0000
@ -112,6 +116,7 @@ Feature: IMAP import messages
When IMAP client "1" appends the following message to "Inbox":
"""
From: Foo <foo@example.com>
Date: 01 Jan 1980 00:00:00 +0000
To: Bridge Test <bridgetest@pm.test>
Subject: Hello
@ -127,6 +132,7 @@ Feature: IMAP import messages
When IMAP client "1" appends the following message to "Sent":
"""
From: Foo <foo@example.com>
Date: 01 Jan 1980 00:00:00 +0000
To: Bridge Test <bridgetest@pm.test>
Subject: Hello
@ -141,6 +147,8 @@ Feature: IMAP import messages
Scenario Outline: Import message without sender to <mailbox>
When IMAP client "1" appends the following message to "<mailbox>":
"""
From: Somebody@somewhere.org
Date: 01 Jan 1980 00:00:00 +0000
To: Lionel Richie <lionel@richie.com>
Subject: RE: Hello, is it me you looking for?
@ -161,6 +169,7 @@ Feature: IMAP import messages
When IMAP client "1" appends the following message to "INBOX":
"""
From: Foo <foo@example.com>
Date: 01 Jan 1980 00:00:00 +0000
To: Bridge Test <bridgetest@pm.test>
Subject: Embedded message
Content-Type: multipart/mixed; boundary="boundary"

View File

@ -17,6 +17,7 @@ Feature: IMAP move messages by append and delete (without MOVE support, e.g., Ou
"""
Received: by 2002:0:0:0:0:0:0:0 with SMTP id 0123456789abcdef; Wed, 30 Dec 2020 01:23:45 0000
From: sndr1@[domain]
Date: 01 Jan 1980 00:00:00 +0000
To: rcvr1@[domain]
Subject: subj1
@ -27,6 +28,7 @@ Feature: IMAP move messages by append and delete (without MOVE support, e.g., Ou
"""
Received: by 2002:0:0:0:0:0:0:0 with SMTP id 0123456789abcdef; Wed, 30 Dec 2020 01:23:45 0000
From: sndr2@[domain]
Date: 01 Jan 1980 00:00:00 +0000
To: rcvr2@[domain]
Subject: subj2

View File

@ -13,7 +13,9 @@ Feature: SMTP sending with APPENDing to Sent
# First do sending.
When SMTP client "1" sends the following message from "[user:user]@[domain]" to "[user:to]@[domain]":
"""
From: [user:user]@[domain]
To: Internal Bridge <[user:to]@[domain]>
Date: 01 Jan 1980 00:00:00 +0000
Subject: Manual send and append
Message-ID: bridgemessage42
@ -37,7 +39,9 @@ Feature: SMTP sending with APPENDing to Sent
# Then simulate manual append to Sent mailbox - message should be detected as a duplicate.
When IMAP client "1" appends the following message to "Sent":
"""
From: [user:user]@[domain]
To: Internal Bridge <[user:to]@[domain]>
Date: 01 Jan 1980 00:00:00 +0000
Subject: Manual send and append
Message-ID: bridgemessage42

View File

@ -446,6 +446,13 @@ func (s *scenario) imapClientAppendsTheFollowingMessagesToMailbox(clientID strin
return err
}
for idx, message := range messages {
if len(message.Date) == 0 {
logrus.Warnf("Appended message has no date, adding default one so it does not fail test")
}
messages[idx].Date = "23 Feb 80 00:00 GMT"
}
for _, message := range messages {
if err := clientAppend(client, mailbox, string(message.Build())); err != nil {
s.t.pushError(err)

View File

@ -1,4 +1,5 @@
From: Sender <sender@pm.me>
Date: 01 Jan 1980 00:00:00 +0000
To: Receiver <receiver@pm.me>
Received: by 2002:0:0:0:0:0:0:0 with SMTP id 0123456789abcdef; Wed, 30 Dec 2020 01:23:45 0000
Content-Type: text/plain; charset=ISO-8859-1

View File

@ -1,4 +1,5 @@
From: Sender <sender@pm.me>
Date: 01 Jan 1980 00:00:00 +0000
To: Receiver <receiver@pm.me>
Received: by 2002:0:0:0:0:0:0:0 with SMTP id 0123456789abcdef; Wed, 30 Dec 2020 01:23:45 0000
Content-Type: text/plain

View File

@ -1,4 +1,5 @@
From: Sender <sender@pm.me>
Date: 01 Jan 1980 00:00:00 +0000
To: Receiver <receiver@pm.me>
Received: by 2002:0:0:0:0:0:0:0 with SMTP id 0123456789abcdef; Wed, 30 Dec 2020 01:23:45 0000
Content-Type: text/plain; charset=KOI8R