This repository has been archived by the owner on Feb 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
316 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,24 @@ | ||
package imap | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/emersion/neutron/backend" | ||
"github.com/emersion/neutron/backend/memory" | ||
"github.com/emersion/neutron/backend/util" | ||
) | ||
|
||
type Backend struct { | ||
backend.DomainsBackend | ||
backend.ContactsBackend | ||
backend.LabelsBackend | ||
backend.ConversationsBackend | ||
backend.SendBackend | ||
backend.EventsBackend | ||
|
||
*connBackend | ||
|
||
users map[string]*backend.User | ||
passwords map[string]string | ||
type Config struct { | ||
Hostname string | ||
Port int | ||
Suffix string | ||
} | ||
|
||
func (b *Backend) Set(item interface{}) error { | ||
switch val := item.(type) { | ||
case backend.SendBackend: | ||
b.SendBackend = val | ||
default: | ||
return errors.New("Unsupported backend") | ||
} | ||
return nil | ||
} | ||
|
||
func New(config *Config) backend.Backend { | ||
bkd := &Backend{ | ||
connBackend: newConnBackend(config), | ||
|
||
users: map[string]*backend.User{}, | ||
passwords: map[string]string{}, | ||
} | ||
|
||
messages := newMessagesBackend(bkd.connBackend) | ||
conversations := util.NewDummyConversationsBackend(messages) | ||
func Use(config *Config, bkd *backend.Backend) *Users { | ||
conns := newConns(config) | ||
messages := newMessages(conns) | ||
conversations := util.NewDummyConversations(messages) | ||
users := newUsers(conns) | ||
|
||
// TODO: do not use memory backends | ||
bkd.EventsBackend = memory.NewEventsBackend() | ||
bkd.DomainsBackend = memory.NewDomainsBackend() | ||
bkd.ContactsBackend = util.NewEventedContactsBackend(memory.NewContactsBackend(), bkd.EventsBackend) | ||
bkd.LabelsBackend = util.NewEventedLabelsBackend(memory.NewLabelsBackend(), bkd.EventsBackend) | ||
bkd.ConversationsBackend = util.NewEventedConversationsBackend(conversations, bkd.EventsBackend) | ||
bkd.SendBackend = util.NewNoopSendBackend() | ||
bkd.Set(conversations, users) | ||
|
||
return bkd | ||
// TODO: do not return users backend | ||
return users | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.