-
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.
To be used in cases where one needs to atomically replace a message (e.g: Drafts) in one go. This was previously possible with a combination of Delete + Create update, but these were not guaranteed to be atomic and could cause undefined behaviors if something else happened in between. The old logic to handle the replacement of delete messages on create has been reverted. It is now expected that this type of behavior uses the newly introduced update.
- Loading branch information
1 parent
4093b99
commit 7b6e1df
Showing
6 changed files
with
187 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package imap | ||
|
||
import ( | ||
"fmt" | ||
"github.com/bradenaw/juniper/xslices" | ||
) | ||
|
||
// MessageUpdated replaces the previous behavior of MessageDelete followed by MessageCreate. Furthermore, it guarantees | ||
// that the operation is executed atomically. | ||
type MessageUpdated struct { | ||
updateBase | ||
*updateWaiter | ||
|
||
Message Message | ||
Literal []byte | ||
MailboxIDs []MailboxID | ||
ParsedMessage *ParsedMessage | ||
} | ||
|
||
func NewMessageUpdated(message Message, literal []byte, mailboxIDs []MailboxID, parsedMessage *ParsedMessage) *MessageUpdated { | ||
return &MessageUpdated{ | ||
updateWaiter: newUpdateWaiter(), | ||
Message: message, | ||
Literal: literal, | ||
MailboxIDs: mailboxIDs, | ||
ParsedMessage: parsedMessage, | ||
} | ||
} | ||
|
||
func (u *MessageUpdated) String() string { | ||
return fmt.Sprintf("MessageUpdate: ID:%v Mailboxes:%v Flags:%s", | ||
u.Message.ID.ShortID(), | ||
xslices.Map(u.MailboxIDs, func(mboxID MailboxID) string { | ||
return mboxID.ShortID() | ||
}), | ||
u.Message.Flags.ToSlice(), | ||
) | ||
} |
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 |
---|---|---|
|
@@ -189,8 +189,7 @@ func TestRemoteMessageUpdate(t *testing.T) { | |
c.S(`* STATUS "mbox1" (MESSAGES 1)`) | ||
c.S(`A002 OK STATUS`) | ||
|
||
s.messageDeleted("user", messageID) | ||
s.messageCreatedWithID("user", messageID, mailboxID, []byte("To: [email protected]"), time.Now()) | ||
s.messageUpdatedWithID("user", messageID, mailboxID, []byte("To: [email protected]"), time.Now()) | ||
s.flush("user") | ||
|
||
c.C(`A002 STATUS mbox1 (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