mirror of
https://github.com/discourse/discourse.git
synced 2025-09-05 08:59:27 +08:00
FEATURE: retry processing incoming emails on rate limit
This commit is contained in:
parent
5c06076b5c
commit
51322a46b3
5 changed files with 61 additions and 15 deletions
|
@ -2,18 +2,21 @@ module Email
|
|||
|
||||
class Processor
|
||||
|
||||
def initialize(mail)
|
||||
def initialize(mail, retry_on_rate_limit=true)
|
||||
@mail = mail
|
||||
@retry_on_rate_limit = retry_on_rate_limit
|
||||
end
|
||||
|
||||
def self.process!(mail)
|
||||
Email::Processor.new(mail).process!
|
||||
def self.process!(mail, retry_on_rate_limit=true)
|
||||
Email::Processor.new(mail, retry_on_rate_limit).process!
|
||||
end
|
||||
|
||||
def process!
|
||||
begin
|
||||
receiver = Email::Receiver.new(@mail)
|
||||
receiver.process!
|
||||
rescue RateLimiter::LimitExceeded
|
||||
@retry_on_rate_limit ? Jobs.enqueue(:process_email, mail: @mail) : raise
|
||||
rescue Email::Receiver::BouncedEmailError => e
|
||||
# never reply to bounced emails
|
||||
log_email_process_failure(@mail, e)
|
||||
|
@ -49,7 +52,6 @@ module Email
|
|||
when ActiveRecord::Rollback then :email_reject_invalid_post
|
||||
when Email::Receiver::InvalidPostAction then :email_reject_invalid_post_action
|
||||
when Discourse::InvalidAccess then :email_reject_invalid_access
|
||||
when RateLimiter::LimitExceeded then :email_reject_rate_limit_specified
|
||||
end
|
||||
|
||||
template_args = {}
|
||||
|
@ -61,10 +63,6 @@ module Email
|
|||
template_args[:post_error] = e.message
|
||||
end
|
||||
|
||||
if message_template == :email_reject_rate_limit_specified
|
||||
template_args[:rate_limit_description] = e.description
|
||||
end
|
||||
|
||||
if message_template
|
||||
# inform the user about the rejection
|
||||
message = Mail::Message.new(mail_string)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue