mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 17:24:42 +08:00
c32bd8ae48
Adds the settings: raw_email_max_length, raw_rejected_email_max_length, delete_rejected_email_after_days. These settings control retention of the "raw" emails logs. raw_email_max_length ensures that if we get incoming email that is huge we will truncate it removing uploads from the raw log. raw_rejected_email_max_length introduces an even more aggressive truncation for rejected incoming mail. delete_rejected_email_after_days controls how many days we will keep rejected emails for (default 90)
15 lines
591 B
Ruby
15 lines
591 B
Ruby
# frozen_string_literal: true
|
|
|
|
desc "removes attachments and truncates long raw message"
|
|
task "incoming_emails:truncate_long" => :environment do
|
|
IncomingEmail.find_each do |incoming_email|
|
|
truncated_raw = Email::Cleaner.new(incoming_email.raw, rejected: incoming_email.rejection_message.present?).execute
|
|
|
|
# raw email is using \n as line separator, mail gem is using \r\n
|
|
# we need to determine if anything change to avoid updating all records
|
|
changed = truncated_raw != Mail.new(incoming_email.raw).to_s
|
|
|
|
incoming_email.update(raw: truncated_raw) if changed
|
|
end
|
|
end
|