forked from Silverfish/proton-bridge
GODT-1954: Draft message support
Add special case handling for draft messages so that if a Draft is updated via an event it is correctly updated on the IMAP client via a the new `imap.MessageUpdated event`. This patch also updates Gluon to the latest version.
This commit is contained in:
@ -21,7 +21,9 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/mail"
|
||||
|
||||
"github.com/ProtonMail/gopenpgp/v2/crypto"
|
||||
"github.com/bradenaw/juniper/iterator"
|
||||
"github.com/bradenaw/juniper/xslices"
|
||||
"github.com/cucumber/godog"
|
||||
@ -218,6 +220,50 @@ func (s *scenario) theAddressOfAccountHasNoKeys(address, username string) error
|
||||
return nil
|
||||
}
|
||||
|
||||
// accountDraftChanged changes the draft attributes, where draftIndex is
|
||||
// similar to sequential ID i.e. 1 represents the first message of draft folder
|
||||
// sorted by API creation time.
|
||||
func (s *scenario) addressDraftChanged(draftIndex int, address, username string, table *godog.Table) error {
|
||||
wantMessages, err := unmarshalTable[Message](table)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(wantMessages) != 1 {
|
||||
return fmt.Errorf("expected to have one row in table but got %d instead", len(wantMessages))
|
||||
}
|
||||
|
||||
draftID := s.t.getDraftID(username, draftIndex)
|
||||
|
||||
encBody := []byte{}
|
||||
|
||||
if wantMessages[0].Body != "" {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
if err := s.t.withClient(ctx, username, func(ctx context.Context, c *liteapi.Client) error {
|
||||
return s.t.withAddrKR(ctx, c, username, s.t.getUserAddrID(s.t.getUserID(username), address),
|
||||
func(ctx context.Context, addrKR *crypto.KeyRing) error {
|
||||
var err error
|
||||
encBody, err = liteapi.EncryptRFC822(addrKR, wantMessages[0].Build())
|
||||
return err
|
||||
})
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
changes := liteapi.DraftTemplate{
|
||||
Subject: wantMessages[0].Subject,
|
||||
Body: string(encBody),
|
||||
}
|
||||
if wantMessages[0].To != "" {
|
||||
changes.ToList = []*mail.Address{{Address: wantMessages[0].To}}
|
||||
}
|
||||
|
||||
return s.t.api.UpdateDraft(s.t.getUserID(username), draftID, changes)
|
||||
}
|
||||
|
||||
func (s *scenario) userLogsInWithUsernameAndPassword(username, password string) error {
|
||||
userID, err := s.t.bridge.LoginFull(context.Background(), username, []byte(password), nil, nil)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user