-
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.
fix(GODT-2007): On append do not add deleted messages to mbox
On append if the header contains a Gluon ID , we should only restore that messages to mailboxes if it has not been deleted.
- Loading branch information
1 parent
8bf679a
commit 4093b99
Showing
3 changed files
with
81 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"bytes" | ||
"context" | ||
"fmt" | ||
"github.com/ProtonMail/gluon/internal/ids" | ||
"os" | ||
"sync" | ||
"testing" | ||
|
@@ -312,3 +313,47 @@ func TestAppendCanHandleOutOfOrderUIDUpdates(t *testing.T) { | |
validateUIDListFn(2) | ||
}) | ||
} | ||
|
||
func TestGODT2007AppendInternalIDPresentOnDeletedMessage(t *testing.T) { | ||
const ( | ||
mailboxName = "saved-messages" | ||
) | ||
|
||
runOneToOneTestClientWithAuth(t, defaultServerOptions(t), func(client *client.Client, s *testSession) { | ||
// Create message and mark deleted. | ||
mboxID := s.mailboxCreated("user", []string{mailboxName}) | ||
messageID := s.messageCreated("user", mboxID, []byte("To: [email protected]\r\n"), time.Now()) | ||
s.flush("user") | ||
|
||
_, err := client.Select(mailboxName, false) | ||
require.NoError(t, err) | ||
|
||
{ | ||
// Check if the header is correctly set. | ||
result := newFetchCommand(t, client).withItems("UID", "BODY[HEADER]").fetch("1") | ||
result.forSeqNum(1, func(builder *validatorBuilder) { | ||
builder.ignoreFlags().wantSection("BODY[HEADER]", fmt.Sprintf("%v: 1", ids.InternalIDKey), "To: [email protected]\r\n") | ||
builder.wantUID(1) | ||
}) | ||
result.checkAndRequireMessageCount(1) | ||
} | ||
|
||
s.messageDeleted("user", messageID) | ||
s.flush("user") | ||
|
||
// Add the same message back with the same id | ||
require.NoError(t, doAppendWithClient(client, mailboxName, fmt.Sprintf("%v: 1\r\nTo: [email protected]\r\n", ids.InternalIDKey), time.Now())) | ||
|
||
{ | ||
// The message should have been created with a new internal id | ||
result := newFetchCommand(t, client).withItems("UID", "BODY[HEADER]").fetch("1") | ||
result.forSeqNum(1, func(builder *validatorBuilder) { | ||
// The header value appears twice because we don't delete existing headers, we only add new ones. | ||
builder.ignoreFlags().wantSection("BODY[HEADER]", fmt.Sprintf("%v: 2", ids.InternalIDKey), fmt.Sprintf("%v: 1", ids.InternalIDKey), "To: [email protected]\r\n") | ||
builder.wantUID(2) | ||
}) | ||
result.checkAndRequireMessageCount(1) | ||
} | ||
|
||
}) | ||
} |