diff options
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | go.mod | 1 | ||||
-rw-r--r-- | go.sum | 2 | ||||
-rw-r--r-- | internal/feed/mail.go | 15 |
4 files changed, 14 insertions, 5 deletions
@@ -31,6 +31,7 @@ for details. (feature contained also in [fork of the original][nec]) * Fix `include-images` option: It now includes images as mime-parts. An additional `embed-images` option serves the images as inline base64-encoded data (the old default behavior of feed2imap). +* Improved image inclusion: Links without scheme; images without extension (using mime-detection) * Use HTML-Parser instead of regular expressions for modifying the HTML content. ### Subtle differences @@ -6,6 +6,7 @@ require ( github.com/PuerkitoBio/goquery v1.5.0 github.com/emersion/go-imap v1.0.4 github.com/emersion/go-message v0.11.3-0.20200422153910-8c6ac6b57e3d + github.com/gabriel-vasile/mimetype v1.1.0 github.com/google/go-cmp v0.4.0 github.com/mmcdole/gofeed v1.0.0-beta2.0.20200331235650-4298e4366be3 gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c @@ -15,6 +15,8 @@ github.com/emersion/go-sasl v0.0.0-20191210011802-430746ea8b9b h1:uhWtEWBHgop1rq github.com/emersion/go-sasl v0.0.0-20191210011802-430746ea8b9b/go.mod h1:G/dpzLu16WtQpBfQ/z3LYiYJn3ZhKSGWn83fyoyQe/k= github.com/emersion/go-textwrapper v0.0.0-20160606182133-d0e65e56babe h1:40SWqY0zE3qCi6ZrtTf5OUdNm5lDnGnjRSq9GgmeTrg= github.com/emersion/go-textwrapper v0.0.0-20160606182133-d0e65e56babe/go.mod h1:aqO8z8wPrjkscevZJFVE1wXJrLpC5LtJG7fqLOsPb2U= +github.com/gabriel-vasile/mimetype v1.1.0 h1:+ahX+MvQPFve4kO9Qjjxf3j49i0ACdV236kJlOCRAnU= +github.com/gabriel-vasile/mimetype v1.1.0/go.mod h1:6CDPel/o/3/s4+bp6kIbsWATq8pmgOisOPG40CJa6To= github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/martinlindhe/base36 v1.0.0 h1:eYsumTah144C0A8P1T/AVSUk5ZoLnhfYFM3OGQxB52A= diff --git a/internal/feed/mail.go b/internal/feed/mail.go index 5f543e4..297aeff 100644 --- a/internal/feed/mail.go +++ b/internal/feed/mail.go @@ -14,6 +14,7 @@ import ( "github.com/PuerkitoBio/goquery" "github.com/emersion/go-message" "github.com/emersion/go-message/mail" + "github.com/gabriel-vasile/mimetype" "github.com/Necoro/feed2imap-go/internal/feed/template" "github.com/Necoro/feed2imap-go/pkg/config" @@ -177,6 +178,10 @@ func (feed *Feed) ToMails(cfg *config.Config) ([]string, error) { } func getImage(src string) ([]byte, string) { + if strings.HasPrefix(src, "//") { + src = "https:" + src + } + resp, err := stdHTTPClient.Get(src) if err != nil { log.Errorf("Error fetching from '%s': %s", src, err) @@ -190,14 +195,14 @@ func getImage(src string) ([]byte, string) { return nil, "" } + var mimeStr string ext := path.Ext(src) if ext == "" { - log.Warnf("Cannot determine extension from '%s', skipping.", src) - return nil, "" + mimeStr = mimetype.Detect(img).String() + } else { + mimeStr = mime.TypeByExtension(ext) } - - mime := mime.TypeByExtension(ext) - return img, mime + return img, mimeStr } func cidNr(idx int) string { |