diff --git a/internal/user/imap.go b/internal/user/imap.go index 479c6ca0..c0d5445d 100644 --- a/internal/user/imap.go +++ b/internal/user/imap.go @@ -236,6 +236,8 @@ func (conn *imapConnector) DeleteMailbox(ctx context.Context, labelID imap.Mailb } // CreateMessage creates a new message on the remote. +// +// nolint:funlen func (conn *imapConnector) CreateMessage( ctx context.Context, mailboxID imap.MailboxID, @@ -279,9 +281,17 @@ func (conn *imapConnector) CreateMessage( return imap.Message{}, nil, err } - if header.Has("Received") { + switch { + case mailboxID == liteapi.InboxLabel: wantFlags = wantFlags.Add(liteapi.MessageFlagReceived) - } else { + + case mailboxID == liteapi.SentLabel: + wantFlags = wantFlags.Add(liteapi.MessageFlagSent) + + case header.Has("Received"): + wantFlags = wantFlags.Add(liteapi.MessageFlagReceived) + + default: wantFlags = wantFlags.Add(liteapi.MessageFlagSent) } } diff --git a/tests/features/imap/message/create.feature b/tests/features/imap/message/create.feature index 3e1a90b2..4a549572 100644 --- a/tests/features/imap/message/create.feature +++ b/tests/features/imap/message/create.feature @@ -15,6 +15,9 @@ Feature: IMAP create messages And IMAP client "1" sees the following messages in "INBOX": | from | to | subject | body | | john.doe@email.com | user@pm.me | foo | bar | + And IMAP client "1" sees the following messages in "All Mail": + | from | to | subject | body | + | john.doe@email.com | user@pm.me | foo | bar | Scenario: Creates draft When IMAP client "1" appends the following messages to "Drafts": @@ -24,6 +27,9 @@ Feature: IMAP create messages And IMAP client "1" sees the following messages in "Drafts": | from | to | subject | body | | user@pm.me | john.doe@email.com | foo | bar | + And IMAP client "1" sees the following messages in "All Mail": + | from | to | subject | body | + | user@pm.me | john.doe@email.com | foo | bar | Scenario: Creates message sent from user's primary address When IMAP client "1" appends the following messages to "Sent": @@ -33,6 +39,9 @@ Feature: IMAP create messages And IMAP client "1" sees the following messages in "Sent": | from | to | subject | body | | user@pm.me | john.doe@email.com | foo | bar | + And IMAP client "1" sees the following messages in "All Mail": + | from | to | subject | body | + | user@pm.me | john.doe@email.com | foo | bar | Scenario: Creates message sent from user's secondary address When IMAP client "1" appends the following messages to "Sent": @@ -42,6 +51,9 @@ Feature: IMAP create messages And IMAP client "1" sees the following messages in "Sent": | from | to | subject | body | | alias@pm.me | john.doe@email.com | foo | bar | + And IMAP client "1" sees the following messages in "All Mail": + | from | to | subject | body | + | alias@pm.me | john.doe@email.com | foo | bar | Scenario: Imports an unrelated message to inbox When IMAP client "1" appends the following messages to "INBOX": @@ -51,6 +63,9 @@ Feature: IMAP create messages And IMAP client "1" sees the following messages in "INBOX": | from | to | subject | body | | john.doe@email.com | john.doe2@pm.me | foo | bar | + And IMAP client "1" sees the following messages in "All Mail": + | from | to | subject | body | + | john.doe@email.com | john.doe2@pm.me | foo | bar | Scenario: Imports an unrelated message to sent When IMAP client "1" appends the following messages to "Sent": @@ -59,4 +74,7 @@ Feature: IMAP create messages Then it succeeds And IMAP client "1" sees the following messages in "Sent": | from | to | subject | body | - | john.doe@email.com | john.doe2@pm.me | foo | bar | \ No newline at end of file + | john.doe@email.com | john.doe2@pm.me | foo | bar | + And IMAP client "1" sees the following messages in "All Mail": + | from | to | subject | body | + | john.doe@email.com | john.doe2@pm.me | foo | bar | diff --git a/tests/features/imap/message/import.feature b/tests/features/imap/message/import.feature index 5f34711a..a2de4212 100644 --- a/tests/features/imap/message/import.feature +++ b/tests/features/imap/message/import.feature @@ -74,13 +74,28 @@ Feature: IMAP import messages Hello """ Then it succeeds + And IMAP client "1" eventually sees the following messages in "Sent": + | from | to | subject | body | + | foo@example.com | bridgetest@pm.test | Hello | Hello | + And IMAP client "1" sees 0 messages in "Inbox" + + Scenario: Import non-received message to Inbox + When IMAP client "1" appends the following message to "Inbox": + """ + From: Foo + To: Bridge Test + Subject: Hello + + Hello + """ + Then it succeeds And IMAP client "1" eventually sees the following messages in "INBOX": | from | to | subject | body | | foo@example.com | bridgetest@pm.test | Hello | Hello | And IMAP client "1" sees 0 messages in "Sent" - Scenario: Import non-received message to Inbox - When IMAP client "1" appends the following message to "Inbox": + Scenario: Import non-received message to Sent + When IMAP client "1" appends the following message to "Sent": """ From: Foo To: Bridge Test @@ -144,4 +159,4 @@ Feature: IMAP import messages --boundary-- """ - Then it succeeds \ No newline at end of file + Then it succeeds diff --git a/tests/types_test.go b/tests/types_test.go index f76571f4..e42ace4b 100644 --- a/tests/types_test.go +++ b/tests/types_test.go @@ -144,7 +144,7 @@ func matchMessages(have, want []Message) error { }) if !IsSub(ToAny(have), ToAny(want)) { - return fmt.Errorf("missing messages: %v", want) + return fmt.Errorf("missing messages: have %+v, want %+v", have, want) } return nil