GODT-1817: Restore old date message feature test + fix

This patch also fixes the message builder to not override other headers
that already exist to avoid overriding sanitized header entries.
This commit is contained in:
Leander Beernaert 2023-01-03 15:29:29 +01:00
parent 6e7f374b0d
commit 272e3895fd
7 changed files with 72 additions and 5 deletions

2
go.mod
View File

@ -7,7 +7,7 @@ require (
github.com/Masterminds/semver/v3 v3.1.1
github.com/ProtonMail/gluon v0.14.2-0.20221220184532-b04fb948e367
github.com/ProtonMail/go-autostart v0.0.0-20210130080809-00ed301c8e9a
github.com/ProtonMail/go-proton-api v0.2.3
github.com/ProtonMail/go-proton-api v0.2.4-0.20230103140323-680d85d1c3f0
github.com/ProtonMail/go-rfc5322 v0.11.0
github.com/ProtonMail/gopenpgp/v2 v2.4.10
github.com/PuerkitoBio/goquery v1.8.0

4
go.sum
View File

@ -43,8 +43,8 @@ github.com/ProtonMail/go-message v0.0.0-20210611055058-fabeff2ec753/go.mod h1:NB
github.com/ProtonMail/go-mime v0.0.0-20220302105931-303f85f7fe0f/go.mod h1:NYt+V3/4rEeDuaev/zw1zCq8uqVEuPHzDPo3OZrlGJ4=
github.com/ProtonMail/go-mime v0.0.0-20220429130430-2192574d760f h1:4IWzKjHzZxdrW9k4zl/qCwenOVHDbVDADPPHFLjs0Oc=
github.com/ProtonMail/go-mime v0.0.0-20220429130430-2192574d760f/go.mod h1:qRZgbeASl2a9OwmsV85aWwRqic0NHPh+9ewGAzb4cgM=
github.com/ProtonMail/go-proton-api v0.2.3 h1:MItHzfA67PRU4CQ9jtuIWD88YQBsyBlAquLBJ/SO2/M=
github.com/ProtonMail/go-proton-api v0.2.3/go.mod h1:JUo5IQG0hNuPRuDpOUsCOvtee6UjTEHHF1QN2i8RSos=
github.com/ProtonMail/go-proton-api v0.2.4-0.20230103140323-680d85d1c3f0 h1:0QzaGMTJsW+LT1+pCG93eYadIwZlgX2aNfwP3O83Mo0=
github.com/ProtonMail/go-proton-api v0.2.4-0.20230103140323-680d85d1c3f0/go.mod h1:JUo5IQG0hNuPRuDpOUsCOvtee6UjTEHHF1QN2i8RSos=
github.com/ProtonMail/go-rfc5322 v0.11.0 h1:o5Obrm4DpmQEffvgsVqG6S4BKwC1Wat+hYwjIp2YcCY=
github.com/ProtonMail/go-rfc5322 v0.11.0/go.mod h1:6oOKr0jXvpoE6pwTx/HukigQpX2J9WUf6h0auplrFTw=
github.com/ProtonMail/go-srp v0.0.5 h1:xhUioxZgDbCnpo9JehyFhwwsn9JLWkUGfB0oiKXgiGg=

View File

@ -364,7 +364,10 @@ func writeMultipartEncryptedRFC822(header message.Header, body []byte) ([]byte,
entFields := bodyHeader.Fields()
for entFields.Next() {
header.Set(entFields.Key(), entFields.Value())
// Only set the header field if it is present. Header sanitation will be overridden otherwise.
if !header.Has(entFields.Key()) {
header.Set(entFields.Key(), entFields.Value())
}
}
if err := textproto.WriteHeader(buf, header.Header); err != nil {

View File

@ -202,6 +202,7 @@ func TestFeatures(testingT *testing.T) {
ctx.Step(`^IMAP client "([^"]*)" appends the following messages to "([^"]*)":$`, s.imapClientAppendsTheFollowingMessagesToMailbox)
ctx.Step(`^IMAP client "([^"]*)" appends "([^"]*)" to "([^"]*)"$`, s.imapClientAppendsToMailbox)
ctx.Step(`^IMAP clients "([^"]*)" and "([^"]*)" move message seq "([^"]*)" of "([^"]*)" to "([^"]*)" by ([^"]*) ([^"]*) ([^"]*)`, s.imapClientsMoveMessageSeqOfUserFromToByOrderedOperations)
ctx.Step(`^IMAP client "([^"]*)" sees header "([^"]*)" in message with subject "([^"]*)" in "([^"]*)"$`, s.imapClientSeesHeaderInMessageWithSubject)
// ==== SMTP ====
ctx.Step(`^user "([^"]*)" connects SMTP client "([^"]*)"$`, s.userConnectsSMTPClient)

View File

@ -0,0 +1,19 @@
Feature: IMAP Fetch
Background:
Given there exists an account with username "[user:user]" and password "password"
And the account "[user:user]" has the following custom mailboxes:
| name | type |
| mbox | folder |
And the address "[user:user]@[domain]" of account "[user:user]" has the following messages in "Inbox":
| from | to | subject | date |
| john.doe@mail.com | [user:user]@[domain] | foo | 13 Jul 69 00:00 +0000 |
And bridge starts
And the user logs in with username "[user:user]" and password "password"
And user "[user:user]" finishes syncing
And user "[user:user]" connects and authenticates IMAP client "1"
Scenario: Fetch very old message
Given IMAP client "1" sees the following messages in "INBOX":
| from | to | subject | date |
| john.doe@mail.com | [user:user]@[domain] | foo | 13 Aug 82 00:00 +0000 |
Then IMAP client "1" sees header "X-Original-Date: Sun, 13 Jul 1969 00:00:00 +0000" in message with subject "foo" in "INBOX"

View File

@ -27,6 +27,7 @@ import (
"strings"
"time"
"github.com/ProtonMail/gluon/rfc822"
"github.com/bradenaw/juniper/iterator"
"github.com/bradenaw/juniper/xslices"
"github.com/cucumber/godog"
@ -503,6 +504,39 @@ func (s *scenario) imapClientsMoveMessageSeqOfUserFromToByOrderedOperations(sour
return nil
}
func (s *scenario) imapClientSeesHeaderInMessageWithSubject(clientID, headerString, subject, mailbox string) error {
_, client := s.t.getIMAPClient(clientID)
messages, err := clientFetch(client, mailbox)
if err != nil {
return err
}
section, err := imap.ParseBodySectionName("BODY[]")
if err != nil {
return err
}
for _, m := range messages {
if m.Envelope.Subject == subject {
literal, err := io.ReadAll(m.GetBody(section))
if err != nil {
return err
}
header, _ := rfc822.Split(literal)
if !bytes.Contains(header, []byte(headerString)) {
return fmt.Errorf("message header does not contain '%v'", headerString)
}
return nil
}
}
return fmt.Errorf("could not find message with given subject '%v'", subject)
}
func clientList(client *client.Client) []*imap.MailboxInfo {
resCh := make(chan *imap.MailboxInfo)

View File

@ -40,6 +40,7 @@ type Message struct {
MIMEType string `bdd:"mime-type"`
Attachments string `bdd:"attachments"`
MessageID string `bdd:"message-id"`
Date string `bdd:"date"`
From string `bdd:"from"`
To string `bdd:"to"`
@ -73,6 +74,14 @@ func (msg Message) Build() []byte {
b = append(b, "Subject: "+msg.Subject+"\r\n"...)
}
if msg.Date != "" {
date, err := time.Parse(time.RFC822, msg.Date)
if err != nil {
panic(err)
}
b = append(b, "Date: "+date.Format(time.RFC822Z)+"\r\n"...)
}
b = append(b, "\r\n"+msg.Body+"\r\n"...)
return b
@ -114,7 +123,8 @@ func newMessageFromIMAP(msg *imap.Message) Message {
Attachments: strings.Join(xslices.Map(m.Attachments, func(att message.Attachment) string { return att.Name }), ", "),
MessageID: msg.Envelope.MessageId,
Unread: !slices.Contains(msg.Flags, imap.SeenFlag),
Deleted: !slices.Contains(msg.Flags, imap.DeletedFlag),
Deleted: slices.Contains(msg.Flags, imap.DeletedFlag),
Date: msg.Envelope.Date.Format(time.RFC822Z),
}
if len(msg.Envelope.From) > 0 {