diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2021-10-29 01:31:10 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2021-10-29 01:31:10 +0200 |
commit | f17f63bb944d886b552facf4b28a557b8e4a64d5 (patch) | |
tree | 9d85015ae0c5aa069c815f3a522662ade5be9a78 /internal/feed/mail.go | |
parent | ce1e4c8465badcb49ea1b4fe8afd987587226614 (diff) | |
download | feed2imap-go-f17f63bb944d886b552facf4b28a557b8e4a64d5.tar.gz feed2imap-go-f17f63bb944d886b552facf4b28a557b8e4a64d5.tar.bz2 feed2imap-go-f17f63bb944d886b552facf4b28a557b8e4a64d5.zip |
#64: Set filename for included images
Diffstat (limited to '')
-rw-r--r-- | internal/feed/mail.go | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/internal/feed/mail.go b/internal/feed/mail.go index b6cd231..f5863a6 100644 --- a/internal/feed/mail.go +++ b/internal/feed/mail.go @@ -123,10 +123,19 @@ func (item *Item) writeHtmlPart(w *message.Writer) error { return item.writeContentPart(w, "html", template.Html) } +func (img *feedImage) buildNameMap(key string) map[string]string { + if img.name == "" { + return nil + } + return map[string]string{key: img.name} +} + func (img *feedImage) writeImagePart(w *message.Writer, cid string) error { var ih message.Header - ih.SetContentType(img.mime, nil) - ih.SetContentDisposition("inline", nil) + // set filename for both Type and Disposition + // according to standard, it belongs to the latter -- but some clients expect the former + ih.SetContentType(img.mime, img.buildNameMap("name")) + ih.SetContentDisposition("inline", img.buildNameMap("filename")) ih.Set("Content-Transfer-Encoding", "base64") ih.SetText("Content-ID", fmt.Sprintf("<%s>", cid)) @@ -288,7 +297,12 @@ func (item *Item) downloadImage(src string) string { if feed.EmbedImages { return "data:" + mime + ";base64," + base64.StdEncoding.EncodeToString(img) } else { - idx := item.addImage(img, mime) + name := path.Base(src) + if name == "/" || name == "." || name == " " { + name = "" + } + + idx := item.addImage(img, mime, name) return "cid:" + cidNr(idx) } } |