مراية لـ
https://github.com/postalserver/postal.git
تم المزامنة 2025-12-01 05:43:04 +00:00
style(rubocop): Lint/ShadowingOuterLocalVariable
هذا الالتزام موجود في:
21
.rubocop.yml
21
.rubocop.yml
@@ -118,17 +118,6 @@ Lint/BooleanSymbol:
|
|||||||
Style/SymbolProc:
|
Style/SymbolProc:
|
||||||
Enabled: false
|
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:
|
Metrics/ModuleLength:
|
||||||
Exclude:
|
Exclude:
|
||||||
- "spec/factories/**/*.rb"
|
- "spec/factories/**/*.rb"
|
||||||
@@ -150,10 +139,6 @@ Style/MultilineBlockChain:
|
|||||||
Exclude:
|
Exclude:
|
||||||
- "spec/**/*.rb"
|
- "spec/**/*.rb"
|
||||||
|
|
||||||
# Increase class lengths to a more reasonable place
|
|
||||||
Metrics/ClassLength:
|
|
||||||
Max: 250
|
|
||||||
|
|
||||||
Metrics/AbcSize:
|
Metrics/AbcSize:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
@@ -188,3 +173,9 @@ Metrics/BlockNesting:
|
|||||||
|
|
||||||
Style/StringConcatenation:
|
Style/StringConcatenation:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
|
Metrics/BlockLength:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
Metrics/ClassLength:
|
||||||
|
Enabled: false
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ class SendWebhookJob < Postal::Job
|
|||||||
if server = Server.find(params["server_id"])
|
if server = Server.find(params["server_id"])
|
||||||
new_items = {}
|
new_items = {}
|
||||||
if params["payload"]
|
if params["payload"]
|
||||||
for key, value in params["payload"]
|
params["payload"].each do |key, value|
|
||||||
next unless key.to_s =~ /\A_(\w+)/
|
next unless key.to_s =~ /\A_(\w+)/
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
|||||||
@@ -424,7 +424,7 @@ class UnqueueMessageJob < Postal::Job
|
|||||||
end
|
end
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
log "#{log_prefix} Internal error: #{e.class}: #{e.message}"
|
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
|
queued_message.retry_later
|
||||||
log "#{log_prefix} Queued message was unlocked"
|
log "#{log_prefix} Queued message was unlocked"
|
||||||
if defined?(Sentry)
|
if defined?(Sentry)
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ module Postal
|
|||||||
sql_query = "INSERT INTO `#{database_name}`.`#{table}`"
|
sql_query = "INSERT INTO `#{database_name}`.`#{table}`"
|
||||||
sql_query << (" (" + keys.map { |k| "`#{k}`" }.join(", ") + ")")
|
sql_query << (" (" + keys.map { |k| "`#{k}`" }.join(", ") + ")")
|
||||||
sql_query << " VALUES "
|
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)
|
query(sql_query)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -295,8 +295,8 @@ module Postal
|
|||||||
end
|
end
|
||||||
|
|
||||||
def stringify_keys(hash)
|
def stringify_keys(hash)
|
||||||
hash.each_with_object({}) do |(key, value), hash|
|
hash.each_with_object({}) do |(key, value), h|
|
||||||
hash[key.to_s] = value
|
h[key.to_s] = value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -365,16 +365,16 @@ module Postal
|
|||||||
"`#{key}` IN (#{escaped_values})"
|
"`#{key}` IN (#{escaped_values})"
|
||||||
elsif value.is_a?(Hash)
|
elsif value.is_a?(Hash)
|
||||||
sql = []
|
sql = []
|
||||||
value.each do |operator, value|
|
value.each do |operator, inner_value|
|
||||||
case operator
|
case operator
|
||||||
when :less_than
|
when :less_than
|
||||||
sql << "`#{key}` < #{escape(value)}"
|
sql << "`#{key}` < #{escape(inner_value)}"
|
||||||
when :greater_than
|
when :greater_than
|
||||||
sql << "`#{key}` > #{escape(value)}"
|
sql << "`#{key}` > #{escape(inner_value)}"
|
||||||
when :less_than_or_equal_to
|
when :less_than_or_equal_to
|
||||||
sql << "`#{key}` <= #{escape(value)}"
|
sql << "`#{key}` <= #{escape(inner_value)}"
|
||||||
when :greater_than_or_equal_to
|
when :greater_than_or_equal_to
|
||||||
sql << "`#{key}` >= #{escape(value)}"
|
sql << "`#{key}` >= #{escape(inner_value)}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
sql.empty? ? "1=1" : sql.join(joiner)
|
sql.empty? ? "1=1" : sql.join(joiner)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ module Postal
|
|||||||
class Client
|
class Client
|
||||||
|
|
||||||
CRAM_MD5_DIGEST = OpenSSL::Digest.new("md5")
|
CRAM_MD5_DIGEST = OpenSSL::Digest.new("md5")
|
||||||
LOG_REDACTION_STRING = "[redacted]".freeze
|
LOG_REDACTION_STRING = "[redacted]"
|
||||||
|
|
||||||
attr_reader :logging_enabled
|
attr_reader :logging_enabled
|
||||||
|
|
||||||
@@ -158,10 +158,10 @@ module Postal
|
|||||||
end
|
end
|
||||||
|
|
||||||
def auth_plain(data)
|
def auth_plain(data)
|
||||||
handler = proc do |data|
|
handler = proc do |idata|
|
||||||
@proc = nil
|
@proc = nil
|
||||||
data = Base64.decode64(data)
|
idata = Base64.decode64(idata)
|
||||||
parts = data.split("\0")
|
parts = idata.split("\0")
|
||||||
username = parts[-2]
|
username = parts[-2]
|
||||||
password = parts[-1]
|
password = parts[-1]
|
||||||
unless username && password
|
unless username && password
|
||||||
@@ -182,9 +182,9 @@ module Postal
|
|||||||
end
|
end
|
||||||
|
|
||||||
def auth_login(data)
|
def auth_login(data)
|
||||||
password_handler = proc do |data|
|
password_handler = proc do |idata|
|
||||||
@proc = nil
|
@proc = nil
|
||||||
password = Base64.decode64(data)
|
password = Base64.decode64(idata)
|
||||||
authenticate(password)
|
authenticate(password)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -217,9 +217,9 @@ module Postal
|
|||||||
challenge = Digest::SHA1.hexdigest(Time.now.to_i.to_s + rand(100_000).to_s)
|
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}>"
|
challenge = "<#{challenge[0, 20]}@#{Postal.config.dns.smtp_server_hostname}>"
|
||||||
|
|
||||||
handler = proc do |data|
|
handler = proc do |idata|
|
||||||
@proc = nil
|
@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)
|
org_permlink, server_permalink = username.split(/[\/_]/, 2)
|
||||||
server = ::Server.includes(:organization).where(organizations: { permalink: org_permlink }, permalink: server_permalink).first
|
server = ::Server.includes(:organization).where(organizations: { permalink: org_permlink }, permalink: server_permalink).first
|
||||||
if server.nil?
|
if server.nil?
|
||||||
@@ -357,7 +357,7 @@ module Postal
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def data(data)
|
def data(_data)
|
||||||
unless in_state(:rcpt_to_received)
|
unless in_state(:rcpt_to_received)
|
||||||
return "503 HELO/EHLO, MAIL FROM and RCPT TO before sending data"
|
return "503 HELO/EHLO, MAIL FROM and RCPT TO before sending data"
|
||||||
end
|
end
|
||||||
@@ -372,13 +372,13 @@ module Postal
|
|||||||
@data << "Received: #{received_header}\r\n"
|
@data << "Received: #{received_header}\r\n"
|
||||||
@headers["received"] = [received_header]
|
@headers["received"] = [received_header]
|
||||||
|
|
||||||
handler = proc do |data|
|
handler = proc do |idata|
|
||||||
if data == "."
|
if idata == "."
|
||||||
@logging_enabled = true
|
@logging_enabled = true
|
||||||
@proc = nil
|
@proc = nil
|
||||||
finished
|
finished
|
||||||
else
|
else
|
||||||
data = data.to_s.sub(/\A\.\./, ".")
|
idata = idata.to_s.sub(/\A\.\./, ".")
|
||||||
|
|
||||||
if @credential && @credential.server.log_smtp_data?
|
if @credential && @credential.server.log_smtp_data?
|
||||||
# We want to log if enabled
|
# We want to log if enabled
|
||||||
@@ -388,20 +388,20 @@ module Postal
|
|||||||
end
|
end
|
||||||
|
|
||||||
if @receiving_headers
|
if @receiving_headers
|
||||||
if data.blank?
|
if idata.blank?
|
||||||
@receiving_headers = false
|
@receiving_headers = false
|
||||||
elsif data.to_s =~ /^\s/
|
elsif idata.to_s =~ /^\s/
|
||||||
# This is a continuation of a header
|
# This is a continuation of a header
|
||||||
if @header_key && @headers[@header_key.downcase] && @headers[@header_key.downcase].last
|
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
|
end
|
||||||
else
|
else
|
||||||
@header_key, value = data.split(/:\s*/, 2)
|
@header_key, value = idata.split(/:\s*/, 2)
|
||||||
@headers[@header_key.downcase] ||= []
|
@headers[@header_key.downcase] ||= []
|
||||||
@headers[@header_key.downcase] << value
|
@headers[@header_key.downcase] << value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@data << data
|
@data << idata
|
||||||
@data << "\r\n"
|
@data << "\r\n"
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
@@ -453,11 +453,11 @@ module Postal
|
|||||||
when :bounce
|
when :bounce
|
||||||
if rp_route = server.routes.where(name: "__returnpath__").first
|
if rp_route = server.routes.where(name: "__returnpath__").first
|
||||||
# If there's a return path route, we can use this to create the message
|
# If there's a return path route, we can use this to create the message
|
||||||
rp_route.create_messages do |message|
|
rp_route.create_messages do |msg|
|
||||||
message.rcpt_to = rcpt_to
|
msg.rcpt_to = rcpt_to
|
||||||
message.mail_from = @mail_from
|
msg.mail_from = @mail_from
|
||||||
message.raw_message = @data
|
msg.raw_message = @data
|
||||||
message.received_with_ssl = @tls
|
msg.received_with_ssl = @tls
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
# There's no return path route, we just need to insert the mesage
|
# There's no return path route, we just need to insert the mesage
|
||||||
|
|||||||
@@ -188,10 +188,10 @@ module Postal
|
|||||||
next if result.nil?
|
next if result.nil?
|
||||||
|
|
||||||
result = [result] unless result.is_a?(Array)
|
result = [result] unless result.is_a?(Array)
|
||||||
result.compact.each do |line|
|
result.compact.each do |iline|
|
||||||
client.log "\e[34m=> #{line.strip}\e[0m"
|
client.log "\e[34m=> #{iline.strip}\e[0m"
|
||||||
begin
|
begin
|
||||||
io.write(line.to_s + "\r\n")
|
io.write(iline.to_s + "\r\n")
|
||||||
io.flush
|
io.flush
|
||||||
rescue Errno::ECONNRESET
|
rescue Errno::ECONNRESET
|
||||||
# Client disconnected before we could write response
|
# Client disconnected before we could write response
|
||||||
@@ -238,8 +238,8 @@ module Postal
|
|||||||
end
|
end
|
||||||
logger.error "[#{client_id}] An error occurred while processing data from a client."
|
logger.error "[#{client_id}] An error occurred while processing data from a client."
|
||||||
logger.error "[#{client_id}] #{e.class}: #{e.message}"
|
logger.error "[#{client_id}] #{e.class}: #{e.message}"
|
||||||
e.backtrace.each do |line|
|
e.backtrace.each do |iline|
|
||||||
logger.error "[#{client_id}] #{line}"
|
logger.error "[#{client_id}] #{iline}"
|
||||||
end
|
end
|
||||||
# Close all IO and forget this client
|
# Close all IO and forget this client
|
||||||
begin
|
begin
|
||||||
|
|||||||
المرجع في مشكلة جديدة
حظر مستخدم