Bug: Fixed quoted text parsing in incoming email (#1076)

* Bugfix: Fixed quoted text parsing in incoming email

We had changed the support email from an account based
only value to account based with fallback on global config
and environment variable.

Incoming email quoted text parsing was still based on
account based support email. Changed this to utilize
the newly introduced fallback values from global config
and environment for parsing quoted text.

* Bugfix: Added one more sender agnostic regex for quoted text parsing
This commit is contained in:
Sony Mathew 2020-07-21 12:20:46 +05:30 committed by GitHub
parent 8079bf50a0
commit fcb7625616
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -85,18 +85,30 @@ class MailPresenter < SimpleDelegator
end end
def quoted_text_regexes def quoted_text_regexes
sender_agnostic_regexes = [ return sender_agnostic_regexes if @account.nil? || account_support_email.blank?
[
Regexp.new("From:\s*" + Regexp.escape(account_support_email), Regexp::IGNORECASE),
Regexp.new('<' + Regexp.escape(account_support_email) + '>', Regexp::IGNORECASE),
Regexp.new(Regexp.escape(account_support_email) + "\s+wrote:", Regexp::IGNORECASE),
Regexp.new('On(.*)' + Regexp.escape(account_support_email) + '(.*)wrote:', Regexp::IGNORECASE)
] + sender_agnostic_regexes
end
def sender_agnostic_regexes
@sender_agnostic_regexes ||= [
Regexp.new("^.*On.*(\n)?wrote:$", Regexp::IGNORECASE), Regexp.new("^.*On.*(\n)?wrote:$", Regexp::IGNORECASE),
Regexp.new('^.*On(.*)(.*)wrote:$', Regexp::IGNORECASE),
Regexp.new("-+original\s+message-+\s*$", Regexp::IGNORECASE), Regexp.new("-+original\s+message-+\s*$", Regexp::IGNORECASE),
Regexp.new("from:\s*$", Regexp::IGNORECASE) Regexp.new("from:\s*$", Regexp::IGNORECASE)
] ]
return sender_agnostic_regexes if @account.nil? || @account.support_email.blank? end
[ def account_support_email
Regexp.new("From:\s*" + Regexp.escape(@account.support_email), Regexp::IGNORECASE), @account_support_email ||= begin
Regexp.new('<' + Regexp.escape(@account.support_email) + '>', Regexp::IGNORECASE), @account.support_email ||
Regexp.new(Regexp.escape(@account.support_email) + "\s+wrote:", Regexp::IGNORECASE), GlobalConfig.get('MAILER_SUPPORT_EMAIL')['MAILER_SUPPORT_EMAIL'] ||
Regexp.new('On(.*)' + Regexp.escape(@account.support_email) + '(.*)wrote:', Regexp::IGNORECASE) ENV.fetch('MAILER_SENDER_EMAIL', nil)
] + sender_agnostic_regexes end
end end
end end