mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Conform EmailLog#bounce_error_code to RFC (#16010)
This commit makes sure that the email log's bounce_error_code conforms to the SMTP error code RFC on save, so that it is always in the format X.X.X or XXX without any additional string details. Also included is a migration to fix this issue for past records.
This commit is contained in:
19
db/post_migrate/20220220234155_conform_bounce_error_code.rb
Normal file
19
db/post_migrate/20220220234155_conform_bounce_error_code.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
# frozen_string_literal: true
|
||||
#
|
||||
class ConformBounceErrorCode < ActiveRecord::Migration[6.1]
|
||||
def up
|
||||
DB.exec(<<~SQL, regexp: '\d\.\d\.\d|\d\d\d')
|
||||
UPDATE email_logs
|
||||
SET bounce_error_code = (
|
||||
SELECT array_to_string(
|
||||
regexp_matches(bounce_error_code, :regexp),
|
||||
''
|
||||
)
|
||||
) WHERE bounce_error_code IS NOT NULL;
|
||||
SQL
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user