-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(GODT-1817): Extend move to not expunge original messages
Update connector interface to signal Gluon whether to expunge the original messages after a move command. This is required so that we can correctly support the concept of mail labels.
- Loading branch information
1 parent
b04fb94
commit 675bf5d
Showing
8 changed files
with
145 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
package tests | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/ProtonMail/gluon/connector" | ||
goimap "github.com/emersion/go-imap" | ||
"github.com/emersion/go-imap/client" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
"time" | ||
|
||
"github.com/ProtonMail/gluon/imap" | ||
) | ||
|
@@ -214,3 +220,126 @@ func TestConcurrency(t *testing.T) { | |
} | ||
}) | ||
} | ||
|
||
// disableRemoveFromMailboxConnector fails the first append and panics if move or remove takes place on the | ||
// connector. | ||
type simulateLabelConnector struct { | ||
*connector.Dummy | ||
mboxID imap.MailboxID | ||
} | ||
|
||
func (r *simulateLabelConnector) CreateMailbox(ctx context.Context, name []string) (imap.Mailbox, error) { | ||
mbox, err := r.Dummy.CreateMailbox(ctx, name) | ||
if err != nil { | ||
return mbox, err | ||
} | ||
|
||
if len(r.mboxID) == 0 { | ||
r.mboxID = mbox.ID | ||
} | ||
|
||
return mbox, nil | ||
} | ||
|
||
func (r *simulateLabelConnector) MoveMessages( | ||
ctx context.Context, | ||
ids []imap.MessageID, | ||
from imap.MailboxID, | ||
to imap.MailboxID, | ||
) (bool, error) { | ||
if _, err := r.Dummy.MoveMessages(ctx, ids, from, to); err != nil { | ||
return false, err | ||
} | ||
|
||
return to != r.mboxID, nil | ||
} | ||
|
||
type simulateLabelConnectorBuilder struct{} | ||
|
||
func (simulateLabelConnectorBuilder) New(usernames []string, password []byte, period time.Duration, flags, permFlags, attrs imap.FlagSet) Connector { | ||
return &simulateLabelConnector{ | ||
Dummy: connector.NewDummy(usernames, password, period, flags, permFlags, attrs), | ||
} | ||
} | ||
|
||
func TestMoveLabelBehavior(t *testing.T) { | ||
runOneToOneTestClientWithAuth(t, defaultServerOptions(t, withConnectorBuilder(&simulateLabelConnectorBuilder{})), func(client *client.Client, _ *testSession) { | ||
require.NoError(t, doAppendWithClient(client, "inbox", "To: [email protected]", time.Now())) | ||
require.NoError(t, doAppendWithClient(client, "inbox", "To: [email protected]", time.Now())) | ||
require.NoError(t, doAppendWithClient(client, "inbox", "To: [email protected]", time.Now())) | ||
|
||
require.NoError(t, client.Create("mylabel")) | ||
|
||
// Move message to label | ||
{ | ||
status, err := client.Select("INBOX", false) | ||
require.NoError(t, err) | ||
require.Equal(t, uint32(3), status.Messages) | ||
|
||
// Move one message to label | ||
require.NoError(t, client.Move(createSeqSet("1"), "mylabel")) | ||
|
||
// Inbox should have 3 messages | ||
status, err = client.Status("INBOX", []goimap.StatusItem{goimap.StatusMessages}) | ||
require.NoError(t, err) | ||
require.Equal(t, uint32(3), status.Messages) | ||
|
||
// Check all messages are still present | ||
newFetchCommand(t, client).withItems("ENVELOPE").fetch("1:3"). | ||
forSeqNum(1, func(builder *validatorBuilder) { | ||
builder.ignoreFlags() | ||
builder.wantEnvelope(func(builder *envelopeValidatorBuilder) { | ||
builder.wantTo("[email protected]") | ||
}) | ||
}). | ||
forSeqNum(2, func(builder *validatorBuilder) { | ||
builder.ignoreFlags() | ||
builder.wantEnvelope(func(builder *envelopeValidatorBuilder) { | ||
builder.wantTo("[email protected]") | ||
}) | ||
}). | ||
forSeqNum(3, func(builder *validatorBuilder) { | ||
builder.ignoreFlags() | ||
builder.wantEnvelope(func(builder *envelopeValidatorBuilder) { | ||
builder.wantTo("[email protected]") | ||
}) | ||
}). | ||
checkAndRequireMessageCount(3) | ||
|
||
// Label should have 1 message | ||
status, err = client.Status("mylabel", []goimap.StatusItem{goimap.StatusMessages}) | ||
require.NoError(t, err) | ||
require.Equal(t, uint32(1), status.Messages) | ||
|
||
} | ||
|
||
// Move message to inbox from label | ||
{ | ||
status, err := client.Select("mylabel", false) | ||
require.NoError(t, err) | ||
require.Equal(t, uint32(1), status.Messages) | ||
|
||
// Check it has the right message | ||
newFetchCommand(t, client).withItems("ENVELOPE").fetch("1").forSeqNum(1, func(builder *validatorBuilder) { | ||
builder.ignoreFlags() | ||
builder.wantEnvelope(func(builder *envelopeValidatorBuilder) { | ||
builder.wantTo("[email protected]") | ||
}) | ||
}).checkAndRequireMessageCount(1) | ||
|
||
// Move one message to label | ||
require.NoError(t, client.Move(createSeqSet("1"), "INBOX")) | ||
|
||
// Inbox should have 3 messages | ||
status, err = client.Status("INBOX", []goimap.StatusItem{goimap.StatusMessages}) | ||
require.NoError(t, err) | ||
require.Equal(t, uint32(3), status.Messages) | ||
|
||
// Label should have 1 message | ||
status, err = client.Status("mylabel", []goimap.StatusItem{goimap.StatusMessages}) | ||
require.NoError(t, err) | ||
require.Equal(t, uint32(0), status.Messages) | ||
} | ||
|
||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters