2014-02-03 19:23:00 +00:00
|
|
|
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
|
2013-06-12 15:59:58 +00:00
|
|
|
|
2012-12-24 13:55:43 +00:00
|
|
|
class Observer::Ticket::Article::FillupFromEmail < ActiveRecord::Observer
|
|
|
|
observe 'ticket::_article'
|
|
|
|
|
|
|
|
def before_create(record)
|
|
|
|
|
|
|
|
# return if we run import mode
|
|
|
|
return if Setting.get('import_mode')
|
|
|
|
|
|
|
|
# if sender is customer, do not change anything
|
2013-01-01 20:29:26 +00:00
|
|
|
sender = Ticket::Article::Sender.lookup( :id => record.ticket_article_sender_id )
|
2012-12-24 13:55:43 +00:00
|
|
|
return if sender == nil
|
|
|
|
return if sender['name'] == 'Customer'
|
|
|
|
|
|
|
|
# set email attributes
|
2013-01-01 20:29:26 +00:00
|
|
|
type = Ticket::Article::Type.lookup( :id => record.ticket_article_type_id )
|
2012-12-24 13:55:43 +00:00
|
|
|
return if type['name'] != 'email'
|
|
|
|
|
|
|
|
# set subject if empty
|
2013-01-01 20:29:26 +00:00
|
|
|
ticket = Ticket.lookup( :id => record.ticket_id )
|
2012-12-24 13:55:43 +00:00
|
|
|
if !record.subject || record.subject == ''
|
|
|
|
record.subject = ticket.title
|
|
|
|
end
|
|
|
|
|
|
|
|
# clean subject
|
|
|
|
record.subject = ticket.subject_clean( record.subject )
|
|
|
|
|
|
|
|
# generate message id
|
|
|
|
fqdn = Setting.get('fqdn')
|
|
|
|
record.message_id = '<' + DateTime.current.to_s(:number) + '.' + record.ticket_id.to_s + '.' + rand(999999).to_s() + '@' + fqdn + '>'
|
|
|
|
|
|
|
|
# set sender
|
|
|
|
email_address = ticket.group.email_address
|
2013-06-19 12:22:13 +00:00
|
|
|
if !email_address
|
|
|
|
raise "No email address found for group '#{ticket.group.name}'"
|
|
|
|
end
|
2012-12-24 13:55:43 +00:00
|
|
|
system_sender = "#{email_address.realname} <#{email_address.email}>"
|
|
|
|
if Setting.get('ticket_define_email_from') == 'AgentNameSystemAddressName'
|
|
|
|
seperator = Setting.get('ticket_define_email_from_seperator')
|
|
|
|
sender = User.find( record.created_by_id )
|
|
|
|
record.from = "#{sender.firstname} #{sender.lastname} #{seperator} #{system_sender}"
|
|
|
|
else
|
|
|
|
record.from = system_sender
|
|
|
|
end
|
|
|
|
end
|
2013-06-12 15:59:58 +00:00
|
|
|
end
|