Commit d80b355

Eric Bower  ·  2025-08-28 23:15:53 -0400 EDT
parent c9bd793
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
+12, -0
......@@ -21,6 +21,7 @@ import (
2121 "github.com/mmcdole/gofeed"
2222 "github.com/picosh/pico/pkg/db"
2323 "github.com/picosh/pico/pkg/shared"
24+ "github.com/picosh/utils"
2425 )
2526
2627 var ErrNoRecentArticles = errors.New("no recent articles")
......@@ -68,6 +69,7 @@ type DigestFeed struct {
6869 UnsubURL string
6970 DaysLeft string
7071 ShowBanner bool
72+ SizeWarning bool
7173 }
7274
7375 type DigestOptions struct {
......@@ -541,6 +543,16 @@ func (f *Fetcher) FetchAll(logger *slog.Logger, urls []string, inlineContent boo
541543 return nil, err
542544 }
543545
546+ // cap body size to prevent abuse
547+ if len(html)+len(text) > 5*utils.MB {
548+ feeds.Options.InlineContent = false
549+ feeds.SizeWarning = true
550+ html, err = f.PrintHtml(feeds)
551+ if err != nil {
552+ return nil, err
553+ }
554+ }
555+
544556 if allErrors != nil {
545557 text = fmt.Sprintf("> %s\n\n%s", allErrors, text)
546558 html = fmt.Sprintf("<blockquote>%s</blockquote><br /><br/>%s", allErrors, html)
+4, -3
......@@ -10,14 +10,15 @@ img {
1010 </style>
1111
1212 {{if .SizeWarning}}
13-<blockquote style="color: #ff0000; background-color: #ffe6e6; padding: 10px; border-left: 3px solid #ff0000;">
14- WARNING: This email is over the size limit. Inline content has been enabled to avoid email delivery issues.
13+<blockquote>
14+ <strong>NOTICE:</strong> This email is over the size limit (5MB). Inline content has been enabled to avoid email delivery issues.
15+ We recommend splitting your RSS feeds into multiple digests.
1516 </blockquote>
1617 {{end}}
1718
1819 {{if .ShowBanner}}
1920 <blockquote>
20- In order to keep this digest email active you must <a href="{{.KeepAliveURL}}">click this link</a>.
21+ <strong>NOTICE:</strong> In order to keep this digest email active you must <a href="{{.KeepAliveURL}}">click this link</a>.
2122 You have {{.DaysLeft}} days left.
2223 </blockquote>
2324 {{end}}