mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-10 12:46:46 +00:00
GODT-1742: Implement hide All Mail
This commit is contained in:
committed by
James Houlahan
parent
395e7b54f6
commit
a7a7d9a3d4
@ -170,7 +170,11 @@ func (bridge *Bridge) GetShowAllMail() bool {
|
||||
}
|
||||
|
||||
func (bridge *Bridge) SetShowAllMail(show bool) error {
|
||||
panic("TODO")
|
||||
bridge.users.IterValues(func(user *user.User) {
|
||||
user.SetShowAllMail(show)
|
||||
})
|
||||
|
||||
return bridge.vault.SetShowAllMail(show)
|
||||
}
|
||||
|
||||
func (bridge *Bridge) GetAutostart() bool {
|
||||
|
||||
@ -389,7 +389,7 @@ func (bridge *Bridge) addUserWithVault(
|
||||
apiUser liteapi.User,
|
||||
vaultUser *vault.User,
|
||||
) error {
|
||||
user, err := user.New(ctx, vaultUser, client, apiUser)
|
||||
user, err := user.New(ctx, vaultUser, client, apiUser, bridge.GetShowAllMail())
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create user: %w", err)
|
||||
}
|
||||
|
||||
@ -336,6 +336,10 @@ func (conn *imapConnector) Close(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (conn *imapConnector) IsMailboxVisible(_ context.Context, _ imap.MailboxID) bool {
|
||||
func (conn *imapConnector) IsMailboxVisible(_ context.Context, id imap.MailboxID) bool {
|
||||
if !conn.GetShowAllMail() && id == liteapi.AllMailLabel {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@ -22,6 +22,7 @@ import (
|
||||
"crypto/subtle"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/ProtonMail/gluon/connector"
|
||||
@ -54,9 +55,11 @@ type User struct {
|
||||
|
||||
syncStopCh chan struct{}
|
||||
syncLock try.Group
|
||||
|
||||
showAllMail int32
|
||||
}
|
||||
|
||||
func New(ctx context.Context, encVault *vault.User, client *liteapi.Client, apiUser liteapi.User) (*User, error) { //nolint:funlen
|
||||
func New(ctx context.Context, encVault *vault.User, client *liteapi.Client, apiUser liteapi.User, showAllMail bool) (*User, error) { //nolint:funlen
|
||||
// Get the user's API addresses.
|
||||
apiAddrs, err := client.GetAddresses(ctx)
|
||||
if err != nil {
|
||||
@ -111,6 +114,8 @@ func New(ctx context.Context, encVault *vault.User, client *liteapi.Client, apiU
|
||||
syncStopCh: make(chan struct{}),
|
||||
}
|
||||
|
||||
user.SetShowAllMail(showAllMail)
|
||||
|
||||
// When we receive an auth object, we update it in the vault.
|
||||
// This will be used to authorize the user on the next run.
|
||||
user.client.AddAuthHandler(func(auth liteapi.Auth) {
|
||||
@ -390,6 +395,20 @@ func (user *User) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (user *User) SetShowAllMail(show bool) {
|
||||
var value int32
|
||||
if show {
|
||||
value = 1
|
||||
} else {
|
||||
value = 0
|
||||
}
|
||||
atomic.StoreInt32(&user.showAllMail, value)
|
||||
}
|
||||
|
||||
func (user *User) GetShowAllMail() bool {
|
||||
return atomic.LoadInt32(&user.showAllMail) == 1
|
||||
}
|
||||
|
||||
func (user *User) checkAuth(email string, password []byte) (string, error) {
|
||||
dec, err := hexDecode(password)
|
||||
if err != nil {
|
||||
|
||||
@ -142,7 +142,7 @@ func withUser(t *testing.T, ctx context.Context, _ *server.Server, m *liteapi.Ma
|
||||
vaultUser, err := vault.AddUser(apiUser.ID, username, apiAuth.UID, apiAuth.RefreshToken, saltedKeyPass)
|
||||
require.NoError(t, err)
|
||||
|
||||
user, err := user.New(ctx, vaultUser, client, apiUser)
|
||||
user, err := user.New(ctx, vaultUser, client, apiUser, true)
|
||||
require.NoError(t, err)
|
||||
defer func() { require.NoError(t, user.Close()) }()
|
||||
|
||||
|
||||
@ -122,6 +122,8 @@ func TestFeatures(testingT *testing.T) {
|
||||
ctx.Step(`^bridge sends an update installed event for version "([^"]*)"$`, s.bridgeSendsAnUpdateInstalledEventForVersion)
|
||||
ctx.Step(`^bridge sends an update not available event$`, s.bridgeSendsAnUpdateNotAvailableEvent)
|
||||
ctx.Step(`^bridge sends a forced update event$`, s.bridgeSendsAForcedUpdateEvent)
|
||||
ctx.Step(`^bridge hides all mail$`, s.bridgeHidesAllMail)
|
||||
ctx.Step(`^bridge shows all mail$`, s.bridgeShowsAllMail)
|
||||
|
||||
// ==== USER ====
|
||||
ctx.Step(`^the user logs in with username "([^"]*)" and password "([^"]*)"$`, s.userLogsInWithUsernameAndPassword)
|
||||
|
||||
@ -267,6 +267,14 @@ func (s *scenario) bridgeSendsAForcedUpdateEvent() error {
|
||||
})
|
||||
}
|
||||
|
||||
func (s *scenario) bridgeHidesAllMail() error {
|
||||
return s.t.bridge.SetShowAllMail(false)
|
||||
}
|
||||
|
||||
func (s *scenario) bridgeShowsAllMail() error {
|
||||
return s.t.bridge.SetShowAllMail(true)
|
||||
}
|
||||
|
||||
func try[T any](inCh *queue.QueuedChannel[T], wait time.Duration, fn func(T) error) error {
|
||||
select {
|
||||
case event := <-inCh.GetChannel():
|
||||
|
||||
46
tests/features/imap/mailbox/hide_all_mail.feature
Normal file
46
tests/features/imap/mailbox/hide_all_mail.feature
Normal file
@ -0,0 +1,46 @@
|
||||
Feature: IMAP Hide All Mail
|
||||
Background:
|
||||
Given there exists an account with username "user@pm.me" and password "password"
|
||||
And bridge starts
|
||||
And the user logs in with username "user@pm.me" and password "password"
|
||||
And user "user@pm.me" finishes syncing
|
||||
And user "user@pm.me" connects and authenticates IMAP client "1"
|
||||
|
||||
Scenario: Hide All Mail Mailbox
|
||||
Given IMAP client "1" sees the following mailbox info:
|
||||
| name | total | unread |
|
||||
| INBOX | 0 | 0 |
|
||||
| Drafts | 0 | 0 |
|
||||
| Sent | 0 | 0 |
|
||||
| Starred | 0 | 0 |
|
||||
| Archive | 0 | 0 |
|
||||
| Spam | 0 | 0 |
|
||||
| Trash | 0 | 0 |
|
||||
| All Mail | 0 | 0 |
|
||||
| Folders | 0 | 0 |
|
||||
| Labels | 0 | 0 |
|
||||
When bridge hides all mail
|
||||
Then IMAP client "1" sees the following mailbox info:
|
||||
| name | total | unread |
|
||||
| INBOX | 0 | 0 |
|
||||
| Drafts | 0 | 0 |
|
||||
| Sent | 0 | 0 |
|
||||
| Starred | 0 | 0 |
|
||||
| Archive | 0 | 0 |
|
||||
| Spam | 0 | 0 |
|
||||
| Trash | 0 | 0 |
|
||||
| Folders | 0 | 0 |
|
||||
| Labels | 0 | 0 |
|
||||
When bridge shows all mail
|
||||
Then IMAP client "1" sees the following mailbox info:
|
||||
| name | total | unread |
|
||||
| INBOX | 0 | 0 |
|
||||
| Drafts | 0 | 0 |
|
||||
| Sent | 0 | 0 |
|
||||
| Starred | 0 | 0 |
|
||||
| Archive | 0 | 0 |
|
||||
| Spam | 0 | 0 |
|
||||
| Trash | 0 | 0 |
|
||||
| All Mail | 0 | 0 |
|
||||
| Folders | 0 | 0 |
|
||||
| Labels | 0 | 0 |
|
||||
Reference in New Issue
Block a user