diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2020-05-02 21:40:02 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2020-05-02 21:40:02 +0200 |
commit | 1525392a23c86214bf7ad1b5b7d8983f7b30837a (patch) | |
tree | 1515a12a24f682131672acfe3be6c0d17ba9c19b | |
parent | 6bd8a6c2cd153bad9ca044b409e55302e10206c1 (diff) | |
download | feed2imap-go-1525392a23c86214bf7ad1b5b7d8983f7b30837a.tar.gz feed2imap-go-1525392a23c86214bf7ad1b5b7d8983f7b30837a.tar.bz2 feed2imap-go-1525392a23c86214bf7ad1b5b7d8983f7b30837a.zip |
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.
Diffstat (limited to '')
-rw-r--r-- | go.mod | 3 | ||||
-rw-r--r-- | go.sum | 3 | ||||
-rw-r--r-- | internal/feed/cache_v1.go | 4 | ||||
-rw-r--r-- | internal/feed/item.go | 11 | ||||
-rw-r--r-- | internal/feed/mail.go | 1 | ||||
-rw-r--r-- | internal/feed/parse.go | 4 |
6 files changed, 16 insertions, 10 deletions
@@ -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 ) @@ -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("<feed#%s#%s@%s>", item.feed.cached.ID(), item.itemId, config.Hostname()) + return fmt.Sprintf("<feed#%s@%s>", 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 } |