Other: Allow non-received messages to be imported to INBOX

This commit is contained in:
James Houlahan 2022-11-02 15:29:27 +01:00
parent 943d95a725
commit 4ded8784fc
4 changed files with 50 additions and 7 deletions

View File

@ -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)
}
}

View File

@ -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 |
| 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 |

View File

@ -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 <foo@example.com>
To: Bridge Test <bridgetest@pm.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 <foo@example.com>
To: Bridge Test <bridgetest@pm.test>
@ -144,4 +159,4 @@ Feature: IMAP import messages
--boundary--
"""
Then it succeeds
Then it succeeds

View File

@ -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