diff options
-rw-r--r-- | go.mod | 3 | ||||
-rw-r--r-- | go.sum | 4 | ||||
-rw-r--r-- | internal/imap/client.go | 17 | ||||
-rw-r--r-- | internal/imap/connection.go | 20 |
4 files changed, 33 insertions, 11 deletions
@@ -5,6 +5,7 @@ go 1.14 require ( github.com/PuerkitoBio/goquery v1.5.0 github.com/emersion/go-imap v1.0.4 + github.com/emersion/go-imap-uidplus v0.0.0-20190115233941-506176eeb0f6 github.com/emersion/go-message v0.11.3-0.20200422153910-8c6ac6b57e3d github.com/gabriel-vasile/mimetype v1.1.0 github.com/google/go-cmp v0.4.0 @@ -12,3 +13,5 @@ require ( github.com/mmcdole/gofeed v1.0.0-beta2.0.20200331235650-4298e4366be3 gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c ) + +replace github.com/emersion/go-imap-uidplus => github.com/Necoro/go-imap-uidplus v0.0.0-20200503000539-a17018888f1a @@ -1,3 +1,5 @@ +github.com/Necoro/go-imap-uidplus v0.0.0-20200503000539-a17018888f1a h1:YvbrP3o8uDdTqHZbLgNNYLvSeY5iuNwW9+CzsduxiYU= +github.com/Necoro/go-imap-uidplus v0.0.0-20200503000539-a17018888f1a/go.mod h1:zEkda+LAg4txW9yrQXUU7lPXGmyntWfkFUwFJ2fEBmw= github.com/PuerkitoBio/goquery v1.5.0 h1:uGvmFXOA73IKluu/F84Xd1tt/z07GYm8X49XKHP7EJk= github.com/PuerkitoBio/goquery v1.5.0/go.mod h1:qD2PgZ9lccMbQlc7eEOjaeRlFQON7xY8kdmcsrnKqMg= github.com/andybalholm/cascadia v1.0.0 h1:hOCXnnZ5A+3eVDX8pvgl4kofXv2ELss0bKcqRySc45o= @@ -8,6 +10,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/emersion/go-imap v1.0.4 h1:uiCAIHM6Z5Jwkma1zdNDWWXxSCqb+/xHBkHflD7XBro= github.com/emersion/go-imap v1.0.4/go.mod h1:yKASt+C3ZiDAiCSssxg9caIckWF/JG7ZQTO7GAmvicU= +github.com/emersion/go-imap-uidplus v0.0.0-20190115233941-506176eeb0f6 h1:iu0B9px6K5GZUaiM/zcB6ho+JYRdzNsiK4PE1Np6ZZc= +github.com/emersion/go-imap-uidplus v0.0.0-20190115233941-506176eeb0f6/go.mod h1:GfiSiw/du0221I3Cf4F0DqX3Bv5Xe580gIIATrQtnJg= github.com/emersion/go-message v0.11.1/go.mod h1:C4jnca5HOTo4bGN9YdqNQM9sITuT3Y0K6bSUw9RklvY= github.com/emersion/go-message v0.11.3-0.20200422153910-8c6ac6b57e3d h1:GJ4ATGxKc/zmU4LIgw4LiNc1W+MQii/hMM+gWRDaHLU= github.com/emersion/go-message v0.11.3-0.20200422153910-8c6ac6b57e3d/go.mod h1:C4jnca5HOTo4bGN9YdqNQM9sITuT3Y0K6bSUw9RklvY= 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) } |