ignore emails that are from the reply by email addresses (#5843)

This commit is contained in:
Ryan Mulligan
2018-05-23 01:04:45 -07:00
committed by Régis Hanol
parent 930ebb5684
commit fac4bf2f85
6 changed files with 48 additions and 8 deletions

View File

@@ -36,6 +36,7 @@ module Email
def handle_failure(mail_string, e)
message_template = case e
when Email::Receiver::NoSenderDetectedError then return nil
when Email::Receiver::FromReplyByAddressError then return nil
when Email::Receiver::EmptyEmailError then :email_reject_empty
when Email::Receiver::NoBodyDetectedError then :email_reject_empty
when Email::Receiver::UserNotFoundError then :email_reject_user_not_found

View File

@@ -21,6 +21,7 @@ module Email
class BouncedEmailError < ProcessingError; end
class NoBodyDetectedError < ProcessingError; end
class NoSenderDetectedError < ProcessingError; end
class FromReplyByAddressError < ProcessingError; end
class InactiveUserError < ProcessingError; end
class SilencedUserError < ProcessingError; end
class BadDestinationAddress < ProcessingError; end
@@ -107,6 +108,7 @@ module Email
def process_internal
raise BouncedEmailError if is_bounce?
raise NoSenderDetectedError if @from_email.blank?
raise FromReplyByAddressError if is_from_reply_by_email_address?
raise ScreenedEmailError if ScreenedEmail.should_block?(@from_email)
user = find_user(@from_email)
@@ -203,6 +205,10 @@ module Email
true
end
def is_from_reply_by_email_address?
Email::Receiver.reply_by_email_address_regex.match(@from_email)
end
def verp
@verp ||= all_destinations.select { |to| to[/\+verp-\h{32}@/] }.first
end
@@ -723,9 +729,13 @@ module Email
reply_addresses.flatten!
reply_addresses.select!(&:present?)
reply_addresses.map! { |a| Regexp.escape(a) }
reply_addresses.map! { |a| a.gsub(Regexp.escape("%{reply_key}"), "(\\h{32})") }
/#{reply_addresses.join("|")}/
reply_addresses.map! { |a| a.gsub("\+", "\+?") }
reply_addresses.map! { |a| a.gsub(Regexp.escape("%{reply_key}"), "(\\h{32})?") }
if reply_addresses.empty?
/$a/ # a regex that can never match
else
/#{reply_addresses.join("|")}/
end
end
def group_incoming_emails_regex