mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-16 07:06:45 +00:00
Finish tests for moving without MOVE support
This commit is contained in:
@ -1,31 +0,0 @@
|
|||||||
Feature: IMAP move messages like Outlook
|
|
||||||
Background:
|
|
||||||
Given there is connected user "user"
|
|
||||||
And there is "user" with mailbox "Folders/mbox"
|
|
||||||
And there are messages in mailbox "INBOX" for "user"
|
|
||||||
| from | to | subject | body |
|
|
||||||
| john.doe@mail.com | user@pm.me | foo | hello |
|
|
||||||
| jane.doe@mail.com | name@pm.me | bar | world |
|
|
||||||
And there is IMAP client logged in as "user"
|
|
||||||
And there is IMAP client selected in "INBOX"
|
|
||||||
|
|
||||||
Scenario: Move message from INBOX to mailbox like outlook
|
|
||||||
When IMAP client moves messages "2" to "<mailbox>" like Outlook for "user"
|
|
||||||
Then IMAP response is "OK"
|
|
||||||
And mailbox "INBOX" for "user" has messages
|
|
||||||
| from | to | subject |
|
|
||||||
| jane.doe@mail.com | name@pm.me | bar |
|
|
||||||
And mailbox "<mailbox>" for "user" has messages
|
|
||||||
| from | to | subject |
|
|
||||||
| john.doe@mail.com | user@pm.me | foo |
|
|
||||||
|
|
||||||
Examples:
|
|
||||||
| mailbox |
|
|
||||||
| Archive |
|
|
||||||
| Folders/mbox |
|
|
||||||
| Spam |
|
|
||||||
| Trash |
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#Scenario: Move message from Trash/Spam to INBOX like outlook
|
|
||||||
60
test/features/imap/message/move_without_support.feature
Normal file
60
test/features/imap/message/move_without_support.feature
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
Feature: IMAP move messages by append and delete (without MOVE support, e.g., Outlook)
|
||||||
|
Background:
|
||||||
|
Given there is connected user "user"
|
||||||
|
And there is "user" with mailbox "Folders/mbox"
|
||||||
|
And there is IMAP client "source" logged in as "user"
|
||||||
|
And there is IMAP client "target" logged in as "user"
|
||||||
|
|
||||||
|
Scenario Outline: Move message from INBOX to mailbox by append and delete
|
||||||
|
# Messages are inserted in opposite way to keep increasing ID.
|
||||||
|
# Sequence numbers are then opposite than listed below.
|
||||||
|
Given there are messages in mailbox "INBOX" for "user"
|
||||||
|
| from | to | subject | body |
|
||||||
|
| john.doe@mail.com | user@pm.me | foo | hello |
|
||||||
|
| jane.doe@mail.com | name@pm.me | bar | world |
|
||||||
|
And there is IMAP client "source" selected in "INBOX"
|
||||||
|
And there is IMAP client "target" selected in "<mailbox>"
|
||||||
|
When IMAP clients "source" and "target" move message "1" of "user" from "INBOX" to "<mailbox>" by append and delete
|
||||||
|
Then IMAP response to "source" is "OK"
|
||||||
|
Then IMAP response to "target" is "OK"
|
||||||
|
When IMAP client "source" sends expunge
|
||||||
|
Then IMAP response to "source" is "OK"
|
||||||
|
And mailbox "INBOX" for "user" has messages
|
||||||
|
| from | to | subject |
|
||||||
|
| john.doe@mail.com | user@pm.me | foo |
|
||||||
|
And mailbox "<mailbox>" for "user" has messages
|
||||||
|
| from | to | subject |
|
||||||
|
| jane.doe@mail.com | name@pm.me | bar |
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
| mailbox |
|
||||||
|
| Archive |
|
||||||
|
| Folders/mbox |
|
||||||
|
| Spam |
|
||||||
|
| Trash |
|
||||||
|
|
||||||
|
Scenario Outline: Move message from Trash/Spam to INBOX by append and delete
|
||||||
|
# Messages are inserted in opposite way to keep increasing ID.
|
||||||
|
# Sequence numbers are then opposite than listed below.
|
||||||
|
Given there are messages in mailbox "<mailbox>" for "user"
|
||||||
|
| from | to | subject | body |
|
||||||
|
| john.doe@mail.com | user@pm.me | foo | hello |
|
||||||
|
| jane.doe@mail.com | name@pm.me | bar | world |
|
||||||
|
And there is IMAP client "source" selected in "<mailbox>"
|
||||||
|
And there is IMAP client "target" selected in "INBOX"
|
||||||
|
When IMAP clients "source" and "target" move message "1" of "user" from "<mailbox>" to "INBOX" by append and delete
|
||||||
|
Then IMAP response to "source" is "OK"
|
||||||
|
Then IMAP response to "target" is "OK"
|
||||||
|
When IMAP client "source" sends expunge
|
||||||
|
Then IMAP response to "source" is "OK"
|
||||||
|
And mailbox "INBOX" for "user" has messages
|
||||||
|
| from | to | subject |
|
||||||
|
| jane.doe@mail.com | name@pm.me | bar |
|
||||||
|
And mailbox "<mailbox>" for "user" has messages
|
||||||
|
| from | to | subject |
|
||||||
|
| john.doe@mail.com | user@pm.me | foo |
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
| mailbox |
|
||||||
|
| Spam |
|
||||||
|
| Trash |
|
||||||
@ -19,6 +19,7 @@ package tests
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/cucumber/godog"
|
"github.com/cucumber/godog"
|
||||||
@ -33,7 +34,7 @@ func IMAPActionsMessagesFeatureContext(s *godog.Suite) {
|
|||||||
s.Step(`^IMAP client searches for "([^"]*)"$`, imapClientSearchesFor)
|
s.Step(`^IMAP client searches for "([^"]*)"$`, imapClientSearchesFor)
|
||||||
s.Step(`^IMAP client copies messages "([^"]*)" to "([^"]*)"$`, imapClientCopiesMessagesTo)
|
s.Step(`^IMAP client copies messages "([^"]*)" to "([^"]*)"$`, imapClientCopiesMessagesTo)
|
||||||
s.Step(`^IMAP client moves messages "([^"]*)" to "([^"]*)"$`, imapClientMovesMessagesTo)
|
s.Step(`^IMAP client moves messages "([^"]*)" to "([^"]*)"$`, imapClientMovesMessagesTo)
|
||||||
s.Step(`^IMAP client moves messages "([^"]*)" to "([^"]*)" like outlook$`, imapClientMovesMessagesToLikeOutlook)
|
s.Step(`^IMAP clients "([^"]*)" and "([^"]*)" move message "([^"]*)" of "([^"]*)" from "([^"]*)" to "([^"]*)" by append and delete$`, imapClientsMoveMessageOfUserFromToByAppendAndDelete)
|
||||||
s.Step(`^IMAP client imports message to "([^"]*)"$`, imapClientCreatesMessage)
|
s.Step(`^IMAP client imports message to "([^"]*)"$`, imapClientCreatesMessage)
|
||||||
s.Step(`^IMAP client imports message to "([^"]*)" with encoding "([^"]*)"$`, imapClientCreatesMessageWithEncoding)
|
s.Step(`^IMAP client imports message to "([^"]*)" with encoding "([^"]*)"$`, imapClientCreatesMessageWithEncoding)
|
||||||
s.Step(`^IMAP client creates message "([^"]*)" from "([^"]*)" to "([^"]*)" with body "([^"]*)" in "([^"]*)"$`, imapClientCreatesMessageFromToWithBody)
|
s.Step(`^IMAP client creates message "([^"]*)" from "([^"]*)" to "([^"]*)" with body "([^"]*)" in "([^"]*)"$`, imapClientCreatesMessageFromToWithBody)
|
||||||
@ -95,45 +96,51 @@ func imapClientMovesMessagesTo(messageRange, newMailboxName string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func imapClientMovesMessagesToLikeOutlook(messageRange, newMailboxName, user string) error {
|
func imapClientsMoveMessageOfUserFromToByAppendAndDelete(sourceIMAPClient, targetIMAPClient, messageUID, bddUserID, sourceMailboxName, targetMailboxName string) error {
|
||||||
sourceClient := "imap"
|
account := ctx.GetTestAccount(bddUserID)
|
||||||
fetchResp := ctx.GetIMAPClient(sourceClient).Fetch(messageRange, "body.peek[]")
|
if account == nil {
|
||||||
fetchResp.AssertOK()
|
return godog.ErrPending
|
||||||
if err := ctx.GetTestingError(); err != nil {
|
}
|
||||||
return err
|
sourceMailbox, err := ctx.GetStoreMailbox(account.Username(), account.AddressID(), sourceMailboxName)
|
||||||
|
if err != nil {
|
||||||
|
return internalError(err, "getting store mailbox")
|
||||||
|
}
|
||||||
|
uid, err := strconv.ParseUint(messageUID, 10, 32)
|
||||||
|
if err != nil {
|
||||||
|
return internalError(err, "parsing message UID")
|
||||||
|
}
|
||||||
|
apiIDs, err := sourceMailbox.GetAPIIDsFromUIDRange(uint32(uid), uint32(uid))
|
||||||
|
if err != nil {
|
||||||
|
return internalError(err, "getting API IDs from sequence range")
|
||||||
|
}
|
||||||
|
message, err := sourceMailbox.GetMessage(apiIDs[0])
|
||||||
|
if err != nil {
|
||||||
|
return internalError(err, "getting message by ID")
|
||||||
}
|
}
|
||||||
|
|
||||||
targetClient := "target"
|
wg := sync.WaitGroup{}
|
||||||
if err := thereIsIMAPClientNamedLoggedInAs(targetClient, user); err != nil {
|
wg.Add(2)
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := thereIsIMAPClientNamedSelectedIn(targetClient, newMailboxName); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
movingLikeOutlook := sync.WaitGroup{}
|
|
||||||
movingLikeOutlook.Add(2)
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer movingLikeOutlook.Done()
|
defer wg.Done()
|
||||||
for _, msg := range fetchResp.Sections() {
|
msg := message.Message()
|
||||||
res := ctx.GetIMAPClient(targetClient).Append(newMailboxName, msg)
|
_ = imapClientNamedCreatesMessageFromToWithBody(
|
||||||
res.AssertOK()
|
targetIMAPClient,
|
||||||
}
|
msg.Subject,
|
||||||
|
msg.Sender.String(),
|
||||||
|
msg.ToList[0].String(),
|
||||||
|
msg.Body,
|
||||||
|
targetMailboxName,
|
||||||
|
)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer movingLikeOutlook.Done()
|
defer wg.Done()
|
||||||
imapClientNamedMarksMessageAsDeleted(sourceClient, messageRange)
|
_ = imapClientNamedMarksMessageAsDeleted(sourceIMAPClient, messageUID)
|
||||||
ctx.GetIMAPLastResponse(sourceClient).AssertOK()
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
movingLikeOutlook.Wait()
|
wg.Wait()
|
||||||
|
return nil
|
||||||
imapClientExpunge()
|
|
||||||
ctx.GetIMAPLastResponse(sourceClient).AssertOK()
|
|
||||||
|
|
||||||
return ctx.GetTestingError()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func imapClientCreatesMessage(mailboxName string, message *gherkin.DocString) error {
|
func imapClientCreatesMessage(mailboxName string, message *gherkin.DocString) error {
|
||||||
@ -162,8 +169,12 @@ func imapClientCreatesMessageWithEncoding(mailboxName, encodingName string, mess
|
|||||||
}
|
}
|
||||||
|
|
||||||
func imapClientCreatesMessageFromToWithBody(subject, from, to, body, mailboxName string) error {
|
func imapClientCreatesMessageFromToWithBody(subject, from, to, body, mailboxName string) error {
|
||||||
res := ctx.GetIMAPClient("imap").AppendBody(mailboxName, subject, from, to, body)
|
return imapClientNamedCreatesMessageFromToWithBody("imap", subject, from, to, body, mailboxName)
|
||||||
ctx.SetIMAPLastResponse("imap", res)
|
}
|
||||||
|
|
||||||
|
func imapClientNamedCreatesMessageFromToWithBody(imapClient, subject, from, to, body, mailboxName string) error {
|
||||||
|
res := ctx.GetIMAPClient(imapClient).AppendBody(mailboxName, subject, from, to, body)
|
||||||
|
ctx.SetIMAPLastResponse(imapClient, res)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -37,8 +37,6 @@ type IMAPResponse struct {
|
|||||||
done bool
|
done bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ir *IMAPResponse) Sections() []string { return ir.sections }
|
|
||||||
|
|
||||||
func (ir *IMAPResponse) sendCommand(reqTag string, reqIndex int, command string, debug *debug, conn io.Writer, response *bufio.Reader) {
|
func (ir *IMAPResponse) sendCommand(reqTag string, reqIndex int, command string, debug *debug, conn io.Writer, response *bufio.Reader) {
|
||||||
defer func() { ir.done = true }()
|
defer func() { ir.done = true }()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user