GODT-2170: Improving test server behaviour.

This commit is contained in:
Jakub
2022-12-01 15:52:42 +01:00
committed by James Houlahan
parent 828fe0e86e
commit 8408a5fdc0
9 changed files with 36 additions and 16 deletions

View File

@ -487,10 +487,6 @@ func (user *User) handleUpdateDraftEvent(ctx context.Context, event proton.Messa
"subject": logging.Sensitive(event.Message.Subject),
}).Info("Handling draft updated event")
for _, updateCh := range user.updateCh {
updateCh.Enqueue(imap.NewMessagesDeleted(imap.MessageID(event.ID)))
}
full, err := user.client.GetFullMessage(ctx, event.Message.ID)
if err != nil {
return fmt.Errorf("failed to get full draft: %w", err)
@ -502,7 +498,12 @@ func (user *User) handleUpdateDraftEvent(ctx context.Context, event proton.Messa
return fmt.Errorf("failed to build RFC822 draft: %w", err)
}
user.updateCh[full.AddressID].Enqueue(imap.NewMessagesCreated(buildRes.update))
user.updateCh[full.AddressID].Enqueue(imap.NewMessageUpdated(
buildRes.update.Message,
buildRes.update.Literal,
buildRes.update.MailboxIDs,
buildRes.update.ParsedMessage,
))
return nil
})

View File

@ -21,6 +21,7 @@ import (
"bytes"
"context"
"fmt"
"net/mail"
"sync/atomic"
"time"
@ -442,7 +443,7 @@ func (conn *imapConnector) importMessage(
messageID := ""
if slices.Contains(labelIDs, proton.DraftsLabel) {
msg, err := conn.createDraft(ctx, literal, addrKR)
msg, err := conn.createDraft(ctx, literal, addrKR, conn.apiAddrs[conn.addrID])
if err != nil {
return fmt.Errorf("failed to create draft: %w", err)
}
@ -516,7 +517,7 @@ func toIMAPMessage(message proton.MessageMetadata) imap.Message {
}
}
func (conn *imapConnector) createDraft(ctx context.Context, literal []byte, addrKR *crypto.KeyRing) (proton.Message, error) { //nolint:funlen
func (conn *imapConnector) createDraft(ctx context.Context, literal []byte, addrKR *crypto.KeyRing, sender proton.Address) (proton.Message, error) { //nolint:funlen
// Create a new message parser from the reader.
parser, err := parser.New(bytes.NewReader(literal))
if err != nil {
@ -549,7 +550,7 @@ func (conn *imapConnector) createDraft(ctx context.Context, literal []byte, addr
Body: armBody,
MIMEType: message.MIMEType,
Sender: message.Sender,
Sender: &mail.Address{Name: sender.DisplayName, Address: sender.Email},
ToList: message.ToList,
CCList: message.CCList,
BCCList: message.BCCList,