Created
February 12, 2015 19:49
-
-
Save softcraft-development/2ed70a2a4d6e2c829fac to your computer and use it in GitHub Desktop.
Inline Mail Part URLs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module InlineMailPartUrls | |
def url | |
# I'm toggling this behaviour based on an environment variable. | |
# As far as I can see, there is no (better) way to decide whether or not | |
# the url is being called from a Rails Mailer Preview vs the actual Mailer call. | |
if ENV["INLINE_MAIL_PART_URLS"] == "true" | |
# Encode the part body in a data URI | |
# http://en.wikipedia.org/wiki/Data_URI_scheme | |
"data:#{mime_type};base64,#{Base64.encode64(body.decoded)}" | |
else | |
# If turned off, just defer to the superclass, which generates a | |
# "cid:" URI. | |
super | |
end | |
end | |
end | |
class Mail::Part | |
# use InlineMailPartUrls for all attachments | |
prepend InlineMailPartUrls | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment