Skip to content

Commit

Permalink
style(rubocop): Lint/ShadowingOuterLocalVariable
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcooke committed Feb 10, 2024
1 parent bd85920 commit 7119e86
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 52 deletions.
21 changes: 6 additions & 15 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,6 @@ Lint/BooleanSymbol:
Style/SymbolProc:
Enabled: false

# Excluding specs from block lengths
Metrics/BlockLength:
Exclude:
- "spec/**/*.rb"
- "db/schema.rb"
- "db/migrate/**/*.rb"
- "lib/tasks/auto_annotate_models.rake"
- "config/routes.rb"
- "lib/tasks/*.rake"
- "app/apis/core_api/base.rb"

Metrics/ModuleLength:
Exclude:
- "spec/factories/**/*.rb"
Expand All @@ -150,10 +139,6 @@ Style/MultilineBlockChain:
Exclude:
- "spec/**/*.rb"

# Increase class lengths to a more reasonable place
Metrics/ClassLength:
Max: 250

Metrics/AbcSize:
Enabled: false

Expand Down Expand Up @@ -188,3 +173,9 @@ Metrics/BlockNesting:

Style/StringConcatenation:
Enabled: false

Metrics/BlockLength:
Enabled: false

Metrics/ClassLength:
Enabled: false
2 changes: 1 addition & 1 deletion app/jobs/send_webhook_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def perform
if server = Server.find(params["server_id"])
new_items = {}
if params["payload"]
for key, value in params["payload"]
params["payload"].each do |key, value|
next unless key.to_s =~ /\A_(\w+)/

begin
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/unqueue_message_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def perform
end
rescue StandardError => e
log "#{log_prefix} Internal error: #{e.class}: #{e.message}"
e.backtrace.each { |e| log("#{log_prefix} #{e}") }
e.backtrace.each { |line| log("#{log_prefix} #{line}") }
queued_message.retry_later
log "#{log_prefix} Queued message was unlocked"
if defined?(Sentry)
Expand Down
16 changes: 8 additions & 8 deletions lib/postal/message_db/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def insert_multi(table, keys, values)
sql_query = "INSERT INTO `#{database_name}`.`#{table}`"
sql_query << (" (" + keys.map { |k| "`#{k}`" }.join(", ") + ")")
sql_query << " VALUES "
sql_query << values.map { |v| "(" + v.map { |v| escape(v) }.join(", ") + ")" }.join(", ")
sql_query << values.map { |v| "(" + v.map { |r| escape(r) }.join(", ") + ")" }.join(", ")
query(sql_query)
end
end
Expand Down Expand Up @@ -295,8 +295,8 @@ def initialize(result)
end

def stringify_keys(hash)
hash.each_with_object({}) do |(key, value), hash|
hash[key.to_s] = value
hash.each_with_object({}) do |(key, value), h|
h[key.to_s] = value
end
end

Expand Down Expand Up @@ -365,16 +365,16 @@ def hash_to_sql(hash, joiner = ", ")
"`#{key}` IN (#{escaped_values})"
elsif value.is_a?(Hash)
sql = []
value.each do |operator, value|
value.each do |operator, inner_value|
case operator
when :less_than
sql << "`#{key}` < #{escape(value)}"
sql << "`#{key}` < #{escape(inner_value)}"
when :greater_than
sql << "`#{key}` > #{escape(value)}"
sql << "`#{key}` > #{escape(inner_value)}"
when :less_than_or_equal_to
sql << "`#{key}` <= #{escape(value)}"
sql << "`#{key}` <= #{escape(inner_value)}"
when :greater_than_or_equal_to
sql << "`#{key}` >= #{escape(value)}"
sql << "`#{key}` >= #{escape(inner_value)}"
end
end
sql.empty? ? "1=1" : sql.join(joiner)
Expand Down
44 changes: 22 additions & 22 deletions lib/postal/smtp_server/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module SMTPServer
class Client

CRAM_MD5_DIGEST = OpenSSL::Digest.new("md5")
LOG_REDACTION_STRING = "[redacted]".freeze
LOG_REDACTION_STRING = "[redacted]"

attr_reader :logging_enabled

Expand Down Expand Up @@ -158,10 +158,10 @@ def noop
end

