diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2020-05-02 02:26:54 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2020-05-02 02:26:54 +0200 |
commit | 3e219c232c0bb4a64f615c599473c959691e6319 (patch) | |
tree | 6d061451eaaf828b3cefde33d9b1bafa462268ca /internal/feed | |
parent | ff4f709486a69bc1650db73a003255e58cae0532 (diff) | |
download | feed2imap-go-3e219c232c0bb4a64f615c599473c959691e6319.tar.gz feed2imap-go-3e219c232c0bb4a64f615c599473c959691e6319.tar.bz2 feed2imap-go-3e219c232c0bb4a64f615c599473c959691e6319.zip |
Improved image support
Diffstat (limited to 'internal/feed')
-rw-r--r-- | internal/feed/mail.go | 15 |
1 files changed, 10 insertions, 5 deletions
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 { |