Fixes #2486 - Unable to process email on CentOS with large images but only 1px height.
This commit is contained in:
parent
6d7480ab3f
commit
43d2418377
7 changed files with 138 additions and 6 deletions
|
@ -51,11 +51,12 @@ returns
|
|||
data.delete('object')
|
||||
|
||||
data['preferences'] ||= {}
|
||||
resizable = false
|
||||
['Mime-Type', 'Content-Type', 'mime_type', 'content_type'].each do |key|
|
||||
next if data['preferences'][key].blank?
|
||||
next if !data['preferences'][key].match(%r{image/(jpeg|jpg|png)}i)
|
||||
|
||||
data['preferences']['resizable'] = true
|
||||
resizable = true
|
||||
break
|
||||
end
|
||||
|
||||
|
@ -63,14 +64,18 @@ returns
|
|||
store = Store.create!(data)
|
||||
|
||||
begin
|
||||
if store.preferences[:resizable] == true
|
||||
if resizable
|
||||
if store.content_preview(silence: true)
|
||||
store.preferences[:resizable] = true
|
||||
store.preferences[:content_preview] = true
|
||||
end
|
||||
if store.content_inline(silence: true)
|
||||
store.preferences[:resizable] = true
|
||||
store.preferences[:content_inline] = true
|
||||
end
|
||||
store.save!
|
||||
if store.preferences[:resizable]
|
||||
store.save!
|
||||
end
|
||||
end
|
||||
rescue => e
|
||||
logger.error e
|
||||
|
@ -291,7 +296,14 @@ returns
|
|||
temp_file.write(content)
|
||||
temp_file.close
|
||||
image = Rszr::Image.load(temp_file.path)
|
||||
return if image.width < width
|
||||
|
||||
# do not resize image if image is smaller or already same size
|
||||
return if image.width <= width
|
||||
|
||||
# do not resize image if new height is smaller then 7px (images
|
||||
# with small height are usally usefull to resize)
|
||||
ratio = image.width / width
|
||||
return if image.height / ratio <= 6
|
||||
|
||||
image.resize!(width, :auto)
|
||||
temp_file_resize = ::Tempfile.new.path
|
||||
|
|
|
@ -192,5 +192,20 @@ RSpec.describe Channel::EmailParser, type: :model do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when mail contains image(s)' do
|
||||
# see https://github.com/zammad/zammad/issues/2486
|
||||
context 'when image is large but not resizable' do
|
||||
let(:mail_file) { Rails.root.join('test', 'data', 'mail', 'mail079.box') }
|
||||
|
||||
it "doesn't set resizable preference" do
|
||||
_ticket, article = described_class.new.process({}, raw_mail)
|
||||
attachment = article.attachments.last
|
||||
|
||||
expect(attachment.filename).to eq('a.jpg')
|
||||
expect(attachment.preferences).not_to include('resizable' => true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
BIN
test/data/image/4000x1.jpg
Normal file
BIN
test/data/image/4000x1.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
BIN
test/data/image/8000x25.jpg
Normal file
BIN
test/data/image/8000x25.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.4 KiB |
BIN
test/data/image/8000x300.jpg
Normal file
BIN
test/data/image/8000x300.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 57 KiB |
57
test/data/mail/mail079.box
Normal file
57
test/data/mail/mail079.box
Normal file
|
@ -0,0 +1,57 @@
|
|||
Return-Path: <me@example.com>
|
||||
X-Original-To: me@example.net
|
||||
Delivered-To: martin@example.de
|
||||
Received: from mx2.example.com (mx2.example.com [127.0.0.1])
|
||||
by base.example.de (Postfix) with ESMTPS id 69D861E933
|
||||
for <me@example.net>; Wed, 20 Feb 2019 19:49:59 +0100 (CET)
|
||||
From: Martin Smith <me@example.com>
|
||||
Content-Type: multipart/alternative;
|
||||
boundary="Apple-Mail=_E3889AFD-C5DA-47A3-86E6-3E59CB07002D"
|
||||
Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\))
|
||||
Subject: image resize test
|
||||
Message-Id: <3271C0D7-9FD0-4E93-925E-87B139DB6FBF@example.com>
|
||||
Date: Wed, 20 Feb 2019 19:50:00 +0100
|
||||
To: Martin Smith <me@example.net>
|
||||
|
||||
|
||||
--Apple-Mail=_E3889AFD-C5DA-47A3-86E6-3E59CB07002D
|
||||
Content-Transfer-Encoding: 7bit
|
||||
Content-Type: text/plain;
|
||||
charset=us-ascii
|
||||
|
||||
image resize test
|
||||
|
||||
|
||||
|
||||
the end
|
||||
--Apple-Mail=_E3889AFD-C5DA-47A3-86E6-3E59CB07002D
|
||||
Content-Type: multipart/related;
|
||||
type="text/html";
|
||||
boundary="Apple-Mail=_113961F0-41B5-43D3-BF74-8B0DE1B757A4"
|
||||
|
||||
|
||||
--Apple-Mail=_113961F0-41B5-43D3-BF74-8B0DE1B757A4
|
||||
Content-Transfer-Encoding: 7bit
|
||||
Content-Type: text/html;
|
||||
charset=us-ascii
|
||||
|
||||
<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">image resize test<div class=""><br class=""></div><div class=""><img apple-inline="yes" id="C94B1FA1-618C-40E3-B731-892907FF8AB3" src="cid:5EF92182-3261-44C7-9835-E8A922AB4976@openvpn" class=""></div><div class=""><br class=""></div><div class="">the end</div></body></html>
|
||||
--Apple-Mail=_113961F0-41B5-43D3-BF74-8B0DE1B757A4
|
||||
Content-Transfer-Encoding: base64
|
||||
Content-Disposition: inline;
|
||||
filename=a.jpg
|
||||
Content-Type: image/jpeg;
|
||||
x-unix-mode=0600;
|
||||
name="a.jpg"
|
||||
Content-Id: <5EF92182-3261-44C7-9835-E8A922AB4976@openvpn>
|
||||
|
||||
/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAoHBwgHBgoICAgLCgoLDhgQDg0NDh0VFhEYIx8lJCIf
|
||||
IiEmKzcvJik0KSEiMEExNDk7Pj4+JS5ESUM8SDc9Pjv/wAALCAABAlgBAREA/8QAHwAAAQUBAQEB
|
||||
AQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1Fh
|
||||
ByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZ
|
||||
WmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXG
|
||||
x8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/9oACAEBAAA/APZKKKKKKKKKKKKKKKKK
|
||||
KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK//2Q==
|
||||
--Apple-Mail=_113961F0-41B5-43D3-BF74-8B0DE1B757A4--
|
||||
|
||||
--Apple-Mail=_E3889AFD-C5DA-47A3-86E6-3E59CB07002D--
|
|
@ -248,7 +248,7 @@ class StoreTest < ActiveSupport::TestCase
|
|||
image = Rszr::Image.load(temp_file)
|
||||
assert_equal(image.width, 200)
|
||||
|
||||
# possible (now preview or inline needed)
|
||||
# no preview or inline needed
|
||||
store = Store.add(
|
||||
object: 'SomeObject5',
|
||||
o_id: rand(1_234_567_890),
|
||||
|
@ -260,7 +260,7 @@ class StoreTest < ActiveSupport::TestCase
|
|||
},
|
||||
created_by_id: 1,
|
||||
)
|
||||
assert_equal(store.preferences[:resizable], true)
|
||||
assert_nil(store.preferences[:resizable])
|
||||
assert_nil(store.preferences[:content_inline])
|
||||
assert_nil(store.preferences[:content_preview])
|
||||
assert_raises(RuntimeError) do
|
||||
|
@ -270,5 +270,53 @@ class StoreTest < ActiveSupport::TestCase
|
|||
store.content_preview
|
||||
end
|
||||
|
||||
# no preview or inline needed
|
||||
store = Store.add(
|
||||
object: 'SomeObject6',
|
||||
o_id: rand(1_234_567_890),
|
||||
data: File.binread(Rails.root.join('test', 'data', 'image', '4000x1.jpg')),
|
||||
filename: 'test1.jpg',
|
||||
preferences: {
|
||||
content_type: 'image/jpg',
|
||||
content_id: 234,
|
||||
},
|
||||
created_by_id: 1,
|
||||
)
|
||||
assert_nil(store.preferences[:resizable])
|
||||
assert_nil(store.preferences[:content_inline])
|
||||
assert_nil(store.preferences[:content_preview])
|
||||
|
||||
# possible (no preview or inline needed)
|
||||
store = Store.add(
|
||||
object: 'SomeObject7',
|
||||
o_id: rand(1_234_567_890),
|
||||
data: File.binread(Rails.root.join('test', 'data', 'image', '8000x25.jpg')),
|
||||
filename: 'test1.jpg',
|
||||
preferences: {
|
||||
content_type: 'image/jpg',
|
||||
content_id: 234,
|
||||
},
|
||||
created_by_id: 1,
|
||||
)
|
||||
assert_nil(store.preferences[:resizable])
|
||||
assert_nil(store.preferences[:content_inline])
|
||||
assert_nil(store.preferences[:content_preview])
|
||||
|
||||
# possible (preview and inline)
|
||||
store = Store.add(
|
||||
object: 'SomeObject8',
|
||||
o_id: rand(1_234_567_890),
|
||||
data: File.binread(Rails.root.join('test', 'data', 'image', '8000x300.jpg')),
|
||||
filename: 'test1.jpg',
|
||||
preferences: {
|
||||
content_type: 'image/jpg',
|
||||
content_id: 234,
|
||||
},
|
||||
created_by_id: 1,
|
||||
)
|
||||
assert_equal(store.preferences[:resizable], true)
|
||||
assert_equal(store.preferences[:content_inline], true)
|
||||
assert_equal(store.preferences[:content_preview], true)
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue