repos / pico

pico services mono repo
git clone https://github.com/picosh/pico.git

commit
d80b355
parent
c9bd793
author
Eric Bower
date
2025-08-28 23:15:53 -0400 EDT
chore(feeds): limit message body size to 5mb

This is in an effort to prevent abuse or having insanely massive RSS
feed digests.  The actual limit is subject to change.
2 files changed,  +16, -3
M pkg/apps/feeds/cron.go
+12, -0
 1@@ -21,6 +21,7 @@ import (
 2 	"github.com/mmcdole/gofeed"
 3 	"github.com/picosh/pico/pkg/db"
 4 	"github.com/picosh/pico/pkg/shared"
 5+	"github.com/picosh/utils"
 6 )
 7 
 8 var ErrNoRecentArticles = errors.New("no recent articles")
 9@@ -68,6 +69,7 @@ type DigestFeed struct {
10 	UnsubURL     string
11 	DaysLeft     string
12 	ShowBanner   bool
13+	SizeWarning  bool
14 }
15 
16 type DigestOptions struct {
17@@ -541,6 +543,16 @@ func (f *Fetcher) FetchAll(logger *slog.Logger, urls []string, inlineContent boo
18 		return nil, err
19 	}
20 
21+	// cap body size to prevent abuse
22+	if len(html)+len(text) > 5*utils.MB {
23+		feeds.Options.InlineContent = false
24+		feeds.SizeWarning = true
25+		html, err = f.PrintHtml(feeds)
26+		if err != nil {
27+			return nil, err
28+		}
29+	}
30+
31 	if allErrors != nil {
32 		text = fmt.Sprintf("> %s\n\n%s", allErrors, text)
33 		html = fmt.Sprintf("<blockquote>%s</blockquote><br /><br/>%s", allErrors, html)
M pkg/apps/feeds/html/digest.page.tmpl
+4, -3
 1@@ -10,14 +10,15 @@ img {
 2 </style>
 3 
 4 {{if .SizeWarning}}
 5-<blockquote style="color: #ff0000; background-color: #ffe6e6; padding: 10px; border-left: 3px solid #ff0000;">
 6-    WARNING: This email is over the size limit. Inline content has been enabled to avoid email delivery issues.
 7+<blockquote>
 8+  <strong>NOTICE:</strong> This email is over the size limit (5MB). Inline content has been enabled to avoid email delivery issues.
 9+  We recommend splitting your RSS feeds into multiple digests.
10 </blockquote>
11 {{end}}
12 
13 {{if .ShowBanner}}
14 <blockquote>
15-  In order to keep this digest email active you must <a href="{{.KeepAliveURL}}">click this link</a>.
16+  <strong>NOTICE:</strong> In order to keep this digest email active you must <a href="{{.KeepAliveURL}}">click this link</a>.
17   You have {{.DaysLeft}} days left.
18 </blockquote>
19 {{end}}