Skip to content
This repository has been archived by the owner on Dec 22, 2018. It is now read-only.

Commit

Permalink
Fix inline image display. Release v0.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Groeneveld committed Jun 10, 2016
1 parent 2cad365 commit 691db77
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## Brimir unreleased (to be announced)
### Added
- Norsk translation by @viddypiddy.

### Changed

Expand All @@ -13,10 +12,17 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Removed

### Fixed
- Notification mails of new tickets now always have correct message-id headers.

### Security

## Brimir 0.7.1 (2016-06-10)
### Added
- Norsk translation by @viddypiddy.

### Fixed
- Notification mails of new tickets now always have correct message-id headers.
- Inline images are now displayed correctly again.

## Brimir 0.7.0 (2016-04-15)
### Added
- Automatic refresh of inbox when browser tab receives focus again.
Expand Down
15 changes: 8 additions & 7 deletions app/helpers/html_text_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,20 @@ def text_to_html(content)
CGI.escapeHTML(content).gsub("\n", '<br />')
end

def sanitize_html(content, attachments = [])
def sanitize_html(content, attachments = {})
result = content

attachments.each do |content_id,url|
result.gsub!(/src="cid:#{content_id}"/, "src=\"#{url}\"")
end

result = sanitize(
strip_inline_style(content),
strip_inline_style(result),
tags: %w( a b br code div em i img li ol p pre table td tfoot
thead tr span strong ul font ),
attributes: %w( src href style color )
)

attachments.each do |attachment|
result.gsub!(/src="cid:#{attachment.content_id}"/,
"src=\"#{attachment.file.url(:original)}\"")
end

result.html_safe
end

Expand Down
7 changes: 6 additions & 1 deletion app/models/concerns/email_message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ module EmailMessage
accepts_nested_attributes_for :attachments, allow_destroy: true

has_many :attached_files, -> { where(content_id: nil) }, as: :attachable, class_name: 'Attachment'
has_many :inline_files, -> { where.not(content_id: nil) }, as: :attachable, class_name: 'Attachment'

has_attached_file :raw_message,
path: Tenant.files_path

do_not_validate_attachment_file_type :raw_message
end

def inline_files
attachments.where.not(content_id: nil).map do |attachment|
[attachment.content_id, attachment.file.url(:original)]
end.to_h
end
end
6 changes: 6 additions & 0 deletions test/helpers/html_text_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,10 @@ class HtmlTextHelperTest < ActionView::TestCase
stripped = strip_inline_style(content)
assert_equal 'Hello', stripped
end

test 'should replace cid: src with actual urls' do
content = '<img src="cid:CONTENT_ID" />'
assert_match(/<img src="TEST".*>/,
sanitize_html(content, { 'CONTENT_ID' => 'TEST' }))
end
end

0 comments on commit 691db77

Please sign in to comment.