forked from Silverfish/proton-bridge
Other: Allow non-received messages to be imported to INBOX
This commit is contained in:
@ -236,6 +236,8 @@ func (conn *imapConnector) DeleteMailbox(ctx context.Context, labelID imap.Mailb
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateMessage creates a new message on the remote.
|
// CreateMessage creates a new message on the remote.
|
||||||
|
//
|
||||||
|
// nolint:funlen
|
||||||
func (conn *imapConnector) CreateMessage(
|
func (conn *imapConnector) CreateMessage(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
mailboxID imap.MailboxID,
|
mailboxID imap.MailboxID,
|
||||||
@ -279,9 +281,17 @@ func (conn *imapConnector) CreateMessage(
|
|||||||
return imap.Message{}, nil, err
|
return imap.Message{}, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if header.Has("Received") {
|
switch {
|
||||||
|
case mailboxID == liteapi.InboxLabel:
|
||||||
wantFlags = wantFlags.Add(liteapi.MessageFlagReceived)
|
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)
|
wantFlags = wantFlags.Add(liteapi.MessageFlagSent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,6 +15,9 @@ Feature: IMAP create messages
|
|||||||
And IMAP client "1" sees the following messages in "INBOX":
|
And IMAP client "1" sees the following messages in "INBOX":
|
||||||
| from | to | subject | body |
|
| from | to | subject | body |
|
||||||
| john.doe@email.com | user@pm.me | foo | bar |
|
| 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
|
Scenario: Creates draft
|
||||||
When IMAP client "1" appends the following messages to "Drafts":
|
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":
|
And IMAP client "1" sees the following messages in "Drafts":
|
||||||
| from | to | subject | body |
|
| from | to | subject | body |
|
||||||
| user@pm.me | john.doe@email.com | foo | bar |
|
| 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
|
Scenario: Creates message sent from user's primary address
|
||||||
When IMAP client "1" appends the following messages to "Sent":
|
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":
|
And IMAP client "1" sees the following messages in "Sent":
|
||||||
| from | to | subject | body |
|
| from | to | subject | body |
|
||||||
| user@pm.me | john.doe@email.com | foo | bar |
|
| 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
|
Scenario: Creates message sent from user's secondary address
|
||||||
When IMAP client "1" appends the following messages to "Sent":
|
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":
|
And IMAP client "1" sees the following messages in "Sent":
|
||||||
| from | to | subject | body |
|
| from | to | subject | body |
|
||||||
| alias@pm.me | john.doe@email.com | foo | bar |
|
| 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
|
Scenario: Imports an unrelated message to inbox
|
||||||
When IMAP client "1" appends the following messages 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":
|
And IMAP client "1" sees the following messages in "INBOX":
|
||||||
| from | to | subject | body |
|
| 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 |
|
||||||
|
|
||||||
Scenario: Imports an unrelated message to sent
|
Scenario: Imports an unrelated message to sent
|
||||||
When IMAP client "1" appends the following messages to "Sent":
|
When IMAP client "1" appends the following messages to "Sent":
|
||||||
@ -60,3 +75,6 @@ Feature: IMAP create messages
|
|||||||
And IMAP client "1" sees the following messages in "Sent":
|
And IMAP client "1" sees the following messages in "Sent":
|
||||||
| from | to | subject | body |
|
| 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 |
|
||||||
|
|||||||
@ -74,13 +74,28 @@ Feature: IMAP import messages
|
|||||||
Hello
|
Hello
|
||||||
"""
|
"""
|
||||||
Then it succeeds
|
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":
|
And IMAP client "1" eventually sees the following messages in "INBOX":
|
||||||
| from | to | subject | body |
|
| from | to | subject | body |
|
||||||
| foo@example.com | bridgetest@pm.test | Hello | Hello |
|
| foo@example.com | bridgetest@pm.test | Hello | Hello |
|
||||||
And IMAP client "1" sees 0 messages in "Sent"
|
And IMAP client "1" sees 0 messages in "Sent"
|
||||||
|
|
||||||
Scenario: Import non-received message to Inbox
|
Scenario: Import non-received message to Sent
|
||||||
When IMAP client "1" appends the following message to "Inbox":
|
When IMAP client "1" appends the following message to "Sent":
|
||||||
"""
|
"""
|
||||||
From: Foo <foo@example.com>
|
From: Foo <foo@example.com>
|
||||||
To: Bridge Test <bridgetest@pm.test>
|
To: Bridge Test <bridgetest@pm.test>
|
||||||
|
|||||||
@ -144,7 +144,7 @@ func matchMessages(have, want []Message) error {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if !IsSub(ToAny(have), ToAny(want)) {
|
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
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user