GODT-1742: Implement hide All Mail

This commit is contained in:
Leander Beernaert
2022-10-20 14:38:42 +02:00
committed by James Houlahan
parent 395e7b54f6
commit a7a7d9a3d4
8 changed files with 88 additions and 5 deletions

View File

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

View File

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

View File

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