aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2020-05-03 02:19:40 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2020-05-03 02:19:40 +0200
commitd131d0dec6a6c7f0af3511bd908cda8a3d910237 (patch)
tree4ba7ecd8aaa33af989df7df314473fada493c3e3 /internal
parent61d4fad5d989d5fca0ee32d8e5624fb444881efa (diff)
downloadfeed2imap-go-d131d0dec6a6c7f0af3511bd908cda8a3d910237.tar.gz
feed2imap-go-d131d0dec6a6c7f0af3511bd908cda8a3d910237.tar.bz2
feed2imap-go-d131d0dec6a6c7f0af3511bd908cda8a3d910237.zip
Use UIDPLUS Imap extension
Diffstat (limited to '')
-rw-r--r--internal/imap/client.go17
-rw-r--r--internal/imap/connection.go20
2 files changed, 26 insertions, 11 deletions
diff --git a/internal/imap/client.go b/internal/imap/client.go
index 24cc3f1..731e35b 100644
--- a/internal/imap/client.go
+++ b/internal/imap/client.go
@@ -1,6 +1,7 @@
package imap
import (
+ uidplus "github.com/emersion/go-imap-uidplus"
imapClient "github.com/emersion/go-imap/client"
"github.com/Necoro/feed2imap-go/pkg/log"
@@ -37,19 +38,21 @@ func (client *Client) Disconnect() {
}
}
-func (client *Client) createConnection(c *imapClient.Client) *connection {
- if client.nextFreeIndex >= len(client.connections) {
+func (cl *Client) createConnection(c *imapClient.Client) *connection {
+ if cl.nextFreeIndex >= len(cl.connections) {
panic("Too many connections")
}
+ client := &client{c, uidplus.NewClient(c)}
+
conn := &connection{
- connConf: &client.connConf,
- mailboxes: client.mailboxes,
- c: c,
+ connConf: &cl.connConf,
+ mailboxes: cl.mailboxes,
+ c: client,
}
- client.connections[client.nextFreeIndex] = conn
- client.nextFreeIndex++
+ cl.connections[cl.nextFreeIndex] = conn
+ cl.nextFreeIndex++
return conn
}
diff --git a/internal/imap/connection.go b/internal/imap/connection.go
index 431d1dc..e8d4da2 100644
--- a/internal/imap/connection.go
+++ b/internal/imap/connection.go
@@ -6,16 +6,22 @@ import (
"time"
"github.com/emersion/go-imap"
+ uidplus "github.com/emersion/go-imap-uidplus"
imapClient "github.com/emersion/go-imap/client"
"github.com/Necoro/feed2imap-go/pkg/log"
"github.com/Necoro/feed2imap-go/pkg/util"
)
+type client struct {
+ *imapClient.Client
+ *uidplus.UidPlusClient
+}
+
type connection struct {
*connConf
mailboxes *mailboxes
- c *imapClient.Client
+ c *client
}
func (conn *connection) startTls() error {
@@ -139,8 +145,14 @@ func (conn *connection) delete(uids []uint32) error {
return fmt.Errorf("marking as deleted: %w", err)
}
- if err := conn.c.Expunge(nil); err != nil {
- return fmt.Errorf("expunging: %w", err)
+ if ok, _ := conn.c.SupportUidPlus(); ok {
+ if err := conn.c.UidExpunge(seqSet, nil); err != nil {
+ return fmt.Errorf("expunging (uid): %w", err)
+ }
+ } else {
+ if err := conn.c.Expunge(nil); err != nil {
+ return fmt.Errorf("expunging: %w", err)
+ }
}
return nil
@@ -234,7 +246,7 @@ func (conn *connection) selectFolder(folder Folder) error {
func (conn *connection) append(folder Folder, flags []string, msg string) error {
reader := strings.NewReader(msg)
- if err := conn.c.Append(folder.str, flags, time.Now(), reader); err != nil {
+ if err := conn.c.Client.Append(folder.str, flags, time.Now(), reader); err != nil {
return fmt.Errorf("uploading message to %s: %w", folder, err)
}