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