From 1525392a23c86214bf7ad1b5b7d8983f7b30837a Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Sat, 2 May 2020 21:40:02 +0200 Subject: Use uuid library directly and encode to base64. Also add an additional header `X-Feed2Imap-Item`, b/c the messageId contains the variable part of the hostname. --- go.mod | 3 +-- go.sum | 3 --- internal/feed/cache_v1.go | 4 +++- internal/feed/item.go | 11 +++++++++-- internal/feed/mail.go | 1 + internal/feed/parse.go | 4 ++-- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 07ca220..62ddc09 100644 --- a/go.mod +++ b/go.mod @@ -8,8 +8,7 @@ require ( 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 - github.com/google/uuid v1.1.1 // indirect - github.com/lithammer/shortuuid v3.0.0+incompatible + github.com/google/uuid v1.1.1 github.com/mmcdole/gofeed v1.0.0-beta2.0.20200331235650-4298e4366be3 gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c ) diff --git a/go.sum b/go.sum index bf51e00..cf49eca 100644 --- a/go.sum +++ b/go.sum @@ -21,9 +21,6 @@ github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/lithammer/shortuuid v1.0.0 h1:kdcbvjGVEgqeVeDIRtnANOi/F6ftbKrtbxY+cjQmK1Q= -github.com/lithammer/shortuuid v3.0.0+incompatible h1:NcD0xWW/MZYXEHa6ITy6kaXN5nwm/V115vj2YXfhS0w= -github.com/lithammer/shortuuid v3.0.0+incompatible/go.mod h1:FR74pbAuElzOUuenUHTK2Tciko1/vKuIKS9dSkDrA4w= github.com/martinlindhe/base36 v1.0.0 h1:eYsumTah144C0A8P1T/AVSUk5ZoLnhfYFM3OGQxB52A= github.com/martinlindhe/base36 v1.0.0/go.mod h1:+AtEs8xrBpCeYgSLoY/aJ6Wf37jtBuR0s35750M27+8= github.com/mmcdole/gofeed v1.0.0-beta2.0.20200331235650-4298e4366be3 h1:Wy+ed15cpwtLcJYNiO4Z0wmjZHpNj4q0RsGbsoxWSMA= diff --git a/internal/feed/cache_v1.go b/internal/feed/cache_v1.go index 9a6de50..e2562c3 100644 --- a/internal/feed/cache_v1.go +++ b/internal/feed/cache_v1.go @@ -6,6 +6,8 @@ import ( "strconv" "time" + "github.com/google/uuid" + "github.com/Necoro/feed2imap-go/pkg/log" "github.com/Necoro/feed2imap-go/pkg/util" ) @@ -46,7 +48,7 @@ type cachedItem struct { UpdatedDate time.Time UpdatedCache time.Time Hash itemHash - ID string + ID uuid.UUID } func (item cachedItem) String() string { diff --git a/internal/feed/item.go b/internal/feed/item.go index 5c67784..b8fb7f7 100644 --- a/internal/feed/item.go +++ b/internal/feed/item.go @@ -1,8 +1,10 @@ package feed import ( + "encoding/base64" "fmt" + "github.com/google/uuid" "github.com/mmcdole/gofeed" "github.com/Necoro/feed2imap-go/pkg/config" @@ -22,7 +24,7 @@ type item struct { updateOnly bool reasons []string images []feedImage - itemId string + itemId uuid.UUID } // Creator returns the name of the creating author. @@ -54,6 +56,11 @@ func (item *item) defaultEmail() string { return item.feed.Global.DefaultEmail } +func (item *item) id() string { + idStr := base64.RawURLEncoding.EncodeToString(item.itemId[:]) + return item.feed.cached.ID() + "#" + idStr +} + func (item *item) messageId() string { - return fmt.Sprintf("", item.feed.cached.ID(), item.itemId, config.Hostname()) + return fmt.Sprintf("", item.id(), config.Hostname()) } diff --git a/internal/feed/mail.go b/internal/feed/mail.go index 41a4cbd..8bb9846 100644 --- a/internal/feed/mail.go +++ b/internal/feed/mail.go @@ -55,6 +55,7 @@ func (item *item) buildHeader() message.Header { h.SetAddressList("To", item.toAddress()) h.Set("X-Feed2Imap-Version", config.Version()) h.Set("X-Feed2Imap-Reason", strings.Join(item.reasons, ",")) + h.Set("X-Feed2Imap-Item", item.id()) h.Set("Message-Id", item.messageId()) { // date diff --git a/internal/feed/parse.go b/internal/feed/parse.go index dfb447a..1ba90fd 100644 --- a/internal/feed/parse.go +++ b/internal/feed/parse.go @@ -7,7 +7,7 @@ import ( "net/http" "time" - "github.com/lithammer/shortuuid" + "github.com/google/uuid" "github.com/mmcdole/gofeed" "github.com/Necoro/feed2imap-go/pkg/log" @@ -56,7 +56,7 @@ func (feed *Feed) parse() error { feed.feed = parsedFeed feed.items = make([]item, len(parsedFeed.Items)) for idx, feedItem := range parsedFeed.Items { - feed.items[idx] = item{Feed: parsedFeed, Item: feedItem, itemId: shortuuid.New(), feed: feed} + feed.items[idx] = item{Feed: parsedFeed, Item: feedItem, itemId: uuid.New(), feed: feed} } return nil } -- cgit v1.2.3-70-g09d2