53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/inline_attachment.rb', line 53
def path_to_image_with_inline_attachment(source)
@part_container ||= @controller
if @part_container.is_a?(ActionMailer::Base) or @part_container.is_a?(ActionMailer::Part)
if source =~ %r{file://}
file_path = source.sub(%r{file://}, '')
else
file_path = "#{RAILS_ROOT}/public#{path_to_image_without_inline_attachment(source).split('?').first}"
end
if File.exists?(file_path)
basename = File.basename(file_path)
ext = basename.split('.').last
cid = Time.now.to_f.to_s + "#{basename}@inline_attachment"
File.open(file_path, 'rb') do |file|
@part_container.inline_attachment(:content_type => "image/#{ext}",
:body => file.read,
:filename => basename,
:cid => "<#{cid}>",
:disposition => "inline")
end
return "cid:#{cid}"
end
end
return path_to_image_without_inline_attachment(source)
end
|