Skip to content

Commit

Permalink
style(rubocop): remaining offences
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcooke committed Feb 12, 2024
1 parent c6326a6 commit ec63666
Show file tree
Hide file tree
Showing 19 changed files with 48 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ gem "clockwork"
gem "dotenv-rails"
gem "dynamic_form"
gem "encrypto_signo"
gem "execjs", "~> 2.7", "< 2.8"
gem "foreman"
gem "gelf"
gem "haml"
gem "hashie"
gem "highline", require: false
gem "execjs", "~> 2.7", "< 2.8"
gem "jwt"
gem "kaminari"
gem "mail"
Expand Down
10 changes: 5 additions & 5 deletions app/jobs/unqueue_message_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ def perform
log "#{log_prefix} Message is a bounce"
original_messages = queued_message.message.original_messages
unless original_messages.empty?
queued_message.message.original_messages.each do |original_message|
queued_message.message.update(bounce_for_id: original_message.id, domain_id: original_message.domain_id)
queued_message.message.create_delivery("Processed", details: "This has been detected as a bounce message for <msg:#{original_message.id}>.")
original_message.bounce!(queued_message.message)
log "#{log_prefix} Bounce linked with message #{original_message.id}"
queued_message.message.original_messages.each do |orig_msg|
queued_message.message.update(bounce_for_id: orig_msg.id, domain_id: orig_msg.domain_id)
queued_message.message.create_delivery("Processed", details: "This has been detected as a bounce message for <msg:#{orig_msg.id}>.")
orig_msg.bounce!(queued_message.message)
log "#{log_prefix} Bounce linked with message #{orig_msg.id}"
end
queued_message.destroy
next
Expand Down
15 changes: 0 additions & 15 deletions app/models/concerns/has_authentication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,4 @@ def begin_password_reset(return_to = nil)

end

class Postal::Errors::AuthenticationError < Postal::Error

attr_reader :error

def initialize(error)
super()
@error = error
end

def to_s
"Authentication Failed: #{@error}"
end

end

# -*- SkipSchemaAnnotations
2 changes: 1 addition & 1 deletion app/models/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def verify
def parent_domains
parts = name.split(".")
parts[0, parts.size - 1].each_with_index.map do |_, i|
parts[i..-1].join(".")
parts[i..].join(".")
end
end

Expand Down
2 changes: 2 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# frozen_string_literal: true
# Seeds go here...
2 changes: 2 additions & 0 deletions lib/postal/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@

module Postal

# rubocop:disable Lint/EmptyClass
class Config
end
# rubocop:enable Lint/EmptyClass

def self.host
@host ||= config.web.host || "localhost:5000"
Expand Down
8 changes: 4 additions & 4 deletions lib/postal/dkim_header.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ def header_names

def normalized_headers
[].tap do |new_headers|
dkim_headers = headers.select { |h|
h.match(%r{
dkim_headers = headers.select do |h|
h.match(/
^(
from|sender|reply-to|subject|date|message-id|to|cc|mime-version|content-type|content-transfer-encoding|
resent-to|resent-cc|resent-from|resent-sender|resent-message-id|in-reply-to|references|list-id|list-help|
list-owner|list-unsubscribe|list-subscribe|list-post
):}ix)
}
):/ix)
end
dkim_headers.each do |h|
new_headers << normalize_header(h)
end
Expand Down
18 changes: 16 additions & 2 deletions lib/postal/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@

module Postal

module Errors
class Error < StandardError
end

class Error < StandardError
module Errors
class AuthenticationError < Error

attr_reader :error

def initialize(error)
super()
@error = error
end

def to_s
"Authentication Failed: #{@error}"
end

end
end

end
2 changes: 1 addition & 1 deletion lib/postal/http_sender.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def send_message(message)

log "Sending request to #{@endpoint.url}"
response = Postal::HTTP.post(@endpoint.url, request_options)
result.secure = !!response[:secure]
result.secure = !!response[:secure] # rubocop:disable Style/DoubleNegation
result.details = "Received a #{response[:code]} from #{@endpoint.url}"
log " -> Received: #{response[:code]}"
if response[:body]
Expand Down
4 changes: 1 addition & 3 deletions lib/postal/message_db/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,7 @@ def initialize(result)
end

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

def escape(value)
Expand Down
2 changes: 2 additions & 0 deletions lib/postal/message_db/delivery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def webhook_hash
}
end

# rubocop:disable Style/HashLikeCase
def webhook_event
@webhook_event ||= case status
when "Sent" then "MessageSent"
Expand All @@ -69,6 +70,7 @@ def webhook_event
when "Held" then "MessageHeld"
end
end
# rubocop:enable Style/HashLikeCase

