مراية لـ
https://github.com/postalserver/postal.git
تم المزامنة 2025-11-30 21:32:30 +00:00
style(rubocop): remaining offences
هذا الالتزام موجود في:
2
Gemfile
2
Gemfile
@@ -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"
|
||||
|
||||
@@ -94,11 +94,11 @@ class UnqueueMessageJob < Postal::Job
|
||||
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
|
||||
|
||||
@@ -44,19 +44,4 @@ module HasAuthentication
|
||||
|
||||
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
|
||||
|
||||
@@ -85,7 +85,7 @@ class Domain < ApplicationRecord
|
||||
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
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
# frozen_string_literal: true
|
||||
# Seeds go here...
|
||||
|
||||
@@ -11,8 +11,10 @@ require_relative "version"
|
||||
|
||||
module Postal
|
||||
|
||||
# rubocop:disable Lint/EmptyClass
|
||||
class Config
|
||||
end
|
||||
# rubocop:enable Lint/EmptyClass
|
||||
|
||||
def self.host
|
||||
@host ||= config.web.host || "localhost:5000"
|
||||
|
||||
@@ -34,14 +34,14 @@ module Postal
|
||||
|
||||
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
|
||||
|
||||
@@ -2,10 +2,24 @@
|
||||
|
||||
module Postal
|
||||
|
||||
module Errors
|
||||
end
|
||||
|
||||
class Error < StandardError
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
@@ -27,7 +27,7 @@ module Postal
|
||||
|
||||
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]
|
||||
|
||||
@@ -295,9 +295,7 @@ module Postal
|
||||
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)
|
||||
|
||||
@@ -61,6 +61,7 @@ module Postal
|
||||
}
|
||||
end
|
||||
|
||||
# rubocop:disable Style/HashLikeCase
|
||||
def webhook_event
|
||||
@webhook_event ||= case status
|
||||
when "Sent" then "MessageSent"
|
||||
@@ -69,6 +70,7 @@ module Postal
|
||||
when "Held" then "MessageHeld"
|
||||
end
|
||||
end
|
||||
# rubocop:enable Style/HashLikeCase
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -32,7 +32,7 @@ module Postal
|
||||
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
|
||||
|
||||
@@ -56,7 +56,7 @@ module Postal
|
||||
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]
|
||||
|
||||
|
||||
@@ -63,15 +63,16 @@ module Postal
|
||||
|
||||
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
|
||||
|
||||
@@ -65,8 +65,6 @@ module Postal
|
||||
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)
|
||||
|
||||
@@ -309,7 +309,7 @@ module Postal
|
||||
"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
|
||||
@@ -415,7 +415,7 @@ module Postal
|
||||
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
|
||||
|
||||
@@ -39,7 +39,7 @@ module Postal
|
||||
@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
|
||||
|
||||
@@ -6,7 +6,7 @@ trap("INT") do
|
||||
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
|
||||
|
||||
@@ -34,7 +34,10 @@ RSpec.configure do |config|
|
||||
# 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
|
||||
|
||||
المرجع في مشكلة جديدة
حظر مستخدم