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

@ -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

@ -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