Skip to content

Commit

Permalink
Merge branch 'master' of github.com:skx/rss2email
Browse files Browse the repository at this point in the history
  • Loading branch information
skx committed May 4, 2022
2 parents 36666ed + 213af8e commit 85521cb
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 13 deletions.
1 change: 1 addition & 0 deletions config_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ notify | Comma-delimited list of emails to send notifications to (if set,
| replaces the emails set in the cron/daemon command).
retry | The maximum number of times to retry a failing HTTP-fetch.
sleep | Sleep the specified number of seconds, before making the request.
tag | Setup a tag for this feed, which can be accessed in the template.
template | The path to a feed-specific email template to use.
user-agent | Configure a specific User-Agent when making HTTP requests.
Expand Down
8 changes: 5 additions & 3 deletions processor/emailer/emailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,13 @@ func (e *Emailer) Sendmail(addresses []string, textstr string, htmlstr string) e
type TemplateParms struct {
Feed string
FeedTitle string
To string
From string
Text string
HTML string
Subject string
Link string
Subject string
Tag string
Text string
To string

// In case people need access to fields
// we've not wrapped/exported explicitly
Expand All @@ -176,6 +177,7 @@ func (e *Emailer) Sendmail(addresses []string, textstr string, htmlstr string) e
x.To = addr
x.RSSFeed = e.feed
x.RSSItem = e.item
x.Tag = e.item.Tag

// The real meat of the mail is the text & HTML
// parts. They need to be encoded, unconditionally.
Expand Down
15 changes: 15 additions & 0 deletions processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,16 @@ func (p *Processor) message(msg string) {
// specifically excluded by the per-feed options.
func (p *Processor) processFeed(entry configfile.Feed, recipients []string) error {

// Is there a tag set for this feed?
tag := ""

// Look at each per-feed option to determine that
for _, opt := range entry.Options {
if strings.ToLower(opt.Name)== "tag" {
tag = opt.Value
}
}

// Show what we're doing.
p.message(fmt.Sprintf("Fetching feed: %s", entry.URL))

Expand Down Expand Up @@ -262,6 +272,11 @@ func (p *Processor) processFeed(entry configfile.Feed, recipients []string) erro
// but that will go away in the future.
item := withstate.FeedItem{Item: xp}

// Set the tag for the item, if present.
if tag != "" {
item.Tag = tag
}

// Keep track of the fact that we saw this feed-item.
//
// This is used for pruning the BoltDB state file.
Expand Down
2 changes: 1 addition & 1 deletion template/template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
Content-Type: multipart/mixed; boundary=21ee3da964c7bf70def62adb9ee1a061747003c026e363e47231258c48f1
From: {{.From}}
To: {{.To}}
Subject: [rss2email] {{.Subject}}
Subject: [rss2email] {{if .Tag}}{{.Tag}} {{end}}{{.Subject}}
X-RSS-Link: {{.Link}}
X-RSS-Feed: {{.Feed}}
X-RSS-GUID: {{.RSSItem.GUID}}
Expand Down
7 changes: 2 additions & 5 deletions template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ import "testing"

func TestTemplate(t *testing.T) {

// content of our template
// content and expected length
content := EmailTemplate()
length := 2484

// expected template length
length := 2457

// check the content is as big as it should be.
if len(content) != length {
t.Fatalf("unexpected template size %d != %d", length, len(content))
}
Expand Down
4 changes: 4 additions & 0 deletions withstate/feeditem.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ type FeedItem struct {

// Wrapped structure
*gofeed.Item

// Tag is a field that can be set for this feed item,
// inside our configuration file.
Tag string
}

// IsNew reports whether this particular feed-item is new.
Expand Down
8 changes: 4 additions & 4 deletions withstate/feeditem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ func TestCollision(t *testing.T) {
// So we want to have two feed items with the same
// GUID. They should map to the same file, so we
// can confirm they would be treated as identical
a := &FeedItem{&gofeed.Item{}}
b := &FeedItem{&gofeed.Item{}}
a := &FeedItem{&gofeed.Item{}, ""}
b := &FeedItem{&gofeed.Item{}, ""}

a.GUID = "steve"
b.GUID = "steve"
Expand Down Expand Up @@ -43,8 +43,8 @@ func TestCollisionMissingHome(t *testing.T) {
// So we want to have two feed items with the same
// GUID. They should map to the same file, so we
// can confirm they would be treated as identical
a := &FeedItem{&gofeed.Item{}}
b := &FeedItem{&gofeed.Item{}}
a := &FeedItem{&gofeed.Item{}, ""}
b := &FeedItem{&gofeed.Item{}, ""}

a.GUID = "steve"
b.GUID = "steve"
Expand Down

0 comments on commit 85521cb

Please sign in to comment.