2016-10-19 03:11:36 +00:00
|
|
|
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
|
2015-04-27 23:19:26 +00:00
|
|
|
module Ticket::Subject
|
2013-08-17 20:04:57 +00:00
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
build new subject with ticket number in there
|
|
|
|
|
|
|
|
ticket = Ticket.find(123)
|
2016-05-23 17:56:39 +00:00
|
|
|
result = ticket.subject_build('some subject', is_reply_true_false)
|
2013-08-17 20:04:57 +00:00
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
result = "[Ticket#1234567] some subject"
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
2016-05-23 17:56:39 +00:00
|
|
|
def subject_build(subject, is_reply = false)
|
2013-08-17 20:04:57 +00:00
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
# clena subject
|
2015-05-07 12:10:38 +00:00
|
|
|
subject = subject_clean(subject)
|
2013-08-17 20:04:57 +00:00
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
ticket_hook = Setting.get('ticket_hook')
|
|
|
|
ticket_hook_divider = Setting.get('ticket_hook_divider')
|
2016-05-23 17:56:39 +00:00
|
|
|
ticket_subject_re = Setting.get('ticket_subject_re')
|
2013-08-17 20:04:57 +00:00
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
# none position
|
|
|
|
if Setting.get('ticket_hook_position') == 'none'
|
2017-08-25 09:37:56 +00:00
|
|
|
if is_reply && ticket_subject_re.present?
|
|
|
|
subject = "#{ticket_subject_re}: #{subject}"
|
|
|
|
end
|
2015-04-27 23:19:26 +00:00
|
|
|
return subject
|
|
|
|
end
|
2013-08-17 20:04:57 +00:00
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
# right position
|
|
|
|
if Setting.get('ticket_hook_position') == 'right'
|
2017-08-25 09:37:56 +00:00
|
|
|
if is_reply && ticket_subject_re.present?
|
|
|
|
subject = "#{ticket_subject_re}: #{subject}"
|
|
|
|
end
|
|
|
|
return "#{subject} [#{ticket_hook}#{ticket_hook_divider}#{number}]"
|
2015-04-27 21:27:51 +00:00
|
|
|
end
|
2013-08-17 20:04:57 +00:00
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
# left position
|
2017-08-25 09:37:56 +00:00
|
|
|
if is_reply && ticket_subject_re.present?
|
|
|
|
return "#{ticket_subject_re}: [#{ticket_hook}#{ticket_hook_divider}#{number}] #{subject}"
|
|
|
|
end
|
|
|
|
"[#{ticket_hook}#{ticket_hook_divider}#{number}] #{subject}"
|
2015-04-27 23:19:26 +00:00
|
|
|
end
|
|
|
|
|
2013-08-17 20:04:57 +00:00
|
|
|
=begin
|
|
|
|
|
|
|
|
clean subject remove ticket number and other not needed chars
|
|
|
|
|
|
|
|
ticket = Ticket.find(123)
|
|
|
|
result = ticket.subject_clean('[Ticket#1234567] some subject')
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
result = "some subject"
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
2016-05-23 17:56:39 +00:00
|
|
|
def subject_clean(subject)
|
2015-04-27 23:19:26 +00:00
|
|
|
ticket_hook = Setting.get('ticket_hook')
|
|
|
|
ticket_hook_divider = Setting.get('ticket_hook_divider')
|
|
|
|
ticket_subject_size = Setting.get('ticket_subject_size')
|
2013-08-17 20:04:57 +00:00
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
# remove all possible ticket hook formats with []
|
2015-05-07 12:10:38 +00:00
|
|
|
subject = subject.gsub(/\[#{ticket_hook}: #{number}\](\s+?|)/, '')
|
|
|
|
subject = subject.gsub(/\[#{ticket_hook}:#{number}\](\s+?|)/, '')
|
|
|
|
subject = subject.gsub(/\[#{ticket_hook}#{ticket_hook_divider}#{number}\](\s+?|)/, '')
|
2013-08-17 20:04:57 +00:00
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
# remove all possible ticket hook formats without []
|
2015-05-07 12:10:38 +00:00
|
|
|
subject = subject.gsub(/#{ticket_hook}: #{number}(\s+?|)/, '')
|
|
|
|
subject = subject.gsub(/#{ticket_hook}:#{number}(\s+?|)/, '')
|
|
|
|
subject = subject.gsub(/#{ticket_hook}#{ticket_hook_divider}#{number}(\s+?|)/, '')
|
2013-08-17 20:04:57 +00:00
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
# remove leading "..:\s" and "..[\d+]:\s" e. g. "Re: " or "Re[5]: "
|
2015-05-05 13:43:00 +00:00
|
|
|
subject = subject.gsub(/^(..(\[\d+\])?:\s)+/, '')
|
2013-08-17 20:04:57 +00:00
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
# resize subject based on config
|
|
|
|
if subject.length > ticket_subject_size.to_i
|
|
|
|
subject = subject[ 0, ticket_subject_size.to_i ] + '[...]'
|
2015-04-27 21:27:51 +00:00
|
|
|
end
|
2015-04-27 23:19:26 +00:00
|
|
|
|
2017-10-24 20:34:52 +00:00
|
|
|
subject.strip!
|
2015-04-27 23:19:26 +00:00
|
|
|
subject
|
2013-08-17 20:04:57 +00:00
|
|
|
end
|
2014-02-03 19:23:00 +00:00
|
|
|
end
|