diff --git a/app/assets/javascripts/app/controllers/ticket_zoom/article_image_view.coffee b/app/assets/javascripts/app/controllers/ticket_zoom/article_image_view.coffee
new file mode 100644
index 000000000..fc4223d14
--- /dev/null
+++ b/app/assets/javascripts/app/controllers/ticket_zoom/article_image_view.coffee
@@ -0,0 +1,19 @@
+class App.TicketZoomArticleImageView extends App.ControllerModal
+ buttonClose: true
+ buttonCancel: true
+ buttonSubmit: 'Download'
+ buttonClass: 'btn--success'
+ head: ''
+ large: true
+
+ events:
+ 'submit form': 'submit'
+ 'click .js-cancel': 'cancel'
+ 'click .js-close': 'cancel'
+
+ content: ->
+ "
<%- @content %>
diff --git a/app/controllers/concerns/creates_ticket_articles.rb b/app/controllers/concerns/creates_ticket_articles.rb
index c087d12a1..5414eb7b3 100644
--- a/app/controllers/concerns/creates_ticket_articles.rb
+++ b/app/controllers/concerns/creates_ticket_articles.rb
@@ -48,22 +48,7 @@ module CreatesTicketArticles
# store dataurl images to store
attachments_inline = []
if article.body && article.content_type =~ %r{text/html}i
- article.body.gsub!( %r{(
}im ) { |_item|
- file_attributes = StaticAssets.data_url_attributes($2)
- cid = "#{ticket.id}.#{rand(999_999_999)}@#{Setting.get('fqdn')}"
- attachment = {
- data: file_attributes[:content],
- filename: cid,
- preferences: {
- 'Content-Type' => file_attributes[:mime_type],
- 'Mime-Type' => file_attributes[:mime_type],
- 'Content-ID' => cid,
- 'Content-Disposition' => 'inline',
- },
- }
- attachments_inline.push attachment
- "#{$1}cid:#{cid}\">"
- }
+ (article.body, attachments_inline) = HtmlSanitizer.replace_inline_images(article.body, ticket.id)
end
# find attachments in upload cache
diff --git a/app/models/ticket/article.rb b/app/models/ticket/article.rb
index 4b1f839b6..cac6521b3 100644
--- a/app/models/ticket/article.rb
+++ b/app/models/ticket/article.rb
@@ -270,6 +270,9 @@ returns
}
attributes['attachments'].push item
}
+ if articles['body'] && articles['content_type'] =~ %r{text/html}i
+ articles['body'] = HtmlSanitizer.dynamic_image_size(articles['body'])
+ end
Ticket::Article.insert_urls(attributes)
end
diff --git a/lib/html_sanitizer.rb b/lib/html_sanitizer.rb
index 21d38b72b..27a34d81f 100644
--- a/lib/html_sanitizer.rb
+++ b/lib/html_sanitizer.rb
@@ -352,6 +352,73 @@ cleanup html string:
false
end
+=begin
+
+reolace inline images with cid images
+
+ string = HtmlSanitizer.replace_inline_images(article.body)
+
+=end
+
+ def self.replace_inline_images(string, prefix = rand(999_999_999))
+ attachments_inline = []
+ scrubber = Loofah::Scrubber.new do |node|
+ if node.name == 'img'
+ if node['src'] && node['src'] =~ %r{^(data:image/(jpeg|png);base64,.+?)$}i
+ file_attributes = StaticAssets.data_url_attributes($1)
+ cid = "#{prefix}.#{rand(999_999_999)}@#{Setting.get('fqdn')}"
+ attachment = {
+ data: file_attributes[:content],
+ filename: cid,
+ preferences: {
+ 'Content-Type' => file_attributes[:mime_type],
+ 'Mime-Type' => file_attributes[:mime_type],
+ 'Content-ID' => cid,
+ 'Content-Disposition' => 'inline',
+ },
+ }
+ attachments_inline.push attachment
+ node['src'] = "cid:#{cid}"
+ end
+ Loofah::Scrubber::STOP
+ end
+ end
+ [Loofah.fragment(string).scrub!(scrubber).to_s, attachments_inline]
+ end
+
+=begin
+
+satinize style of img tags
+
+ string = HtmlSanitizer.dynamic_image_size(article.body)
+
+=end
+
+ def self.dynamic_image_size(string)
+ scrubber = Loofah::Scrubber.new do |node|
+ if node.name == 'img'
+ if node['src']
+ style = 'max-width:100%;'
+ if node['style']
+ pears = node['style'].downcase.gsub(/\t|\n|\r/, '').split(';')
+ pears.each { |local_pear|
+ prop = local_pear.split(':')
+ next if !prop[0]
+ key = prop[0].strip
+ if key == 'height'
+ key = 'max-height'
+ end
+ style += "#{key}:#{prop[1]};"
+ }
+ end
+ node['style'] = style
+ end
+ Loofah::Scrubber::STOP
+ end
+ end
+ Loofah.fragment(string).scrub!(scrubber).to_s
+ end
+
private_class_method :cleanup_target
private_class_method :add_link
private_class_method :url_same?
diff --git a/lib/notification_factory/mailer.rb b/lib/notification_factory/mailer.rb
index 5142f1367..a55127afe 100644
--- a/lib/notification_factory/mailer.rb
+++ b/lib/notification_factory/mailer.rb
@@ -156,6 +156,11 @@ returns
result[:subject] = data[:main_object].subject_build(result[:subject])
end
+ # prepare scaling of images
+ if result[:body]
+ result[:body] = HtmlSanitizer.dynamic_image_size(result[:body])
+ end
+
NotificationFactory::Mailer.send(
recipient: data[:user],
subject: result[:subject],
diff --git a/test/controllers/ticket_articles_controller_test.rb b/test/controllers/ticket_articles_controller_test.rb
index 449f6590b..e46de52a0 100644
--- a/test/controllers/ticket_articles_controller_test.rb
+++ b/test/controllers/ticket_articles_controller_test.rb
@@ -99,8 +99,8 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
result = JSON.parse(@response.body)
assert_equal(Hash, result.class)
assert_equal(nil, result['subject'])
- assert_no_match(/some body
should = 'lineĀ 1
you
-----&'
- assert_equal( should, html.html2text)
+ assert_equal(should, html.html2text)
html = '
'
should = '* #1
* #2'
- assert_equal( should, html.html2text)
+ assert_equal(should, html.html2text)
html = '
@@ -235,7 +235,7 @@ you
>
> Thank you for installing Zammad.
>'
- assert_equal( should, html.html2text)
+ assert_equal(should, html.html2text)
html = '
some other content
'
should = 'some other content'
- assert_equal( should, html.html2text)
+ assert_equal(should, html.html2text)
html = ' IT-Infrastruktur
@@ -337,7 +337,7 @@ div.wordsection1
'
should = 'IT-Infrastruktur'
- assert_equal( should, html.html2text)
+ assert_equal(should, html.html2text)
html = "
some head
some content
@@ -848,6 +848,18 @@ christian.schaefer@example.com'
result = 'john.smith2@example.com'
assert_equal(result, html.html2html_strict)
+ html = '
'
+ result = '
'
+ assert_equal(result, html.html2html_strict)
+
+ html = '
'
+ result = '
'
+ assert_equal(result, html.html2html_strict)
+
+ html = '
'
+ result = '
'
+ assert_equal(result, html.html2html_strict)
+
html = '
'
#result = '
http://www.example.de/
'
result = '
http://www.example.de/
'
@@ -864,6 +876,51 @@ christian.schaefer@example.com'
assert_equal(result, html.html2html_strict)
end
+ test 'inline attachment replace' do
+ html = '
'
+ (body, attachments_inline) = HtmlSanitizer.replace_inline_images(html)
+ assert_match(/
/, body)
+ assert(1, attachments_inline.count)
+
+ html = '
'
+ (body, attachments_inline) = HtmlSanitizer.replace_inline_images(html)
+ assert_match(/
/, body)
+ assert(1, attachments_inline.count)
+
+ html = '
/, body)
+ assert(1, attachments_inline.count)
+
+ html = ''
+ (body, attachments_inline) = HtmlSanitizer.replace_inline_images(html)
+ assert_match(//, body)
+ assert(0, attachments_inline.count)
+
+ html = '123
'
+ (body, attachments_inline) = HtmlSanitizer.replace_inline_images(html)
+ assert_match(/