diff --git a/app/models/ticket/article.rb b/app/models/ticket/article.rb
index 3cb3250da..84b91e1f4 100644
--- a/app/models/ticket/article.rb
+++ b/app/models/ticket/article.rb
@@ -41,10 +41,24 @@ class Ticket::Article < ApplicationModel
self.message_id_md5 = Digest::MD5.hexdigest(message_id.to_s)
end
- # insert inline image urls
+=begin
+
+insert inline image urls to body
+
+ article_attributes = Ticket::Article.insert_urls(
+ article_attributes,
+ attachments,
+ )
+
+returns
+
+ article_attributes_with_body_and_urls
+
+=end
+
def self.insert_urls(article, attachments)
inline_attachments = {}
- article['body'].gsub!( /()/i ) { |item|
+ article['body'].gsub!( /()/i ) { |item|
replace = item
# look for attachment
@@ -65,6 +79,38 @@ class Ticket::Article < ApplicationModel
article
end
+=begin
+
+get inline attachments of article
+
+ article = Ticket::Article.find(123)
+ attachments = article.attachments_inline
+
+returns
+
+ [attachment1, attachment2, ...]
+
+=end
+
+ def attachments_inline
+ inline_attachments = {}
+ body.gsub( //i ) { |_item|
+
+ # look for attachment
+ attachments.each { |file|
+ next if !file.preferences['Content-ID'] || file.preferences['Content-ID'] != $2
+ inline_attachments[file.id] = true
+ break
+ }
+ }
+ new_attachments = []
+ attachments.each { |file|
+ next if !inline_attachments[file.id]
+ new_attachments.push file
+ }
+ new_attachments
+ end
+
def self.last_customer_agent_article(ticket_id)
sender = Ticket::Article::Sender.lookup(name: 'System')
Ticket::Article.where('ticket_id = ? AND sender_id NOT IN (?)', ticket_id, sender.id).order('created_at DESC').first
diff --git a/lib/notification_factory/mailer.rb b/lib/notification_factory/mailer.rb
index e4763d238..de4a9b44a 100644
--- a/lib/notification_factory/mailer.rb
+++ b/lib/notification_factory/mailer.rb
@@ -82,6 +82,7 @@ returns
body: 'some body',
content_type: '', # optional, e. g. 'text/html'
references: ['message-id123', 'message-id456'],
+ attachments: [attachments...], # optional
)
=end
@@ -106,6 +107,7 @@ returns
references: data[:references],
body: data[:body],
content_type: content_type,
+ attachments: data[:attachments],
},
true
)
@@ -122,6 +124,7 @@ returns
main_object: ticket.find(123), # optional
references: ['message-id123', 'message-id456'],
standalone: true, # default: false - will send header & footer
+ attachments: [attachments...], # optional
)
=end
@@ -147,6 +150,7 @@ returns
body: result[:body],
content_type: 'text/html',
references: data[:references],
+ attachments: data[:attachments],
)
end
diff --git a/test/unit/notification_factory_mailer_test.rb b/test/unit/notification_factory_mailer_test.rb
index 8e2323a19..31b79d7b5 100644
--- a/test/unit/notification_factory_mailer_test.rb
+++ b/test/unit/notification_factory_mailer_test.rb
@@ -6,7 +6,7 @@ class NotificationFactoryMailerTest < ActiveSupport::TestCase
test 'notifications send' do
result = NotificationFactory::Mailer.send(
recipient: User.find(2),
- subject: 'sime subject',
+ subject: 'some subject',
body: 'some body',
content_type: '',
)
@@ -16,7 +16,7 @@ class NotificationFactoryMailerTest < ActiveSupport::TestCase
result = NotificationFactory::Mailer.send(
recipient: User.find(2),
- subject: 'sime subject',
+ subject: 'some subject',
body: 'some body',
content_type: 'text/plain',
)
@@ -26,7 +26,7 @@ class NotificationFactoryMailerTest < ActiveSupport::TestCase
result = NotificationFactory::Mailer.send(
recipient: User.find(2),
- subject: 'sime subject',
+ subject: 'some subject',
body: 'some body',
content_type: 'text/html',
)
@@ -34,6 +34,50 @@ class NotificationFactoryMailerTest < ActiveSupport::TestCase
assert_match('text/plain', result.to_s)
assert_match('body', result.to_s)
assert_match('text/html', result.to_s)
+
+ attachments = []
+ attachments.push Store.add(
+ object: 'TestMailer',
+ o_id: 1,
+ data: 'content_file1_normally_should_be_an_image',
+ filename: 'some_file1.jpg',
+ preferences: {
+ 'Content-Type' => 'image/jpeg',
+ 'Mime-Type' => 'image/jpeg',
+ 'Content-ID' => '15.274327094.140938@zammad.example.com',
+ 'Content-Disposition' => 'inline'
+ },
+ created_by_id: 1,
+ )
+ attachments.push Store.add(
+ object: 'TestMailer',
+ o_id: 1,
+ data: 'content_file2',
+ filename: 'some_file2.txt',
+ preferences: {
+ 'Content-Type' => 'text/stream',
+ 'Mime-Type' => 'text/stream',
+ },
+ created_by_id: 1,
+ )
+
+ result = NotificationFactory::Mailer.send(
+ recipient: User.find(2),
+ subject: 'some subject',
+ body: 'some bodyasdasd
',
+ content_type: 'text/html',
+ attachments: attachments,
+ )
+ assert_match('some body', result.to_s)
+ assert_match('text/plain', result.to_s)
+ assert_match('body', result.to_s)
+ assert_match('text/html', result.to_s)
+ assert_match('Content-Type: image/jpeg', result.to_s)
+ assert_match('Content-Disposition: inline', result.to_s)
+ assert_match('Content-ID: <15.274327094.140938@zammad.example.com>', result.to_s)
+ assert_match('text/stream', result.to_s)
+ assert_match('some_file2.txt', result.to_s)
+
end
test 'notifications settings' do
diff --git a/test/unit/ticket_test.rb b/test/unit/ticket_test.rb
index 938856ed9..85a61a5dd 100644
--- a/test/unit/ticket_test.rb
+++ b/test/unit/ticket_test.rb
@@ -282,4 +282,93 @@ class TicketTest < ActiveSupport::TestCase
end
+ test 'article attachment helper' do
+
+ ticket1 = Ticket.create(
+ title: 'some article helper test1',
+ group: Group.lookup(name: 'Users'),
+ customer_id: 2,
+ state: Ticket::State.lookup(name: 'new'),
+ priority: Ticket::Priority.lookup(name: '2 normal'),
+ updated_by_id: 1,
+ created_by_id: 1,
+ )
+ assert(ticket1, 'ticket created')
+
+ # create inbound article #1
+ article1 = Ticket::Article.create(
+ ticket_id: ticket1.id,
+ from: 'some_sender@example.com',
+ to: 'some_recipient@example.com',
+ subject: 'some subject',
+ message_id: 'some@id',
+ content_type: 'text/html',
+ body: 'some message article helper test1