Merge commit '8b39ea4a'

create-reload-action
Lukasz Janyst 3 years ago
commit 1d443988e6
No known key found for this signature in database
GPG Key ID: 32DE641041F17A9A
  1. 3
      pkg/bridge/bridge.go
  2. 2
      pkg/config/settings/settings.go
  3. 46
      pkg/imap/backend.go
  4. 4
      pkg/imap/user.go

@ -128,7 +128,8 @@ func (b *Bridge) Run() error {
} }
bccSelf := b.settings.GetBool(settings.BCCSelf) bccSelf := b.settings.GetBool(settings.BCCSelf)
imapBackend := imap.NewIMAPBackend(b.listener, b.settings, b.Users, bccSelf) isAllMailVisible := b.settings.GetBool(settings.IsAllMailVisible)
imapBackend := imap.NewIMAPBackend(b.listener, b.settings, b.Users, bccSelf, isAllMailVisible)
smtpBackend := smtp.NewSMTPBackend(b.listener, b.Users, bccSelf) smtpBackend := smtp.NewSMTPBackend(b.listener, b.Users, bccSelf)
serverAddress := b.settings.Get(settings.ServerAddress) serverAddress := b.settings.Get(settings.ServerAddress)

@ -44,6 +44,7 @@ const (
ServerAddress = "ServerAddress" ServerAddress = "ServerAddress"
CredentialsStore = "CredentialsStore" CredentialsStore = "CredentialsStore"
BCCSelf = "BCCSelf" BCCSelf = "BCCSelf"
IsAllMailVisible = "IsAllMailVisible"
) )
type Settings struct { type Settings struct {
@ -81,6 +82,7 @@ func (s *Settings) setDefaultValues() {
s.setDefault(IMAPPortKey, DefaultIMAPPort) s.setDefault(IMAPPortKey, DefaultIMAPPort)
s.setDefault(SMTPPortKey, DefaultSMTPPort) s.setDefault(SMTPPortKey, DefaultSMTPPort)
s.setDefault(BCCSelf, "false") s.setDefault(BCCSelf, "false")
s.setDefault(IsAllMailVisible, "true")
settingsDir := "/etc/peroxide" settingsDir := "/etc/peroxide"
s.setDefault(CacheDir, "/var/cache/peroxide/cache") s.setDefault(CacheDir, "/var/cache/peroxide/cache")

@ -24,10 +24,11 @@
// When IMAP clients request message literals (or parts thereof), we sometimes need to build RFC822 message literals. // When IMAP clients request message literals (or parts thereof), we sometimes need to build RFC822 message literals.
// To do this, we pass build jobs to the message builder, which internally manages its own parallelism. // To do this, we pass build jobs to the message builder, which internally manages its own parallelism.
// Summary: // Summary:
// - each IMAP fetch request is handled in parallel, // - each IMAP fetch request is handled in parallel,
// - within each IMAP fetch request, individual items are handled by a pool of `fetchWorkers` workers, // - within each IMAP fetch request, individual items are handled by a pool of `fetchWorkers` workers,
// - within each worker, build jobs are posted to the message builder, // - within each worker, build jobs are posted to the message builder,
// - the message builder handles build jobs using its own, independent worker pool, // - the message builder handles build jobs using its own, independent worker pool,
//
// The builder will handle jobs in parallel up to its own internal limit. This prevents it from overwhelming API. // The builder will handle jobs in parallel up to its own internal limit. This prevents it from overwhelming API.
package imap package imap
@ -46,11 +47,12 @@ import (
) )
type imapBackend struct { type imapBackend struct {
usersMgr *users.Users usersMgr *users.Users
updates *imapUpdates updates *imapUpdates
eventListener listener.Listener eventListener listener.Listener
listWorkers int listWorkers int
bccSelf bool bccSelf bool
isAllMailVisible bool
users map[string]*imapUser users map[string]*imapUser
usersLocker sync.Locker usersLocker sync.Locker
@ -66,25 +68,13 @@ func NewIMAPBackend(
setting *settings.Settings, setting *settings.Settings,
users *users.Users, users *users.Users,
bccSelf bool, bccSelf bool,
isAllMailVisible bool,
) *imapBackend { //nolint[golint] ) *imapBackend { //nolint[golint]
imapWorkers := setting.GetInt(settings.IMAPWorkers) imapWorkers := setting.GetInt(settings.IMAPWorkers)
cacheDir := setting.Get(settings.CacheDir) cacheDir := setting.Get(settings.CacheDir)
backend := newIMAPBackend(cacheDir, users, eventListener, imapWorkers, bccSelf)
go backend.monitorDisconnectedUsers()
return backend backend := &imapBackend{
}
func newIMAPBackend(
cacheDir string,
users *users.Users,
eventListener listener.Listener,
listWorkers int,
bccSelf bool,
) *imapBackend {
return &imapBackend{
usersMgr: users, usersMgr: users,
updates: newIMAPUpdates(), updates: newIMAPUpdates(),
eventListener: eventListener, eventListener: eventListener,
@ -94,9 +84,15 @@ func newIMAPBackend(
imapCachePath: filepath.Join(cacheDir, "imap_backend_cache.json"), imapCachePath: filepath.Join(cacheDir, "imap_backend_cache.json"),
imapCacheLock: &sync.RWMutex{}, imapCacheLock: &sync.RWMutex{},
listWorkers: listWorkers, listWorkers: imapWorkers,
bccSelf: bccSelf,
bccSelf: bccSelf,
isAllMailVisible: isAllMailVisible,
} }
go backend.monitorDisconnectedUsers()
return backend
} }
func (ib *imapBackend) getUser(address, slot, password string) (*imapUser, error) { func (ib *imapBackend) getUser(address, slot, password string) (*imapUser, error) {

@ -121,6 +121,10 @@ func (iu *imapUser) Username() string {
func (iu *imapUser) ListMailboxes(showOnlySubcribed bool) ([]goIMAPBackend.Mailbox, error) { func (iu *imapUser) ListMailboxes(showOnlySubcribed bool) ([]goIMAPBackend.Mailbox, error) {
mailboxes := []goIMAPBackend.Mailbox{} mailboxes := []goIMAPBackend.Mailbox{}
for _, storeMailbox := range iu.storeAddress.ListMailboxes() { for _, storeMailbox := range iu.storeAddress.ListMailboxes() {
if storeMailbox.LabelID() == pmapi.AllMailLabel && !iu.backend.isAllMailVisible {
continue
}
if showOnlySubcribed && !iu.isSubscribed(storeMailbox.LabelID()) { if showOnlySubcribed && !iu.isSubscribed(storeMailbox.LabelID()) {
continue continue
} }

Loading…
Cancel
Save