diff --git a/app/models/credential.rb b/app/models/credential.rb index 1af484d..2c37593 100644 --- a/app/models/credential.rb +++ b/app/models/credential.rb @@ -23,7 +23,7 @@ class Credential < ApplicationRecord belongs_to :server - TYPES = ["SMTP", "API", "SMTP-IP"] + TYPES = ["SMTP", "API", "SMTP-IP"].freeze validates :key, presence: true, uniqueness: { case_sensitive: false } validates :type, inclusion: { in: TYPES } diff --git a/app/models/domain.rb b/app/models/domain.rb index ae0b416..ba61992 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -44,15 +44,14 @@ class Domain < ApplicationRecord include HasDNSChecks - VERIFICATION_EMAIL_ALIASES = ["webmaster", "postmaster", "admin", "administrator", "hostmaster"] + VERIFICATION_EMAIL_ALIASES = ["webmaster", "postmaster", "admin", "administrator", "hostmaster"].freeze + VERIFICATION_METHODS = ["DNS", "Email"].freeze belongs_to :server, optional: true belongs_to :owner, optional: true, polymorphic: true has_many :routes, dependent: :destroy has_many :track_domains, dependent: :destroy - VERIFICATION_METHODS = ["DNS", "Email"] - validates :name, presence: true, format: { with: /\A[a-z0-9\-.]*\z/ }, uniqueness: { case_sensitive: false, scope: [:owner_type, :owner_id], message: "is already added" } validates :verification_method, inclusion: { in: VERIFICATION_METHODS } diff --git a/app/models/http_endpoint.rb b/app/models/http_endpoint.rb index a2e2faa..ff33a24 100644 --- a/app/models/http_endpoint.rb +++ b/app/models/http_endpoint.rb @@ -31,8 +31,8 @@ class HTTPEndpoint < ApplicationRecord has_many :routes, as: :endpoint has_many :additional_route_endpoints, dependent: :destroy, as: :endpoint - ENCODINGS = ["BodyAsJSON", "FormData"] - FORMATS = ["Hash", "RawMessage"] + ENCODINGS = ["BodyAsJSON", "FormData"].freeze + FORMATS = ["Hash", "RawMessage"].freeze before_destroy :update_routes diff --git a/app/models/organization.rb b/app/models/organization.rb index 0857822..57e16cd 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -25,7 +25,7 @@ class Organization < ApplicationRecord - RESERVED_PERMALINKS = ["new", "edit", "remove", "delete", "destroy", "admin", "mail", "org", "server"] + RESERVED_PERMALINKS = ["new", "edit", "remove", "delete", "destroy", "admin", "mail", "org", "server"].freeze INITIAL_QUOTA = 10 INITIAL_SUPER_QUOTA = 10_000 diff --git a/app/models/route.rb b/app/models/route.rb index 0561551..cd837d0 100644 --- a/app/models/route.rb +++ b/app/models/route.rb @@ -24,7 +24,9 @@ class Route < ApplicationRecord - MODES = ["Endpoint", "Accept", "Hold", "Bounce", "Reject"] + MODES = ["Endpoint", "Accept", "Hold", "Bounce", "Reject"].freeze + SPAM_MODES = ["Mark", "Quarantine", "Fail"].freeze + ENDPOINT_TYPES = ["SMTPEndpoint", "HTTPEndpoint", "AddressEndpoint"].freeze include HasUUID @@ -33,9 +35,6 @@ class Route < ApplicationRecord belongs_to :endpoint, polymorphic: true, optional: true has_many :additional_route_endpoints, dependent: :destroy - SPAM_MODES = ["Mark", "Quarantine", "Fail"] - ENDPOINT_TYPES = ["SMTPEndpoint", "HTTPEndpoint", "AddressEndpoint"] - validates :name, presence: true, format: /\A(([a-z0-9\-.]*)|(\*)|(__returnpath__))\z/ validates :spam_mode, inclusion: { in: SPAM_MODES } validates :endpoint, presence: { if: proc { mode == "Endpoint" } } diff --git a/app/models/server.rb b/app/models/server.rb index 33a72ca..c2f39a6 100644 --- a/app/models/server.rb +++ b/app/models/server.rb @@ -43,7 +43,8 @@ class Server < ApplicationRecord - RESERVED_PERMALINKS = ["new", "all", "search", "stats", "edit", "manage", "delete", "destroy", "remove"] + RESERVED_PERMALINKS = ["new", "all", "search", "stats", "edit", "manage", "delete", "destroy", "remove"].freeze + MODES = ["Live", "Development"].freeze include HasUUID include HasSoftDestroy @@ -64,8 +65,6 @@ class Server < ApplicationRecord has_many :track_domains, dependent: :destroy has_many :ip_pool_rules, dependent: :destroy, as: :owner - MODES = ["Live", "Development"] - random_string :token, type: :chars, length: 6, unique: true, upper_letters_only: true default_value :permalink, -> { name ? name.parameterize : nil } default_value :raw_message_retention_days, -> { 30 } diff --git a/app/models/smtp_endpoint.rb b/app/models/smtp_endpoint.rb index cda9dac..84c40aa 100644 --- a/app/models/smtp_endpoint.rb +++ b/app/models/smtp_endpoint.rb @@ -26,7 +26,7 @@ class SMTPEndpoint < ApplicationRecord has_many :routes, as: :endpoint has_many :additional_route_endpoints, dependent: :destroy, as: :endpoint - SSL_MODES = ["None", "Auto", "STARTTLS", "TLS"] + SSL_MODES = ["None", "Auto", "STARTTLS", "TLS"].freeze before_destroy :update_routes diff --git a/app/models/webhook_event.rb b/app/models/webhook_event.rb index a0a2236..a54da56 100644 --- a/app/models/webhook_event.rb +++ b/app/models/webhook_event.rb @@ -25,7 +25,7 @@ class WebhookEvent < ApplicationRecord "MessageLinkClicked", "MessageLoaded", "DomainDNSError" - ] + ].freeze belongs_to :webhook diff --git a/app/models/webhook_request.rb b/app/models/webhook_request.rb index 567c1bb..97d4b6f 100644 --- a/app/models/webhook_request.rb +++ b/app/models/webhook_request.rb @@ -21,7 +21,7 @@ class WebhookRequest < ApplicationRecord include HasUUID - RETRIES = { 1 => 2.minutes, 2 => 3.minutes, 3 => 6.minutes, 4 => 10.minutes, 5 => 15.minutes } + RETRIES = { 1 => 2.minutes, 2 => 3.minutes, 3 => 6.minutes, 4 => 10.minutes, 5 => 15.minutes }.freeze belongs_to :server belongs_to :webhook, optional: true diff --git a/lib/postal/app_logger.rb b/lib/postal/app_logger.rb index 98c6fa2..13fd044 100644 --- a/lib/postal/app_logger.rb +++ b/lib/postal/app_logger.rb @@ -45,8 +45,8 @@ module Postal class LogFormatter - TIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%3N".freeze - COLORS = [32, 34, 35, 31, 32, 33] + TIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%3N" + COLORS = [32, 34, 35, 31, 32, 33].freeze def call(severity, datetime, progname, msg) time = datetime.strftime(TIME_FORMAT) diff --git a/lib/postal/message_db/statistics.rb b/lib/postal/message_db/statistics.rb index 723a61c..d069bd2 100644 --- a/lib/postal/message_db/statistics.rb +++ b/lib/postal/message_db/statistics.rb @@ -8,8 +8,8 @@ module Postal @database = database end - STATS_GAPS = { hourly: :hour, daily: :day, monthly: :month, yearly: :year } - COUNTERS = [:incoming, :outgoing, :spam, :bounces, :held] + STATS_GAPS = { hourly: :hour, daily: :day, monthly: :month, yearly: :year }.freeze + COUNTERS = [:incoming, :outgoing, :spam, :bounces, :held].freeze # # Increment an appropriate counter diff --git a/lib/postal/message_inspectors/spam_assassin.rb b/lib/postal/message_inspectors/spam_assassin.rb index 24395e1..c3346bb 100644 --- a/lib/postal/message_inspectors/spam_assassin.rb +++ b/lib/postal/message_inspectors/spam_assassin.rb @@ -7,7 +7,7 @@ module Postal EXCLUSIONS = { outgoing: ["NO_RECEIVED", "NO_RELAYS", "ALL_TRUSTED", "FREEMAIL_FORGED_REPLYTO", "RDNS_DYNAMIC", "CK_HELO_GENERIC", /^SPF_/, /^HELO_/, /DKIM_/, /^RCVD_IN_/], incoming: [] - } + }.freeze def inspect_message(inspection) data = nil diff --git a/lib/postal/received_header.rb b/lib/postal/received_header.rb index a3fe372..a9bec15 100644 --- a/lib/postal/received_header.rb +++ b/lib/postal/received_header.rb @@ -6,7 +6,7 @@ module Postal OUR_HOSTNAMES = { smtp: Postal.config.dns.smtp_server_hostname, http: Postal.config.web.host - } + }.freeze class << self diff --git a/lib/postal/reply_separator.rb b/lib/postal/reply_separator.rb index 9f6d416..30726bd 100644 --- a/lib/postal/reply_separator.rb +++ b/lib/postal/reply_separator.rb @@ -15,7 +15,7 @@ module Postal /^>*\s*Sent from my.*/m, /^>*\s*=== Please reply above this line ===.*/m, /(^>.*\n?){10,}/ - ] + ].freeze def self.separate(text) return "" unless text.is_a?(String)