aboutsummaryrefslogtreecommitdiff
path: root/internal/imap/client.go
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2020-04-22 23:40:53 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2020-04-22 23:40:53 +0200
commit9280ecb7e0b0039d6c1f4800373eb76452145078 (patch)
treee3dd11e9953f949709505731a16e8246afe536aa /internal/imap/client.go
parent15b6c155a8476cf86e8bd745e239e55e77317909 (diff)
downloadfeed2imap-go-9280ecb7e0b0039d6c1f4800373eb76452145078.tar.gz
feed2imap-go-9280ecb7e0b0039d6c1f4800373eb76452145078.tar.bz2
feed2imap-go-9280ecb7e0b0039d6c1f4800373eb76452145078.zip
Concurrent feed processing; central imap handler
Diffstat (limited to 'internal/imap/client.go')
-rw-r--r--internal/imap/client.go29
1 files changed, 26 insertions, 3 deletions
diff --git a/internal/imap/client.go b/internal/imap/client.go
index 3f004e2..da06f54 100644
--- a/internal/imap/client.go
+++ b/internal/imap/client.go
@@ -17,6 +17,7 @@ type Client struct {
mailboxes mailboxes
delimiter string
toplevel Folder
+ commander *commander
}
type Folder struct {
@@ -50,6 +51,8 @@ func (mbs mailboxes) add(elem *imap.MailboxInfo) {
func (client *Client) Disconnect() {
if client != nil {
+ client.stopCommander()
+
connected := (client.c.State() & imap.ConnectedState) != 0
_ = client.c.Logout()
@@ -119,7 +122,7 @@ func (client *Client) fetchDelimiter() error {
return nil
}
-func (client *Client) EnsureFolder(folder Folder) error {
+func (client *Client) ensureFolder(folder Folder) error {
if client.mailboxes.contains(folder) {
return nil
}
@@ -146,6 +149,26 @@ func (client *Client) EnsureFolder(folder Folder) error {
}
}
-func (client *Client) PutMessage(folder Folder, message string, date time.Time) error {
- return client.c.Append(folder.String(), nil, date, strings.NewReader(message))
+func (client *Client) EnsureFolder(folder Folder, errorHandler ErrorHandler) {
+ client.commander.execute(ensureCommando{folder}, errorHandler)
+}
+
+func (client *Client) putMessages(folder Folder, messages []string) error {
+ if len(messages) == 0 {
+ return nil
+ }
+
+ now := time.Now()
+ for _, msg := range messages {
+ reader := strings.NewReader(msg)
+ if err := client.c.Append(folder.str, nil, now, reader); err != nil {
+ return fmt.Errorf("uploading message to %s: %w", folder, err)
+ }
+ }
+
+ return nil
+}
+
+func (client *Client) PutMessages(folder Folder, messages []string, errorHandler ErrorHandler) {
+ client.commander.execute(addCommando{folder, messages}, errorHandler)
}