123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
- module Ticket::Subject
- =begin
- build new subject with ticket number in there
- ticket = Ticket.find(123)
- result = ticket.subject_build('some subject')
- returns
- result = "[Ticket#1234567] some subject"
- =end
- def subject_build (subject)
- # clena subject
- subject = self.subject_clean(subject)
- ticket_hook = Setting.get('ticket_hook')
- ticket_hook_divider = Setting.get('ticket_hook_divider')
- # none position
- if Setting.get('ticket_hook_position') == 'none'
- return subject
- end
- # right position
- if Setting.get('ticket_hook_position') == 'right'
- return subject + " [#{ticket_hook}#{ticket_hook_divider}#{self.number}] "
- end
- # left position
- return "[#{ticket_hook}#{ticket_hook_divider}#{self.number}] " + subject
- end
- =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
- def subject_clean (subject)
- ticket_hook = Setting.get('ticket_hook')
- ticket_hook_divider = Setting.get('ticket_hook_divider')
- ticket_subject_size = Setting.get('ticket_subject_size')
- # remove all possible ticket hook formats with []
- subject = subject.gsub /\[#{ticket_hook}: #{self.number}\](\s+?|)/, ''
- subject = subject.gsub /\[#{ticket_hook}:#{self.number}\](\s+?|)/, ''
- subject = subject.gsub /\[#{ticket_hook}#{ticket_hook_divider}#{self.number}\](\s+?|)/, ''
- # remove all possible ticket hook formats without []
- subject = subject.gsub /#{ticket_hook}: #{self.number}(\s+?|)/, ''
- subject = subject.gsub /#{ticket_hook}:#{self.number}(\s+?|)/, ''
- subject = subject.gsub /#{ticket_hook}#{ticket_hook_divider}#{self.number}(\s+?|)/, ''
- # remove leading "..:\s" and "..[\d+]:\s" e. g. "Re: " or "Re[5]: "
- subject = subject.gsub /^(..(\[\d+\])?:\s)+/, ''
- # resize subject based on config
- if subject.length > ticket_subject_size.to_i
- subject = subject[ 0, ticket_subject_size.to_i ] + '[...]'
- end
- return subject
- end
- end
|