extract bounce scores into site settings

This commit is contained in:
Régis Hanol 2016-07-25 17:27:28 +02:00
parent 9971e62254
commit d2e22ab215
4 changed files with 16 additions and 14 deletions

View File

@ -29,9 +29,9 @@ class WebhooksController < ActionController::Base
# by the "dropped" event and we don't want to increase bounce score twice
# for the same message
if event == "bounced".freeze && params["error"]["4."]
process_bounce(message_id, Email::Receiver::SOFT_BOUNCE_SCORE)
process_bounce(message_id, SiteSetting.soft_bounce_score)
elsif event == "dropped".freeze
process_bounce(message_id, Email::Receiver::HARD_BOUNCE_SCORE)
process_bounce(message_id, SiteSetting.hard_bounce_score)
end
mailgun_success
@ -43,12 +43,12 @@ class WebhooksController < ActionController::Base
message_id = (event["smtp-id"] || "").tr("<>", "")
if event["event"] == "bounce".freeze
if event["status"]["4."]
process_bounce(message_id, Email::Receiver::SOFT_BOUNCE_SCORE)
process_bounce(message_id, SiteSetting.soft_bounce_score)
else
process_bounce(message_id, Email::Receiver::HARD_BOUNCE_SCORE)
process_bounce(message_id, SiteSetting.hard_bounce_score)
end
elsif event["event"] == "dropped".freeze
process_bounce(message_id, Email::Receiver::HARD_BOUNCE_SCORE)
process_bounce(message_id, SiteSetting.hard_bounce_score)
end
end
@ -61,9 +61,9 @@ class WebhooksController < ActionController::Base
message_id = event["CustomID"]
if event["event"] == "bounce".freeze
if event["hard_bounce"]
process_bounce(message_id, Email::Receiver::HARD_BOUNCE_SCORE)
process_bounce(message_id, SiteSetting.hard_bounce_score)
else
process_bounce(message_id, Email::Receiver::SOFT_BOUNCE_SCORE)
process_bounce(message_id, SiteSetting.soft_bounce_score)
end
end
end
@ -79,9 +79,9 @@ class WebhooksController < ActionController::Base
case event["event"]
when "hard_bounce"
process_bounce(message_id, Email::Receiver::HARD_BOUNCE_SCORE)
process_bounce(message_id, SiteSetting.hard_bounce_score)
when "soft_bounce"
process_bounce(message_id, Email::Receiver::SOFT_BOUNCE_SCORE)
process_bounce(message_id, SiteSetting.soft_bounce_score)
end
end

View File

@ -1210,6 +1210,9 @@ en:
ignore_by_title: "Ignore incoming emails based on their title."
mailgun_api_key: "Mailgun Secret API key used to verify webhook messages."
soft_bounce_score: "Score added to the user when a temporary bounce happens."
hard_bounce_score: "Score added to the user when a permanent bounce happens."
manual_polling_enabled: "Push emails using the API for email replies."
pop3_polling_enabled: "Poll via POP3 for email replies."
pop3_polling_ssl: "Use SSL while connecting to the POP3 server. (Recommended)"

View File

@ -622,6 +622,8 @@ email:
mailgun_api_key:
default: ''
regex: '^key-\h{32}$'
soft_bounce_score: 1
hard_bounce_score: 2
files:

View File

@ -136,9 +136,6 @@ module Email
end
end
SOFT_BOUNCE_SCORE ||= 1
HARD_BOUNCE_SCORE ||= 2
def is_bounce?
return false unless @mail.bounced? || verp
@ -152,9 +149,9 @@ module Email
email ||= @from_email
if @mail.error_status.present? && @mail.error_status.start_with?("4.")
Email::Receiver.update_bounce_score(email, SOFT_BOUNCE_SCORE)
Email::Receiver.update_bounce_score(email, SiteSetting.soft_bounce_score)
else
Email::Receiver.update_bounce_score(email, HARD_BOUNCE_SCORE)
Email::Receiver.update_bounce_score(email, SiteSetting.hard_bounce_score)
end
true