forked from Silverfish/proton-bridge
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:
@ -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)
|
||||
|
||||
19
tests/features/imap/message/fetch.feature
Normal file
19
tests/features/imap/message/fetch.feature
Normal 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"
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user