aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2020-05-02 18:51:37 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2020-05-02 18:51:37 +0200
commit477241a2c2356c61b7317246040aee50d2a7a81d (patch)
tree56a040ab9c938d71455366ade90d1c5443440d32 /internal
parentc05a640571b57bd63e67867f9d8122c4e2d1d183 (diff)
downloadfeed2imap-go-477241a2c2356c61b7317246040aee50d2a7a81d.tar.gz
feed2imap-go-477241a2c2356c61b7317246040aee50d2a7a81d.tar.bz2
feed2imap-go-477241a2c2356c61b7317246040aee50d2a7a81d.zip
WIP: Message-Ids
Diffstat (limited to 'internal')
-rw-r--r--internal/feed/cache.go1
-rw-r--r--internal/feed/cache_v1.go19
-rw-r--r--internal/feed/feed.go1
-rw-r--r--internal/feed/mail.go9
-rw-r--r--internal/feed/parse.go3
5 files changed, 30 insertions, 3 deletions
diff --git a/internal/feed/cache.go b/internal/feed/cache.go
index f1dfb77..731eab1 100644
--- a/internal/feed/cache.go
+++ b/internal/feed/cache.go
@@ -27,6 +27,7 @@ type CachedFeed interface {
Checked(withFailure bool)
Failures() int
Last() time.Time
+ ID() string
filterItems(items []feeditem, ignoreHash bool, alwaysNew bool) []feeditem
Commit()
}
diff --git a/internal/feed/cache_v1.go b/internal/feed/cache_v1.go
index bbb8f13..b2813ce 100644
--- a/internal/feed/cache_v1.go
+++ b/internal/feed/cache_v1.go
@@ -3,8 +3,11 @@ package feed
import (
"crypto/sha256"
"fmt"
+ "strconv"
"time"
+ "github.com/lithammer/shortuuid"
+
"github.com/Necoro/feed2imap-go/pkg/log"
"github.com/Necoro/feed2imap-go/pkg/util"
)
@@ -16,6 +19,10 @@ const (
type feedId uint64
+func (id feedId) String() string {
+ return strconv.FormatUint(uint64(id), 16)
+}
+
type v1Cache struct {
Ids map[feedDescriptor]feedId
NextId uint64
@@ -23,6 +30,7 @@ type v1Cache struct {
}
type cachedFeed struct {
+ id feedId // not saved, has to be set on loading
LastCheck time.Time
currentCheck time.Time
NumFailures int // can't be named `Failures` b/c it'll collide with the interface
@@ -40,6 +48,7 @@ type cachedItem struct {
UpdatedDate time.Time
UpdatedCache time.Time
Hash itemHash
+ ID string
}
func (item cachedItem) String() string {
@@ -75,6 +84,10 @@ func (cf *cachedFeed) Last() time.Time {
return cf.LastCheck
}
+func (cf *cachedFeed) ID() string {
+ return cf.id.String()
+}
+
func (cache *v1Cache) Version() Version {
return v1Version
}
@@ -98,6 +111,7 @@ func (cache *v1Cache) getItem(id feedId) CachedFeed {
feed = &cachedFeed{}
cache.Feeds[id] = feed
}
+ feed.id = id
return feed
}
@@ -142,6 +156,8 @@ func (cache *v1Cache) findItem(feed *Feed) CachedFeed {
func newCachedItem(item feeditem) cachedItem {
var ci cachedItem
+ ci.ID = shortuuid.New()
+
ci.Title = item.Item.Title
ci.Link = item.Item.Link
if item.Item.PublishedParsed != nil {
@@ -192,6 +208,7 @@ func (cf *cachedFeed) filterItems(items []feeditem, ignoreHash, alwaysNew bool)
}
filtered = append(filtered, *item)
cacheadd = append(cacheadd, ci)
+ item.itemId = ci.ID
}
CACHE_ITEMS:
@@ -211,6 +228,7 @@ CACHE_ITEMS:
log.Debugf("Guid matches with: %s", oldItem)
if !oldItem.similarTo(&ci, ignoreHash) {
item.addReason("guid (upd)")
+ ci.ID = oldItem.ID
app(item, ci, &idx)
} else {
log.Debugf("Similar, ignoring")
@@ -240,6 +258,7 @@ CACHE_ITEMS:
}
log.Debugf("Link matches, updating: %s", oldItem)
item.addReason("link (upd)")
+ ci.ID = oldItem.ID
app(item, ci, &idx)
continue CACHE_ITEMS
diff --git a/internal/feed/feed.go b/internal/feed/feed.go
index 1a6ef97..9ed44df 100644
--- a/internal/feed/feed.go
+++ b/internal/feed/feed.go
@@ -35,6 +35,7 @@ type feeditem struct {
updateOnly bool
reasons []string
images []feedImage
+ itemId string
}
// Creator returns the name of the creating author.
diff --git a/internal/feed/mail.go b/internal/feed/mail.go
index 4b0e38b..ebf032a 100644
--- a/internal/feed/mail.go
+++ b/internal/feed/mail.go
@@ -49,8 +49,9 @@ func buildHeader(feed *Feed, item feeditem, cfg *config.Config) message.Header {
h.SetContentType("multipart/alternative", nil)
h.SetAddressList("From", fromAdress(feed, item, cfg))
h.SetAddressList("To", address(feed.Name, cfg.DefaultEmail))
- h.Add("X-Feed2Imap-Version", config.Version())
- h.Add("X-Feed2Imap-Reason", strings.Join(item.reasons, ","))
+ h.Set("X-Feed2Imap-Version", config.Version())
+ h.Set("X-Feed2Imap-Reason", strings.Join(item.reasons, ","))
+ h.Set("Message-Id", feed.messageId(item))
{ // date
date := item.Item.PublishedParsed
@@ -227,6 +228,10 @@ func getBody(content, description string, bodyCfg config.Body) string {
}
}
+func (feed *Feed) messageId(item feeditem) string {
+ return fmt.Sprintf("<feed#%s#%s@%s>", feed.cached.ID(), item.itemId, config.Hostname())
+}
+
func (feed *Feed) buildBody(item *feeditem) {
body := getBody(item.Item.Content, item.Item.Description, feed.Body)
diff --git a/internal/feed/parse.go b/internal/feed/parse.go
index 1ce6cda..435c0ed 100644
--- a/internal/feed/parse.go
+++ b/internal/feed/parse.go
@@ -7,6 +7,7 @@ import (
"net/http"
"time"
+ "github.com/lithammer/shortuuid"
"github.com/mmcdole/gofeed"
"github.com/Necoro/feed2imap-go/pkg/log"
@@ -55,7 +56,7 @@ func parseFeed(feed *Feed) error {
feed.feed = parsedFeed
feed.items = make([]feeditem, len(parsedFeed.Items))
for idx, item := range parsedFeed.Items {
- feed.items[idx] = feeditem{Feed: parsedFeed, Item: item}
+ feed.items[idx] = feeditem{Feed: parsedFeed, Item: item, itemId: shortuuid.New()}
}
return nil
}