aboutsummaryrefslogtreecommitdiff
path: root/internal/feed
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--internal/feed/mail.go40
1 files changed, 27 insertions, 13 deletions
diff --git a/internal/feed/mail.go b/internal/feed/mail.go
index 2b0cdf7..5e308e2 100644
--- a/internal/feed/mail.go
+++ b/internal/feed/mail.go
@@ -7,6 +7,7 @@ import (
"io"
"io/ioutil"
"mime"
+ "net/url"
"path"
"strings"
"time"
@@ -191,22 +192,16 @@ func (feed *Feed) Messages() (msg.Messages, error) {
return mails, nil
}
-func getImage(src string) ([]byte, string) {
- if strings.HasPrefix(src, "//") {
- src = "https:" + src
- }
-
+func getImage(src string) ([]byte, string, error) {
resp, err := stdHTTPClient.Get(src)
if err != nil {
- log.Errorf("Error fetching from '%s': %s", src, err)
- return nil, ""
+ return nil, "", fmt.Errorf("fetching from '%s': %w", src, err)
}
defer resp.Body.Close()
img, err := ioutil.ReadAll(resp.Body)
if err != nil {
- log.Errorf("Error reading body from '%s': %s", src, err)
- return nil, ""
+ return nil, "", fmt.Errorf("reading from '%s': %w", src, err)
}
var mimeStr string
@@ -216,7 +211,7 @@ func getImage(src string) ([]byte, string) {
} else {
mimeStr = mime.TypeByExtension(ext)
}
- return img, mimeStr
+ return img, mimeStr, nil
}
func cidNr(idx int) string {
@@ -243,6 +238,11 @@ func getBody(content, description string, bodyCfg config.Body) string {
func (item *item) buildBody() {
feed := item.feed
+ feedUrl, err := url.Parse(feed.Url)
+ if err != nil {
+ panic(fmt.Sprintf("URL '%s' of feed '%s' is not a valid URL. How have we ended up here?", feed.Url, feed.Name))
+ }
+
body := getBody(item.Item.Content, item.Item.Description, feed.Body)
if !feed.InclImages {
@@ -252,7 +252,7 @@ func (item *item) buildBody() {
doc, err := goquery.NewDocumentFromReader(strings.NewReader(body))
if err != nil {
- log.Debugf("Feed %s: Error while parsing html content: %s", feed.Name, err)
+ log.Errorf("Feed %s: Item %s: Error while parsing html content: %s", feed.Name, item.Item.Link, err)
if body != "" {
item.Body = "<br />" + body
}
@@ -269,7 +269,20 @@ func (item *item) buildBody() {
return
}
- img, mime := getImage(src)
+ srcUrl,err := url.Parse(src)
+ if err != nil {
+ log.Errorf("Feed %s: Item %s: Error parsing URL '%s' embedded in item: %s",
+ feed.Name, item.Item.Link, src, err)
+ return
+ }
+ imgUrl := feedUrl.ResolveReference(srcUrl)
+
+ img, mime, err := getImage(imgUrl.String())
+ if err != nil {
+ log.Errorf("Feed %s: Item %s: Error fetching image: %s",
+ feed.Name, item.Item.Link, err)
+ return
+ }
if img == nil {
return
}
@@ -289,7 +302,8 @@ func (item *item) buildBody() {
html, err := doc.Find("body").Html()
if err != nil {
item.clearImages()
- log.Errorf("Error during rendering HTML, skipping.")
+ log.Errorf("Feed %s: Item %s: Error during rendering HTML: %s",
+ feed.Name, item.Item.Link, err)
} else {
body = html
}
hm/shmmodule.c?h=v0.14.1&id=31b1482b90f4d9c03c549538756978fe6f2da6a3&follow=1'> r605@Devoty: necoro | 2008-01-14 11:43:34 +0100Necoro2-26/+129 2008-01-14 r603@Devoty: necoro | 2008-01-14 11:30:26 +0100Necoro4-26/+38 2008-01-11 r598@Devoty: necoro | 2008-01-10 16:36:29 +0100Necoro4-10/+50 2008-01-11 r597@Devoty: necoro | 2008-01-10 14:12:35 +0100Necoro1-3/+3 2008-01-10 r595@Devoty: necoro | 2008-01-10 04:04:15 +0100Necoro1-52/+3 2008-01-09 r586@Devoty: necoro | 2008-01-09 14:54:18 +0100Necoro1-1/+1 2007-12-06 r577@Devoty: necoro | 2007-12-06 20:37:36 +0100Necoro1-1/+1 2007-12-06 r572@Devoty: necoro | 2007-11-28 08:48:15 +0100Necoro1-0/+1 2007-11-27 r570@Devoty: necoro | 2007-11-27 02:08:21 +0100Necoro3-84/+108