def auth_plain(data)
handler = proc do |data|
handler = proc do |idata|
@proc = nil
data = Base64.decode64(data)
parts = data.split("\0")
idata = Base64.decode64(idata)
parts = idata.split("\0")
username = parts[-2]
password = parts[-1]
unless username && password
Expand All @@ -182,9 +182,9 @@ def auth_plain(data)
end

def auth_login(data)
password_handler = proc do |data|
password_handler = proc do |idata|
@proc = nil
password = Base64.decode64(data)
password = Base64.decode64(idata)
authenticate(password)
end

Expand Down Expand Up @@ -217,9 +217,9 @@ def auth_cram_md5(data)
challenge = Digest::SHA1.hexdigest(Time.now.to_i.to_s + rand(100_000).to_s)
challenge = "<#{challenge[0, 20]}@#{Postal.config.dns.smtp_server_hostname}>"

handler = proc do |data|
handler = proc do |idata|
@proc = nil
username, password = Base64.decode64(data).split(" ", 2).map { |a| a.chomp }
username, password = Base64.decode64(idata).split(" ", 2).map { |a| a.chomp }
org_permlink, server_permalink = username.split(/[\/_]/, 2)
server = ::Server.includes(:organization).where(organizations: { permalink: org_permlink }, permalink: server_permalink).first
if server.nil?
Expand Down Expand Up @@ -357,7 +357,7 @@ def rcpt_to(data)
end
end

def data(data)
def data(_data)
unless in_state(:rcpt_to_received)
return "503 HELO/EHLO, MAIL FROM and RCPT TO before sending data"
end
Expand All @@ -372,13 +372,13 @@ def data(data)
@data << "Received: #{received_header}\r\n"
@headers["received"] = [received_header]

handler = proc do |data|
if data == "."
handler = proc do |idata|
if idata == "."
@logging_enabled = true
@proc = nil
finished
else
data = data.to_s.sub(/\A\.\./, ".")
idata = idata.to_s.sub(/\A\.\./, ".")

if @credential && @credential.server.log_smtp_data?
# We want to log if enabled
Expand All @@ -388,20 +388,20 @@ def data(data)
end

if @receiving_headers
if data.blank?
if idata.blank?
@receiving_headers = false
elsif data.to_s =~ /^\s/
elsif idata.to_s =~ /^\s/
# This is a continuation of a header
if @header_key && @headers[@header_key.downcase] && @headers[@header_key.downcase].last
@headers[@header_key.downcase].last << data.to_s
@headers[@header_key.downcase].last << idata.to_s
end
else
@header_key, value = data.split(/:\s*/, 2)
@header_key, value = idata.split(/:\s*/, 2)
@headers[@header_key.downcase] ||= []
@headers[@header_key.downcase] << value
end
end
@data << data
@data << idata
@data << "\r\n"
nil
end
Expand Down Expand Up @@ -453,11 +453,11 @@ def finished
when :bounce
if rp_route = server.routes.where(name: "__returnpath__").first
# If there's a return path route, we can use this to create the message
rp_route.create_messages do |message|
message.rcpt_to = rcpt_to
message.mail_from = @mail_from
message.raw_message = @data
message.received_with_ssl = @tls
rp_route.create_messages do |msg|
msg.rcpt_to = rcpt_to
msg.mail_from = @mail_from
msg.raw_message = @data
msg.received_with_ssl = @tls
end
else
# There's no return path route, we just need to insert the mesage
Expand Down
10 changes: 5 additions & 5 deletions lib/postal/smtp_server/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ def run_event_loop
next if result.nil?

result = [result] unless result.is_a?(Array)
result.compact.each do |line|
client.log "\e[34m=> #{line.strip}\e[0m"
result.compact.each do |iline|
client.log "\e[34m=> #{iline.strip}\e[0m"
begin
io.write(line.to_s + "\r\n")
io.write(iline.to_s + "\r\n")
io.flush
rescue Errno::ECONNRESET
# Client disconnected before we could write response
Expand Down Expand Up @@ -238,8 +238,8 @@ def run_event_loop
end
logger.error "[#{client_id}] An error occurred while processing data from a client."
logger.error "[#{client_id}] #{e.class}: #{e.message}"
e.backtrace.each do |line|
logger.error "[#{client_id}] #{line}"
e.backtrace.each do |iline|
logger.error "[#{client_id}] #{iline}"
end
# Close all IO and forget this client
begin
Expand Down

0 comments on commit 7119e86

Please sign in to comment.