Improved code layout.

This commit is contained in:
Martin Edenhofer 2017-03-06 12:18:04 +01:00
parent 187376a2c1
commit 199bf8773a
7 changed files with 47 additions and 24 deletions

View file

@ -27,8 +27,8 @@ class App.TicketArticle extends App.Model
displayName: -> displayName: ->
if @subject if @subject
return @subject return @subject
if App.Ticket.exists( @ticket_id ) if App.Ticket.exists(@ticket_id)
ticket = App.Ticket.find( @ticket_id ) ticket = App.Ticket.find(@ticket_id)
if ticket if ticket
return ticket.title return ticket.title
'???' '???'

View file

@ -13,7 +13,7 @@
<div class="page-header"> <div class="page-header">
<div class="page-header-title"> <div class="page-header-title">
<h1><%- @T( @page.head ) %> <small><%- @T( @page.sub_head ) %></small></h1> <h1><%- @T(@page.head) %> <small><%- @T(@page.sub_head) %></small></h1>
</div> </div>
</div> </div>
<div class="page-content"> <div class="page-content">

View file

@ -75,7 +75,7 @@ example
end end
end end
Rails.logger.info "fetching imap (#{options[:host]}/#{options[:user]} port=#{port},ssl=#{ssl})" Rails.logger.info "fetching imap (#{options[:host]}/#{options[:user]} port=#{port},ssl=#{ssl},folder=#{options[:folder]})"
# on check, reduce open_timeout to have faster probing # on check, reduce open_timeout to have faster probing
timeout = 45 timeout = 45
@ -173,20 +173,14 @@ example
message_meta = @imap.fetch(message_id, ['RFC822.SIZE', 'FLAGS', 'INTERNALDATE'])[0] message_meta = @imap.fetch(message_id, ['RFC822.SIZE', 'FLAGS', 'INTERNALDATE'])[0]
# ignore to big messages # ignore to big messages
max_message_size = Setting.get('postmaster_max_size').to_f info = too_big?(message_meta, count, count_all)
real_message_size = message_meta.attr['RFC822.SIZE'].to_f / 1024 / 1024 if info
if real_message_size > max_message_size
info = " - ignore message #{count}/#{count_all} - because message is too big (is:#{real_message_size} MB/max:#{max_message_size} MB)"
Rails.logger.info info
notice += "#{info}\n" notice += "#{info}\n"
next next
end end
# ignore deleted messages # ignore deleted messages
if message_meta.attr['FLAGS'].include?(:Deleted) next if deleted?(message_meta, count, count_all)
Rails.logger.info " - ignore message #{count}/#{count_all} - because message has already delete flag"
next
end
# delete email from server after article was created # delete email from server after article was created
msg = @imap.fetch(message_id, 'RFC822')[0].attr['RFC822'] msg = @imap.fetch(message_id, 'RFC822')[0].attr['RFC822']
@ -212,4 +206,24 @@ example
return if !@imap return if !@imap
@imap.disconnect() @imap.disconnect()
end end
private
def deleted?(message_meta, count, count_all)
return false if !message_meta.attr['FLAGS'].include?(:Deleted)
Rails.logger.info " - ignore message #{count}/#{count_all} - because message has already delete flag"
true
end
def too_big?(message_meta, count, count_all)
max_message_size = Setting.get('postmaster_max_size').to_f
real_message_size = message_meta.attr['RFC822.SIZE'].to_f / 1024 / 1024
if real_message_size > max_message_size
info = " - ignore message #{count}/#{count_all} - because message is too big (is:#{real_message_size} MB/max:#{max_message_size} MB)"
Rails.logger.info info
return info
end
false
end
end end

View file

@ -202,6 +202,9 @@ returns
@stream_client.client.user(filter) do |tweet| @stream_client.client.user(filter) do |tweet|
next if tweet.class != Twitter::Tweet && tweet.class != Twitter::DirectMessage next if tweet.class != Twitter::Tweet && tweet.class != Twitter::DirectMessage
# wait until own posts are stored in local database to prevent importing own tweets
sleep 4
next if Ticket::Article.find_by(message_id: tweet.id) next if Ticket::Article.find_by(message_id: tweet.id)
# check direct message # check direct message

View file

@ -30,9 +30,9 @@ class Channel::EmailParser
data: 'binary of attachment', data: 'binary of attachment',
filename: 'file_name_of_attachment.txt', filename: 'file_name_of_attachment.txt',
preferences: { preferences: {
content-alternative: true, 'content-alternative' => true,
Mime-Type: 'text/plain', 'Mime-Type' => 'text/plain',
Charset: 'iso-8859-1', 'Charset: => 'iso-8859-1',
}, },
}, },
], ],

View file

@ -4,13 +4,13 @@ module Channel::Filter::FollowUpCheck
def self.run(_channel, mail) def self.run(_channel, mail)
return if mail[ 'x-zammad-ticket-id'.to_sym ] return if mail['x-zammad-ticket-id'.to_sym]
# get ticket# from subject # get ticket# from subject
ticket = Ticket::Number.check(mail[:subject]) ticket = Ticket::Number.check(mail[:subject])
if ticket if ticket
Rails.logger.debug "Follow up for '##{ticket.number}' in subject." Rails.logger.debug "Follow up for '##{ticket.number}' in subject."
mail[ 'x-zammad-ticket-id'.to_sym ] = ticket.id mail['x-zammad-ticket-id'.to_sym] = ticket.id
return true return true
end end
@ -21,7 +21,7 @@ module Channel::Filter::FollowUpCheck
ticket = Ticket::Number.check(mail[:body]) ticket = Ticket::Number.check(mail[:body])
if ticket if ticket
Rails.logger.debug "Follow up for '##{ticket.number}' in body." Rails.logger.debug "Follow up for '##{ticket.number}' in body."
mail[ 'x-zammad-ticket-id'.to_sym ] = ticket.id mail['x-zammad-ticket-id'.to_sym] = ticket.id
return true return true
end end
end end
@ -33,13 +33,13 @@ module Channel::Filter::FollowUpCheck
ticket = Ticket::Number.check(attachment[:data]) ticket = Ticket::Number.check(attachment[:data])
next if !ticket next if !ticket
Rails.logger.debug "Follow up for '##{ticket.number}' in attachment." Rails.logger.debug "Follow up for '##{ticket.number}' in attachment."
mail[ 'x-zammad-ticket-id'.to_sym ] = ticket.id mail['x-zammad-ticket-id'.to_sym] = ticket.id
return true return true
} }
end end
# get ticket# from references # get ticket# from references
if setting.include?('references') || (mail[ 'x-zammad-is-auto-response'.to_sym ] == true || Setting.get('ticket_hook_position') == 'none') if setting.include?('references') || (mail['x-zammad-is-auto-response'.to_sym] == true || Setting.get('ticket_hook_position') == 'none')
# get all references 'References' + 'In-Reply-To' # get all references 'References' + 'In-Reply-To'
references = '' references = ''
@ -59,7 +59,7 @@ module Channel::Filter::FollowUpCheck
article = Ticket::Article.where(message_id_md5: message_id_md5).order('created_at DESC, id DESC').limit(1).first article = Ticket::Article.where(message_id_md5: message_id_md5).order('created_at DESC, id DESC').limit(1).first
next if !article next if !article
Rails.logger.debug "Follow up for '##{article.ticket.number}' in references." Rails.logger.debug "Follow up for '##{article.ticket.number}' in references."
mail[ 'x-zammad-ticket-id'.to_sym ] = article.ticket_id mail['x-zammad-ticket-id'.to_sym] = article.ticket_id
return true return true
} }
end end
@ -98,7 +98,7 @@ module Channel::Filter::FollowUpCheck
next if subject_to_check != article_first.subject next if subject_to_check != article_first.subject
Rails.logger.debug "Follow up for '##{article.ticket.number}' in references with same subject as inital article." Rails.logger.debug "Follow up for '##{article.ticket.number}' in references with same subject as inital article."
mail[ 'x-zammad-ticket-id'.to_sym ] = article_first.ticket_id mail['x-zammad-ticket-id'.to_sym] = article_first.ticket_id
return true return true
} }
end end

View file

@ -106,9 +106,13 @@ move files from db backend to fs
Store::File.move('DB', 'File') Store::File.move('DB', 'File')
nice move to keep system responsive
Store::File.move('DB', 'File', delay_in_sec) # e. g. 1
=end =end
def self.move(source, target) def self.move(source, target, delay = nil)
adapter_source = load_adapter("Store::Provider::#{source}") adapter_source = load_adapter("Store::Provider::#{source}")
adapter_target = load_adapter("Store::Provider::#{target}") adapter_target = load_adapter("Store::Provider::#{target}")
@ -126,6 +130,8 @@ move files from db backend to fs
adapter_source.delete(item.sha) adapter_source.delete(item.sha)
logger.info "Moved file #{item.sha} from #{source} to #{target}" logger.info "Moved file #{item.sha} from #{source} to #{target}"
sleep delay if delay
} }
true true
end end