Fix non-idiomatic Ruby

Fix non-idiomatic Ruby

From 15268f58de57a04619ed96693e06537f445ed774 Mon Sep 17 00:00:00 2001
From: Saj Goonatilleke <saj@discourse.org>
Date: Thu, 29 Nov 2018 14:16:41 +1100
Subject: [PATCH] Fix non-idiomatic Ruby


diff --git a/lib/mail_receiver/fast_rejection.rb b/lib/mail_receiver/fast_rejection.rb
index 9b419d6..bd482f0 100644
--- a/lib/mail_receiver/fast_rejection.rb
+++ b/lib/mail_receiver/fast_rejection.rb
@@ -1,3 +1,4 @@
+require 'set'
 require 'syslog'
 require 'json'
 require 'uri'
@@ -14,9 +15,7 @@ class FastRejection < MailReceiverBase
 
 		@disabled = @env['DISCOURSE_FAST_REJECTION_DISABLED'] || !@env['DISCOURSE_BASE_URL']
 
-		@blacklisted_sender_domains = Hash[
-			@env.fetch('BLACKLISTED_SENDER_DOMAINS', "").split(" ").map { |v| [v.downcase, nil] }
-		]
+		@blacklisted_sender_domains = @env.fetch('BLACKLISTED_SENDER_DOMAINS', "").split(" ").map(&:downcase).to_set
 	end
 
 	def disabled?
@@ -60,7 +59,7 @@ class FastRejection < MailReceiverBase
 			logger.info("deferred mail with domainless sender #{args['sender']}")
 			return 'defer_if_permit Invalid sender'
 		end
-		if @blacklisted_sender_domains.key? domain
+		if @blacklisted_sender_domains.include? domain
 			logger.info("rejected mail from blacklisted sender domain #{domain} (from #{args['sender']})")
 			return 'reject Invalid sender'
 		end
diff --git a/lib/mail_receiver/mail.rb b/lib/mail_receiver/mail.rb
index c8e9cb7..6e78031 100644
--- a/lib/mail_receiver/mail.rb
+++ b/lib/mail_receiver/mail.rb
@@ -6,5 +6,5 @@
 #
 # See section 3.4 of RFC 2822.
 def domain_from_addrspec(addrspec)
-	(addrspec.split("@", 2)[1] or "").downcase
+	(addrspec.split("@", 2)[1] || "").downcase
 end

GitHub

1 Like