2014-02-05 16:14:57 +00:00
|
|
|
class Observer::Ticket::Article::CommunicateEmail::BackgroundJob
|
|
|
|
def initialize(id)
|
|
|
|
@article_id = id
|
|
|
|
end
|
2015-05-07 10:27:12 +00:00
|
|
|
|
2014-02-05 16:14:57 +00:00
|
|
|
def perform
|
|
|
|
record = Ticket::Article.find( @article_id )
|
|
|
|
|
|
|
|
# build subject
|
2015-04-27 13:42:53 +00:00
|
|
|
ticket = Ticket.lookup( id: record.ticket_id )
|
2014-02-05 16:14:57 +00:00
|
|
|
subject = ticket.subject_build( record.subject )
|
|
|
|
|
|
|
|
# send email
|
2015-01-01 00:26:17 +00:00
|
|
|
message = Channel::EmailSend.send(
|
2014-02-05 16:14:57 +00:00
|
|
|
{
|
2015-04-27 13:42:53 +00:00
|
|
|
message_id: record.message_id,
|
|
|
|
in_reply_to: record.in_reply_to,
|
|
|
|
from: record.from,
|
|
|
|
to: record.to,
|
|
|
|
cc: record.cc,
|
|
|
|
subject: subject,
|
|
|
|
content_type: record.content_type,
|
|
|
|
body: record.body,
|
|
|
|
attachments: record.attachments
|
2014-02-05 16:14:57 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
# store mail plain
|
|
|
|
Store.add(
|
2015-04-27 13:42:53 +00:00
|
|
|
object: 'Ticket::Article::Mail',
|
|
|
|
o_id: record.id,
|
|
|
|
data: message.to_s,
|
|
|
|
filename: "ticket-#{ticket.number}-#{record.id}.eml",
|
|
|
|
preferences: {},
|
|
|
|
created_by_id: record.created_by_id,
|
2014-02-05 16:14:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# add history record
|
|
|
|
recipient_list = ''
|
|
|
|
[:to, :cc].each { |key|
|
2015-05-07 09:04:40 +00:00
|
|
|
|
|
|
|
next if !record[key]
|
|
|
|
next if record[key] == ''
|
|
|
|
|
|
|
|
if recipient_list != ''
|
|
|
|
recipient_list += ','
|
2014-02-05 16:14:57 +00:00
|
|
|
end
|
2015-05-07 09:04:40 +00:00
|
|
|
recipient_list += record[key]
|
2014-02-05 16:14:57 +00:00
|
|
|
}
|
2015-04-30 15:25:04 +00:00
|
|
|
|
|
|
|
return if recipient_list == ''
|
|
|
|
|
|
|
|
History.add(
|
|
|
|
o_id: record.id,
|
|
|
|
history_type: 'email',
|
|
|
|
history_object: 'Ticket::Article',
|
|
|
|
related_o_id: ticket.id,
|
|
|
|
related_history_object: 'Ticket',
|
|
|
|
value_from: record.subject,
|
|
|
|
value_to: recipient_list,
|
|
|
|
created_by_id: record.created_by_id,
|
|
|
|
)
|
2014-02-05 16:14:57 +00:00
|
|
|
end
|
2015-04-27 14:15:29 +00:00
|
|
|
end
|