Added service protection. Just create a max. of recipients/users.

This commit is contained in:
Martin Edenhofer 2017-09-28 20:32:04 +02:00
parent 1c941ec317
commit d5033b99bd
2 changed files with 41 additions and 0 deletions

View file

@ -87,6 +87,8 @@ module Channel::Filter::IdentifySender
# create to and cc user # create to and cc user
def self.create_recipients(mail) def self.create_recipients(mail)
max_count = 40
current_count = 0
['raw-to', 'raw-cc'].each { |item| ['raw-to', 'raw-cc'].each { |item|
next if !mail[item.to_sym] next if !mail[item.to_sym]
begin begin
@ -99,6 +101,8 @@ module Channel::Filter::IdentifySender
lastname: '', lastname: '',
email: address_data.address, email: address_data.address,
) )
current_count += 1
return false if current_count == max_count
} }
rescue => e rescue => e
# parse not parseable fields by mail gem like # parse not parseable fields by mail gem like
@ -122,6 +126,8 @@ module Channel::Filter::IdentifySender
lastname: '', lastname: '',
email: address, email: address,
) )
current_count += 1
return false if current_count == max_count
} }
end end
} }

View file

@ -0,0 +1,35 @@
# encoding: utf-8
require 'test_helper'
class EmailProcessIdentifySenderMax < ActiveSupport::TestCase
test 'text max created recipients per email' do
current_users = User.count
email_raw_string = "From: customer@example.com
To: #{generate_recipient(22)}
Cc: #{generate_recipient(22)}
Subject: test max sender identify
Some Text"
ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
ticket = Ticket.find(ticket_p.id)
assert_equal('test max sender identify', ticket.title)
assert_equal(current_users + 40, User.count)
end
def generate_recipient(count)
recipients = ''
count.times.each do
if recipients.present?
recipients += ', '
end
domain = "#{Time.zone.now.to_i}-#{rand(999_999_999)}.example.com"
email = "#{Time.zone.now.to_i}-#{rand(999_999_999)}@#{domain}"
recipients += email
end
recipients
end
end