end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/postal/message_db/live_stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def total(minutes, options = {})
raise Postal::Error, "You must provide at least one type to return" if options[:types].empty?

time = minutes.minutes.ago.beginning_of_minute.utc.to_f
types = options[:types].map { |t| "#{@database.escape(t.to_s)}" }.join(", ")
types = options[:types].map { |t| @database.escape(t.to_s) }.join(", ")
result = @database.query("SELECT SUM(count) as count FROM `#{@database.database_name}`.`live_stats` WHERE `type` IN (#{types}) AND timestamp > #{time}").first
result["count"] || 0
end
Expand Down
2 changes: 1 addition & 1 deletion lib/postal/message_inspectors/rspamd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def request(message, scope)
response = nil
begin
response = http.request(request)
rescue Exception => e
rescue StandardError => e
logger.error "Error talking to rspamd: #{e.class} (#{e.message})"
logger.error e.backtrace[0, 5]

Expand Down
7 changes: 4 additions & 3 deletions lib/postal/message_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,16 @@ def generate

def parse_parts(parts)
parts.each do |part|
if part.content_type =~ /text\/html/
case part.content_type
when /text\/html/
part.body = parse(part.body.decoded.dup, :html)
part.content_transfer_encoding = nil
part.charset = "UTF-8"
elsif part.content_type =~ /text\/plain/
when /text\/plain/
part.body = parse(part.body.decoded.dup, :text)
part.content_transfer_encoding = nil
part.charset = "UTF-8"
elsif part.content_type =~ /multipart\/(alternative|related)/
when /multipart\/(alternative|related)/
unless part.parts.empty?
parse_parts(part.parts)
end
Expand Down
2 changes: 0 additions & 2 deletions lib/postal/smtp_sender.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ def start
smtp_client.enable_starttls(self.class.ssl_context_with_verify)
when "TLS"
smtp_client.enable_tls(self.class.ssl_context_with_verify)
else
# Nothing
end

smtp_client.start(@source_ip_address ? @source_ip_address.hostname : self.class.default_helo_hostname)
Expand Down
4 changes: 2 additions & 2 deletions lib/postal/smtp_server/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def rcpt_to(data)
"550 Route does not accept incoming messages"
else
log "Added route #{route.id} to recipients (tag: #{tag.inspect})"
actual_rcpt_to = "#{route.name}" + (tag ? "+#{tag}" : "") + "@#{route.domain.name}"
actual_rcpt_to = "#{route.name}#{tag ? "+#{tag}" : ''}@#{route.domain.name}"
@recipients << [:route, actual_rcpt_to, route.server, { route: route }]
"250 OK"
end
Expand Down Expand Up @@ -415,7 +415,7 @@ def finished
if @data.bytesize > Postal.config.smtp_server.max_message_size.megabytes.to_i
transaction_reset
@state = :welcomed
return "552 Message too large (maximum size %dMB)" % Postal.config.smtp_server.max_message_size
return format("552 Message too large (maximum size %dMB)", Postal.config.smtp_server.max_message_size)
end

if @headers["received"].grep(/by #{Postal.config.dns.smtp_server_hostname}/).count > 4
Expand Down
2 changes: 1 addition & 1 deletion lib/postal/smtp_server/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def ssl_context
@ssl_context ||= begin
ssl_context = OpenSSL::SSL::SSLContext.new
ssl_context.cert = Postal.smtp_certificates[0]
ssl_context.extra_chain_cert = Postal.smtp_certificates[1..-1]
ssl_context.extra_chain_cert = Postal.smtp_certificates[1..]
ssl_context.key = Postal.smtp_private_key
ssl_context.ssl_version = Postal.config.smtp_server.ssl_version if Postal.config.smtp_server.ssl_version
ssl_context.ciphers = Postal.config.smtp_server.tls_ciphers if Postal.config.smtp_server.tls_ciphers
Expand Down
2 changes: 1 addition & 1 deletion script/test_app_smtp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
exit
end

if ARGV[0].nil? || !(ARGV[0] =~ /@/)
if ARGV[0].nil? || ARGV[0] !~ /@/
puts "usage: postal test-app-smtp [email address]"
exit 1
end
Expand Down
3 changes: 3 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
# Because the mail databases don't use any transactions, all data left in the
# database will be left there unless removed.
DatabaseCleaner.start

# rubocop:disable Lint/ConstantDefinitionInBlock
GLOBAL_SERVER = FactoryBot.create(:server, provision_database: true)
# rubocop:enable Lint/ConstantDefinitionInBlock
end

config.after(:suite) do
Expand Down

0 comments on commit ec63666

Please sign in to comment.