aboutsummaryrefslogtreecommitdiff
path: root/internal/feed
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2021-10-29 01:31:10 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2021-10-29 01:31:10 +0200
commitf17f63bb944d886b552facf4b28a557b8e4a64d5 (patch)
tree9d85015ae0c5aa069c815f3a522662ade5be9a78 /internal/feed
parentce1e4c8465badcb49ea1b4fe8afd987587226614 (diff)
downloadfeed2imap-go-f17f63bb944d886b552facf4b28a557b8e4a64d5.tar.gz
feed2imap-go-f17f63bb944d886b552facf4b28a557b8e4a64d5.tar.bz2
feed2imap-go-f17f63bb944d886b552facf4b28a557b8e4a64d5.zip
#64: Set filename for included images
Diffstat (limited to 'internal/feed')
-rw-r--r--internal/feed/item.go5
-rw-r--r--internal/feed/mail.go20
2 files changed, 20 insertions, 5 deletions
diff --git a/internal/feed/item.go b/internal/feed/item.go
index f7dd506..b45f5c5 100644
--- a/internal/feed/item.go
+++ b/internal/feed/item.go
@@ -17,6 +17,7 @@ import (
type feedImage struct {
image []byte
mime string
+ name string
}
type Item struct {
@@ -69,8 +70,8 @@ func (item *Item) AddReason(reason string) {
}
}
-func (item *Item) addImage(img []byte, mime string) int {
- i := feedImage{img, mime}
+func (item *Item) addImage(img []byte, mime string, name string) int {
+ i := feedImage{img, mime, name}
item.images = append(item.images, i)
return len(item.images)
}
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)
}
}
>Splitted windows.pyRené 'Necoro' Neumann10-424/+549 2008-03-12Moved get_dependencies to top package classRené 'Necoro' Neumann4-50/+85 2008-03-11improved performance by caching the use_expand queriesRené 'Necoro' Neumann1-5/+14 2008-03-11use catapult varsRené 'Necoro' Neumann2-4/+6 2008-03-11Updated catapult stuffRené 'Necoro' Neumann5-56/+108 2008-03-10Generate correct KeyNotFoundExceptionRené 'Necoro' Neumann1-2/+2 2008-03-09Small changesRené 'Necoro' Neumann3-1/+4 2008-03-07Better session handlingRené 'Necoro' Neumann1-5/+54 2008-03-07Small changesRené 'Necoro' Neumann1-1/+4 2008-03-07Updated shm module to 1.2René 'Necoro' Neumann1-8/+21 2008-03-07Update TODORené 'Necoro' Neumann1-3/+1 2008-03-07hmm ... yesRené 'Necoro' Neumann1-1/+1 2008-03-06Used better exceptions for configuration parserRené 'Necoro' Neumann1-26/+114 2008-03-06Update translationRené 'Necoro' Neumann2-349/+393 2008-03-06Update createpot.shRené 'Necoro' Neumann1-3/+2 2008-03-06Use 'nofork' instead of 'nolistener'René 'Necoro' Neumann1-3/+3 2008-03-05Install glade files into template dir and not data dirRené 'Necoro' Neumann2-2/+1 2008-03-05Added dependency listRené 'Necoro' Neumann3-117/+237