مراية لـ
https://github.com/postalserver/postal.git
تم المزامنة 2025-12-01 05:43:04 +00:00
style(rubocop): remaining offences
هذا الالتزام موجود في:
2
Gemfile
2
Gemfile
@@ -12,12 +12,12 @@ gem "clockwork"
|
|||||||
gem "dotenv-rails"
|
gem "dotenv-rails"
|
||||||
gem "dynamic_form"
|
gem "dynamic_form"
|
||||||
gem "encrypto_signo"
|
gem "encrypto_signo"
|
||||||
|
gem "execjs", "~> 2.7", "< 2.8"
|
||||||
gem "foreman"
|
gem "foreman"
|
||||||
gem "gelf"
|
gem "gelf"
|
||||||
gem "haml"
|
gem "haml"
|
||||||
gem "hashie"
|
gem "hashie"
|
||||||
gem "highline", require: false
|
gem "highline", require: false
|
||||||
gem "execjs", "~> 2.7", "< 2.8"
|
|
||||||
gem "jwt"
|
gem "jwt"
|
||||||
gem "kaminari"
|
gem "kaminari"
|
||||||
gem "mail"
|
gem "mail"
|
||||||
|
|||||||
@@ -94,11 +94,11 @@ class UnqueueMessageJob < Postal::Job
|
|||||||
log "#{log_prefix} Message is a bounce"
|
log "#{log_prefix} Message is a bounce"
|
||||||
original_messages = queued_message.message.original_messages
|
original_messages = queued_message.message.original_messages
|
||||||
unless original_messages.empty?
|
unless original_messages.empty?
|
||||||
queued_message.message.original_messages.each do |original_message|
|
queued_message.message.original_messages.each do |orig_msg|
|
||||||
queued_message.message.update(bounce_for_id: original_message.id, domain_id: original_message.domain_id)
|
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:#{original_message.id}>.")
|
queued_message.message.create_delivery("Processed", details: "This has been detected as a bounce message for <msg:#{orig_msg.id}>.")
|
||||||
original_message.bounce!(queued_message.message)
|
orig_msg.bounce!(queued_message.message)
|
||||||
log "#{log_prefix} Bounce linked with message #{original_message.id}"
|
log "#{log_prefix} Bounce linked with message #{orig_msg.id}"
|
||||||
end
|
end
|
||||||
queued_message.destroy
|
queued_message.destroy
|
||||||
next
|
next
|
||||||
|
|||||||
@@ -44,19 +44,4 @@ module HasAuthentication
|
|||||||
|
|
||||||
end
|
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
|
# -*- SkipSchemaAnnotations
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ class Domain < ApplicationRecord
|
|||||||
def parent_domains
|
def parent_domains
|
||||||
parts = name.split(".")
|
parts = name.split(".")
|
||||||
parts[0, parts.size - 1].each_with_index.map do |_, i|
|
parts[0, parts.size - 1].each_with_index.map do |_, i|
|
||||||
parts[i..-1].join(".")
|
parts[i..].join(".")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
# Seeds go here...
|
||||||
|
|||||||
@@ -11,8 +11,10 @@ require_relative "version"
|
|||||||
|
|
||||||
module Postal
|
module Postal
|
||||||
|
|
||||||
|
# rubocop:disable Lint/EmptyClass
|
||||||
class Config
|
class Config
|
||||||
end
|
end
|
||||||
|
# rubocop:enable Lint/EmptyClass
|
||||||
|
|
||||||
def self.host
|
def self.host
|
||||||
@host ||= config.web.host || "localhost:5000"
|
@host ||= config.web.host || "localhost:5000"
|
||||||
|
|||||||
@@ -34,14 +34,14 @@ module Postal
|
|||||||
|
|
||||||
def normalized_headers
|
def normalized_headers
|
||||||
[].tap do |new_headers|
|
[].tap do |new_headers|
|
||||||
dkim_headers = headers.select { |h|
|
dkim_headers = headers.select do |h|
|
||||||
h.match(%r{
|
h.match(/
|
||||||
^(
|
^(
|
||||||
from|sender|reply-to|subject|date|message-id|to|cc|mime-version|content-type|content-transfer-encoding|
|
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|
|
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
|
list-owner|list-unsubscribe|list-subscribe|list-post
|
||||||
):}ix)
|
):/ix)
|
||||||
}
|
end
|
||||||
dkim_headers.each do |h|
|
dkim_headers.each do |h|
|
||||||
new_headers << normalize_header(h)
|
new_headers << normalize_header(h)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,10 +2,24 @@
|
|||||||
|
|
||||||
module Postal
|
module Postal
|
||||||
|
|
||||||
module Errors
|
|
||||||
end
|
|
||||||
|
|
||||||
class Error < StandardError
|
class Error < StandardError
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ module Postal
|
|||||||
|
|
||||||
log "Sending request to #{@endpoint.url}"
|
log "Sending request to #{@endpoint.url}"
|
||||||
response = Postal::HTTP.post(@endpoint.url, request_options)
|
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}"
|
result.details = "Received a #{response[:code]} from #{@endpoint.url}"
|
||||||
log " -> Received: #{response[:code]}"
|
log " -> Received: #{response[:code]}"
|
||||||
if response[:body]
|
if response[:body]
|
||||||
|
|||||||
@@ -295,9 +295,7 @@ module Postal
|
|||||||
end
|
end
|
||||||
|
|
||||||
def stringify_keys(hash)
|
def stringify_keys(hash)
|
||||||
hash.each_with_object({}) do |(key, value), h|
|
hash.transform_keys(&:to_s)
|
||||||
h[key.to_s] = value
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def escape(value)
|
def escape(value)
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ module Postal
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# rubocop:disable Style/HashLikeCase
|
||||||
def webhook_event
|
def webhook_event
|
||||||
@webhook_event ||= case status
|
@webhook_event ||= case status
|
||||||
when "Sent" then "MessageSent"
|
when "Sent" then "MessageSent"
|
||||||
@@ -69,6 +70,7 @@ module Postal
|
|||||||
when "Held" then "MessageHeld"
|
when "Held" then "MessageHeld"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
# rubocop:enable Style/HashLikeCase
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ module Postal
|
|||||||
raise Postal::Error, "You must provide at least one type to return" if options[:types].empty?
|
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
|
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 = @database.query("SELECT SUM(count) as count FROM `#{@database.database_name}`.`live_stats` WHERE `type` IN (#{types}) AND timestamp > #{time}").first
|
||||||
result["count"] || 0
|
result["count"] || 0
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ module Postal
|
|||||||
response = nil
|
response = nil
|
||||||
begin
|
begin
|
||||||
response = http.request(request)
|
response = http.request(request)
|
||||||
rescue Exception => e
|
rescue StandardError => e
|
||||||
logger.error "Error talking to rspamd: #{e.class} (#{e.message})"
|
logger.error "Error talking to rspamd: #{e.class} (#{e.message})"
|
||||||
logger.error e.backtrace[0, 5]
|
logger.error e.backtrace[0, 5]
|
||||||
|
|
||||||
|
|||||||
@@ -63,15 +63,16 @@ module Postal
|
|||||||
|
|
||||||
def parse_parts(parts)
|
def parse_parts(parts)
|
||||||
parts.each do |part|
|
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.body = parse(part.body.decoded.dup, :html)
|
||||||
part.content_transfer_encoding = nil
|
part.content_transfer_encoding = nil
|
||||||
part.charset = "UTF-8"
|
part.charset = "UTF-8"
|
||||||
elsif part.content_type =~ /text\/plain/
|
when /text\/plain/
|
||||||
part.body = parse(part.body.decoded.dup, :text)
|
part.body = parse(part.body.decoded.dup, :text)
|
||||||
part.content_transfer_encoding = nil
|
part.content_transfer_encoding = nil
|
||||||
part.charset = "UTF-8"
|
part.charset = "UTF-8"
|
||||||
elsif part.content_type =~ /multipart\/(alternative|related)/
|
when /multipart\/(alternative|related)/
|
||||||
unless part.parts.empty?
|
unless part.parts.empty?
|
||||||
parse_parts(part.parts)
|
parse_parts(part.parts)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -65,8 +65,6 @@ module Postal
|
|||||||
smtp_client.enable_starttls(self.class.ssl_context_with_verify)
|
smtp_client.enable_starttls(self.class.ssl_context_with_verify)
|
||||||
when "TLS"
|
when "TLS"
|
||||||
smtp_client.enable_tls(self.class.ssl_context_with_verify)
|
smtp_client.enable_tls(self.class.ssl_context_with_verify)
|
||||||
else
|
|
||||||
# Nothing
|
|
||||||
end
|
end
|
||||||
|
|
||||||
smtp_client.start(@source_ip_address ? @source_ip_address.hostname : self.class.default_helo_hostname)
|
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"
|
"550 Route does not accept incoming messages"
|
||||||
else
|
else
|
||||||
log "Added route #{route.id} to recipients (tag: #{tag.inspect})"
|
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 }]
|
@recipients << [:route, actual_rcpt_to, route.server, { route: route }]
|
||||||
"250 OK"
|
"250 OK"
|
||||||
end
|
end
|
||||||
@@ -415,7 +415,7 @@ module Postal
|
|||||||
if @data.bytesize > Postal.config.smtp_server.max_message_size.megabytes.to_i
|
if @data.bytesize > Postal.config.smtp_server.max_message_size.megabytes.to_i
|
||||||
transaction_reset
|
transaction_reset
|
||||||
@state = :welcomed
|
@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
|
end
|
||||||
|
|
||||||
if @headers["received"].grep(/by #{Postal.config.dns.smtp_server_hostname}/).count > 4
|
if @headers["received"].grep(/by #{Postal.config.dns.smtp_server_hostname}/).count > 4
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ module Postal
|
|||||||
@ssl_context ||= begin
|
@ssl_context ||= begin
|
||||||
ssl_context = OpenSSL::SSL::SSLContext.new
|
ssl_context = OpenSSL::SSL::SSLContext.new
|
||||||
ssl_context.cert = Postal.smtp_certificates[0]
|
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.key = Postal.smtp_private_key
|
||||||
ssl_context.ssl_version = Postal.config.smtp_server.ssl_version if Postal.config.smtp_server.ssl_version
|
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
|
ssl_context.ciphers = Postal.config.smtp_server.tls_ciphers if Postal.config.smtp_server.tls_ciphers
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ trap("INT") do
|
|||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
|
|
||||||
if ARGV[0].nil? || !(ARGV[0] =~ /@/)
|
if ARGV[0].nil? || ARGV[0] !~ /@/
|
||||||
puts "usage: postal test-app-smtp [email address]"
|
puts "usage: postal test-app-smtp [email address]"
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -34,7 +34,10 @@ RSpec.configure do |config|
|
|||||||
# Because the mail databases don't use any transactions, all data left in the
|
# Because the mail databases don't use any transactions, all data left in the
|
||||||
# database will be left there unless removed.
|
# database will be left there unless removed.
|
||||||
DatabaseCleaner.start
|
DatabaseCleaner.start
|
||||||
|
|
||||||
|
# rubocop:disable Lint/ConstantDefinitionInBlock
|
||||||
GLOBAL_SERVER = FactoryBot.create(:server, provision_database: true)
|
GLOBAL_SERVER = FactoryBot.create(:server, provision_database: true)
|
||||||
|
# rubocop:enable Lint/ConstantDefinitionInBlock
|
||||||
end
|
end
|
||||||
|
|
||||||
config.after(:suite) do
|
config.after(:suite) do
|
||||||
|
|||||||
المرجع في مشكلة جديدة
حظر مستخدم