forked from Silverfish/proton-bridge
Updates() needs to return imapBackend.Update instead of interface with go-imap v1
This commit is contained in:
@ -30,6 +30,7 @@ import (
|
|||||||
"github.com/ProtonMail/proton-bridge/internal/store"
|
"github.com/ProtonMail/proton-bridge/internal/store"
|
||||||
"github.com/ProtonMail/proton-bridge/pkg/listener"
|
"github.com/ProtonMail/proton-bridge/pkg/listener"
|
||||||
"github.com/ProtonMail/proton-bridge/pkg/pmapi"
|
"github.com/ProtonMail/proton-bridge/pkg/pmapi"
|
||||||
|
imapBackend "github.com/emersion/go-imap/backend"
|
||||||
"github.com/hashicorp/go-multierror"
|
"github.com/hashicorp/go-multierror"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
logrus "github.com/sirupsen/logrus"
|
logrus "github.com/sirupsen/logrus"
|
||||||
@ -59,7 +60,7 @@ type Bridge struct {
|
|||||||
// idleUpdates is a channel which the imap backend listens to and which it uses
|
// idleUpdates is a channel which the imap backend listens to and which it uses
|
||||||
// to send idle updates to the mail client (eg thunderbird).
|
// to send idle updates to the mail client (eg thunderbird).
|
||||||
// The user stores should send idle updates on this channel.
|
// The user stores should send idle updates on this channel.
|
||||||
idleUpdates chan interface{}
|
idleUpdates chan imapBackend.Update
|
||||||
|
|
||||||
lock sync.RWMutex
|
lock sync.RWMutex
|
||||||
|
|
||||||
@ -89,7 +90,7 @@ func New(
|
|||||||
clientManager: clientManager,
|
clientManager: clientManager,
|
||||||
credStorer: credStorer,
|
credStorer: credStorer,
|
||||||
storeCache: store.NewCache(config.GetIMAPCachePath()),
|
storeCache: store.NewCache(config.GetIMAPCachePath()),
|
||||||
idleUpdates: make(chan interface{}),
|
idleUpdates: make(chan imapBackend.Update),
|
||||||
lock: sync.RWMutex{},
|
lock: sync.RWMutex{},
|
||||||
stopAll: make(chan struct{}),
|
stopAll: make(chan struct{}),
|
||||||
}
|
}
|
||||||
@ -541,7 +542,7 @@ func (b *Bridge) updateUserAgent() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetIMAPUpdatesChannel sets the channel on which idle events should be sent.
|
// GetIMAPUpdatesChannel sets the channel on which idle events should be sent.
|
||||||
func (b *Bridge) GetIMAPUpdatesChannel() chan interface{} {
|
func (b *Bridge) GetIMAPUpdatesChannel() chan imapBackend.Update {
|
||||||
if b.idleUpdates == nil {
|
if b.idleUpdates == nil {
|
||||||
log.Warn("Bridge updates channel is nil")
|
log.Warn("Bridge updates channel is nil")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,6 +29,7 @@ import (
|
|||||||
"github.com/ProtonMail/proton-bridge/internal/store"
|
"github.com/ProtonMail/proton-bridge/internal/store"
|
||||||
"github.com/ProtonMail/proton-bridge/pkg/listener"
|
"github.com/ProtonMail/proton-bridge/pkg/listener"
|
||||||
"github.com/ProtonMail/proton-bridge/pkg/pmapi"
|
"github.com/ProtonMail/proton-bridge/pkg/pmapi"
|
||||||
|
imapBackend "github.com/emersion/go-imap/backend"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
@ -44,7 +45,7 @@ type User struct {
|
|||||||
clientManager ClientManager
|
clientManager ClientManager
|
||||||
credStorer CredentialsStorer
|
credStorer CredentialsStorer
|
||||||
|
|
||||||
imapUpdatesChannel chan interface{}
|
imapUpdatesChannel chan imapBackend.Update
|
||||||
|
|
||||||
store *store.Store
|
store *store.Store
|
||||||
storeCache *store.Cache
|
storeCache *store.Cache
|
||||||
@ -102,7 +103,7 @@ func (u *User) client() pmapi.Client {
|
|||||||
// have the apitoken and password), authorising the user against the api, loading the user store (creating a new one
|
// have the apitoken and password), authorising the user against the api, loading the user store (creating a new one
|
||||||
// if necessary), and setting the imap idle updates channel (used to send imap idle updates to the imap backend if
|
// if necessary), and setting the imap idle updates channel (used to send imap idle updates to the imap backend if
|
||||||
// something in the store changed).
|
// something in the store changed).
|
||||||
func (u *User) init(idleUpdates chan interface{}) (err error) {
|
func (u *User) init(idleUpdates chan imapBackend.Update) (err error) {
|
||||||
u.unlockingKeyringLock.Lock()
|
u.unlockingKeyringLock.Lock()
|
||||||
u.wasKeyringUnlocked = false
|
u.wasKeyringUnlocked = false
|
||||||
u.unlockingKeyringLock.Unlock()
|
u.unlockingKeyringLock.Unlock()
|
||||||
|
|||||||
@ -38,7 +38,7 @@ type panicHandler interface {
|
|||||||
type imapBackend struct {
|
type imapBackend struct {
|
||||||
panicHandler panicHandler
|
panicHandler panicHandler
|
||||||
bridge bridger
|
bridge bridger
|
||||||
updates chan interface{}
|
updates chan goIMAPBackend.Update
|
||||||
eventListener listener.Listener
|
eventListener listener.Listener
|
||||||
|
|
||||||
users map[string]*imapUser
|
users map[string]*imapUser
|
||||||
@ -80,7 +80,7 @@ func newIMAPBackend(
|
|||||||
return &imapBackend{
|
return &imapBackend{
|
||||||
panicHandler: panicHandler,
|
panicHandler: panicHandler,
|
||||||
bridge: bridge,
|
bridge: bridge,
|
||||||
updates: make(chan interface{}),
|
updates: make(chan goIMAPBackend.Update),
|
||||||
eventListener: eventListener,
|
eventListener: eventListener,
|
||||||
|
|
||||||
users: map[string]*imapUser{},
|
users: map[string]*imapUser{},
|
||||||
@ -180,7 +180,7 @@ func (ib *imapBackend) Login(_ *imap.ConnInfo, username, password string) (goIMA
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Updates returns a channel of updates for IMAP IDLE extension.
|
// Updates returns a channel of updates for IMAP IDLE extension.
|
||||||
func (ib *imapBackend) Updates() <-chan interface{} {
|
func (ib *imapBackend) Updates() <-chan goIMAPBackend.Update {
|
||||||
// Called from go-imap in goroutines - we need to handle panics for each function.
|
// Called from go-imap in goroutines - we need to handle panics for each function.
|
||||||
defer ib.panicHandler.HandlePanic()
|
defer ib.panicHandler.HandlePanic()
|
||||||
|
|
||||||
|
|||||||
@ -29,7 +29,7 @@ import (
|
|||||||
|
|
||||||
// SetIMAPUpdateChannel sets the channel on which imap update messages will be sent. This should be the channel
|
// SetIMAPUpdateChannel sets the channel on which imap update messages will be sent. This should be the channel
|
||||||
// on which the imap backend listens for imap updates.
|
// on which the imap backend listens for imap updates.
|
||||||
func (store *Store) SetIMAPUpdateChannel(updates chan interface{}) {
|
func (store *Store) SetIMAPUpdateChannel(updates chan imapBackend.Update) {
|
||||||
store.log.Debug("Listening for IMAP updates")
|
store.log.Debug("Listening for IMAP updates")
|
||||||
|
|
||||||
if store.imapUpdates = updates; store.imapUpdates == nil {
|
if store.imapUpdates = updates; store.imapUpdates == nil {
|
||||||
@ -107,7 +107,7 @@ func (store *Store) imapMailboxStatus(address, mailboxName string, total, unread
|
|||||||
store.imapSendUpdate(update)
|
store.imapSendUpdate(update)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (store *Store) imapSendUpdate(update interface{}) {
|
func (store *Store) imapSendUpdate(update imapBackend.Update) {
|
||||||
if store.imapUpdates == nil {
|
if store.imapUpdates == nil {
|
||||||
store.log.Trace("IMAP IDLE unavailable")
|
store.log.Trace("IMAP IDLE unavailable")
|
||||||
return
|
return
|
||||||
|
|||||||
@ -29,7 +29,7 @@ func TestCreateOrUpdateMessageIMAPUpdates(t *testing.T) {
|
|||||||
m, clear := initMocks(t)
|
m, clear := initMocks(t)
|
||||||
defer clear()
|
defer clear()
|
||||||
|
|
||||||
updates := make(chan interface{})
|
updates := make(chan imapBackend.Update)
|
||||||
|
|
||||||
m.newStoreNoEvents(true)
|
m.newStoreNoEvents(true)
|
||||||
m.store.SetIMAPUpdateChannel(updates)
|
m.store.SetIMAPUpdateChannel(updates)
|
||||||
@ -49,7 +49,7 @@ func TestCreateOrUpdateMessageIMAPUpdatesBulkUpdate(t *testing.T) {
|
|||||||
m, clear := initMocks(t)
|
m, clear := initMocks(t)
|
||||||
defer clear()
|
defer clear()
|
||||||
|
|
||||||
updates := make(chan interface{})
|
updates := make(chan imapBackend.Update)
|
||||||
|
|
||||||
m.newStoreNoEvents(true)
|
m.newStoreNoEvents(true)
|
||||||
m.store.SetIMAPUpdateChannel(updates)
|
m.store.SetIMAPUpdateChannel(updates)
|
||||||
@ -75,7 +75,7 @@ func TestDeleteMessageIMAPUpdate(t *testing.T) {
|
|||||||
insertMessage(t, m, "msg1", "Test message 1", addrID1, 0, []string{pmapi.AllMailLabel})
|
insertMessage(t, m, "msg1", "Test message 1", addrID1, 0, []string{pmapi.AllMailLabel})
|
||||||
insertMessage(t, m, "msg2", "Test message 2", addrID1, 0, []string{pmapi.AllMailLabel})
|
insertMessage(t, m, "msg2", "Test message 2", addrID1, 0, []string{pmapi.AllMailLabel})
|
||||||
|
|
||||||
updates := make(chan interface{})
|
updates := make(chan imapBackend.Update)
|
||||||
m.store.SetIMAPUpdateChannel(updates)
|
m.store.SetIMAPUpdateChannel(updates)
|
||||||
go checkIMAPUpdates(t, updates, []func(interface{}) bool{
|
go checkIMAPUpdates(t, updates, []func(interface{}) bool{
|
||||||
checkMessageDelete(addr1, "All Mail", 2),
|
checkMessageDelete(addr1, "All Mail", 2),
|
||||||
@ -87,7 +87,7 @@ func TestDeleteMessageIMAPUpdate(t *testing.T) {
|
|||||||
close(updates)
|
close(updates)
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkIMAPUpdates(t *testing.T, updates chan interface{}, checkFunctions []func(interface{}) bool) {
|
func checkIMAPUpdates(t *testing.T, updates chan imapBackend.Update, checkFunctions []func(interface{}) bool) {
|
||||||
idx := 0
|
idx := 0
|
||||||
for update := range updates {
|
for update := range updates {
|
||||||
if idx >= len(checkFunctions) {
|
if idx >= len(checkFunctions) {
|
||||||
|
|||||||
@ -26,6 +26,7 @@ import (
|
|||||||
|
|
||||||
"github.com/ProtonMail/proton-bridge/pkg/listener"
|
"github.com/ProtonMail/proton-bridge/pkg/listener"
|
||||||
"github.com/ProtonMail/proton-bridge/pkg/pmapi"
|
"github.com/ProtonMail/proton-bridge/pkg/pmapi"
|
||||||
|
imapBackend "github.com/emersion/go-imap/backend"
|
||||||
"github.com/hashicorp/go-multierror"
|
"github.com/hashicorp/go-multierror"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -101,7 +102,7 @@ type Store struct {
|
|||||||
db *bolt.DB
|
db *bolt.DB
|
||||||
lock *sync.RWMutex
|
lock *sync.RWMutex
|
||||||
addresses map[string]*Address
|
addresses map[string]*Address
|
||||||
imapUpdates chan interface{}
|
imapUpdates chan imapBackend.Update
|
||||||
|
|
||||||
isSyncRunning bool
|
isSyncRunning bool
|
||||||
addressMode addressMode
|
addressMode addressMode
|
||||||
|
|||||||
Reference in New Issue
Block a user