Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
6d14c379
Commit
6d14c379
authored
8 years ago
by
Tom Robinson
Committed by
GitHub
8 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #3996 from metabase/fix-email-content-ids
Use unique Content-IDs to workaround confused email clients
parents
75acd228
24c3fb36
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/metabase/email/messages.clj
+15
-11
15 additions, 11 deletions
src/metabase/email/messages.clj
with
15 additions
and
11 deletions
src/metabase/email/messages.clj
+
15
−
11
View file @
6d14c379
...
...
@@ -169,17 +169,21 @@
(
.write
fos
img-bytes
))
file
))
(
defn-
hash-bytes
"Generate a hash to be used in a Content-ID"
[
^
bytes
img-bytes
]
(
Math/abs
^
Integer
(
java.util.Arrays/hashCode
img-bytes
)))
(
defn-
render-image
[
images-atom,
^
bytes
image-bytes
]
(
str
"cid:IMAGE"
(
or
(
u/first-index-satisfying
(
fn
[
^
bytes
item
]
(
java.util.Arrays/equals
item
image-bytes
))
@
images-atom
)
(
u/prog1
(
count
@
images-atom
)
(
swap!
images-atom
conj
image-bytes
)))))
(
let
[
content-id
(
str
(
hash-bytes
image-bytes
)
"@metabase"
)]
(
if-not
(
contains?
@
images-atom
content-id
)
(
swap!
images-atom
assoc
content-id
image-bytes
))
(
str
"cid:"
content-id
)))
(
defn
render-pulse-email
"Take a pulse object and list of results, returns an array of attachment objects for an email"
[
pulse
results
]
(
let
[
images
(
atom
[]
)
(
let
[
images
(
atom
{}
)
body
(
binding
[
render/*include-title*
true
render/*render-img-fn*
(
partial
render-image
images
)]
(
vec
(
cons
:div
(
for
[
result
results
]
...
...
@@ -195,8 +199,8 @@
:quotationAuthor
(
:author
data-quote
)
:logoFooter
true
})]
(
apply
vector
{
:type
"text/html; charset=utf-8"
:content
message-body
}
(
map
-indexed
(
fn
[
id
x
bytes
]
{
:type
:inline
:content-id
(
str
"IMAGE"
idx
)
:content-type
"image/png"
:content
(
write-byte-array-to-temp-file
bytes
)})
@
images
))))
(
map
(
fn
[[
content-
id
bytes
]
]
{
:type
:inline
:content-id
content-id
:content-type
"image/png"
:content
(
write-byte-array-to-temp-file
bytes
)})
(
seq
@
images
))))
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment