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: ->
if @subject
return @subject
if App.Ticket.exists( @ticket_id )
ticket = App.Ticket.find( @ticket_id )
if App.Ticket.exists(@ticket_id)
ticket = App.Ticket.find(@ticket_id)
if ticket
return ticket.title
'???'

View file

@ -13,7 +13,7 @@
<div class="page-header">
<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 class="page-content">

View file

@ -75,7 +75,7 @@ example
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
timeout = 45
@ -173,20 +173,14 @@ example
message_meta = @imap.fetch(message_id, ['RFC822.SIZE', 'FLAGS', 'INTERNALDATE'])[0]
# ignore to big messages
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
info = too_big?(message_meta, count, count_all)
if info
notice += "#{info}\n"
next
end
# ignore deleted messages
if message_meta.attr['FLAGS'].include?(:Deleted)
Rails.logger.info " - ignore message #{count}/#{count_all} - because message has already delete flag"
next
end
next if deleted?(message_meta, count, count_all)
# delete email from server after article was created
msg = @imap.fetch(message_id, 'RFC822')[0].attr['RFC822']
@ -212,4 +206,24 @@ example
return if !@imap
@imap.disconnect()
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

View file

@ -202,6 +202,9 @@ returns
@stream_client.client.user(filter) do |tweet|
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)
# check direct message

View file

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

View file

@ -4,13 +4,13 @@ module Channel::Filter::FollowUpCheck
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
ticket = Ticket::Number.check(mail[:subject])
if ticket
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
end
@ -21,7 +21,7 @@ module Channel::Filter::FollowUpCheck
ticket = Ticket::Number.check(mail[:body])
if ticket
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
end
end
@ -33,13 +33,13 @@ module Channel::Filter::FollowUpCheck
ticket = Ticket::Number.check(attachment[:data])
next if !ticket
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
}
end
# 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'
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
next if !article
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
}
end
@ -98,7 +98,7 @@ module Channel::Filter::FollowUpCheck
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."
mail[ 'x-zammad-ticket-id'.to_sym ] = article_first.ticket_id
mail['x-zammad-ticket-id'.to_sym] = article_first.ticket_id
return true
}
end

View file

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