مراية لـ
https://github.com/postalserver/postal.git
تم المزامنة 2026-01-18 13:59:47 +00:00
style(rubocop): fix all safe auto correctable offenses
هذا الالتزام موجود في:
@@ -1,7 +1,7 @@
|
||||
# Be sure to restart your server when you modify this file.
|
||||
|
||||
# Version of your assets, change this if you want to expire all your assets.
|
||||
Rails.application.config.assets.version = '1.0'
|
||||
Rails.application.config.assets.version = "1.0"
|
||||
|
||||
# Add additional assets to the asset load path
|
||||
# Rails.application.config.assets.paths << Emoji.images_path
|
||||
|
||||
@@ -12,13 +12,13 @@
|
||||
|
||||
# These inflection rules are supported but not enabled by default:
|
||||
ActiveSupport::Inflector.inflections(:en) do |inflect|
|
||||
inflect.acronym 'API'
|
||||
inflect.acronym 'SMTP'
|
||||
inflect.acronym 'IP'
|
||||
inflect.acronym 'DNS'
|
||||
inflect.acronym 'UUID'
|
||||
inflect.acronym 'HTTP'
|
||||
inflect.acronym 'DB'
|
||||
inflect.acronym 'MX'
|
||||
inflect.acronym 'DKIM'
|
||||
inflect.acronym "API"
|
||||
inflect.acronym "SMTP"
|
||||
inflect.acronym "IP"
|
||||
inflect.acronym "DNS"
|
||||
inflect.acronym "UUID"
|
||||
inflect.acronym "HTTP"
|
||||
inflect.acronym "DB"
|
||||
inflect.acronym "MX"
|
||||
inflect.acronym "DKIM"
|
||||
end
|
||||
|
||||
@@ -1,37 +1,38 @@
|
||||
require 'mail'
|
||||
require "mail"
|
||||
module Mail
|
||||
|
||||
module Encodings
|
||||
|
||||
# Handle windows-1258 as windows-1252 when decoding
|
||||
def Encodings.q_value_decode(str)
|
||||
str = str.sub(/\=\?windows-?1258\?/i, '\=?windows-1252?')
|
||||
def self.q_value_decode(str)
|
||||
str = str.sub(/=\?windows-?1258\?/i, '\=?windows-1252?')
|
||||
RubyVer.q_value_decode(str)
|
||||
end
|
||||
def Encodings.b_value_decode(str)
|
||||
str = str.sub(/\=\?windows-?1258\?/i, '\=?windows-1252?')
|
||||
|
||||
def self.b_value_decode(str)
|
||||
str = str.sub(/=\?windows-?1258\?/i, '\=?windows-1252?')
|
||||
RubyVer.b_value_decode(str)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Message
|
||||
|
||||
## Extract plain text body of message
|
||||
def plain_body
|
||||
if self.multipart? and self.text_part
|
||||
self.text_part.decoded
|
||||
elsif self.mime_type == 'text/plain' || self.mime_type.nil?
|
||||
self.decoded
|
||||
else
|
||||
nil
|
||||
if multipart? and text_part
|
||||
text_part.decoded
|
||||
elsif mime_type == "text/plain" || mime_type.nil?
|
||||
decoded
|
||||
end
|
||||
end
|
||||
|
||||
## Extract HTML text body of message
|
||||
def html_body
|
||||
if self.multipart? and self.html_part
|
||||
self.html_part.decoded
|
||||
elsif self.mime_type == 'text/html'
|
||||
self.decoded
|
||||
else
|
||||
nil
|
||||
if multipart? and html_part
|
||||
html_part.decoded
|
||||
elsif mime_type == "text/html"
|
||||
decoded
|
||||
end
|
||||
end
|
||||
|
||||
@@ -46,9 +47,21 @@ module Mail
|
||||
# Returns the filename of the attachment (if it exists) or returns nil
|
||||
# Make up a filename for rfc822 attachments if it isn't specified
|
||||
def find_attachment
|
||||
content_type_name = header[:content_type].filename rescue nil
|
||||
content_disp_name = header[:content_disposition].filename rescue nil
|
||||
content_loc_name = header[:content_location].location rescue nil
|
||||
content_type_name = begin
|
||||
header[:content_type].filename
|
||||
rescue StandardError
|
||||
nil
|
||||
end
|
||||
content_disp_name = begin
|
||||
header[:content_disposition].filename
|
||||
rescue StandardError
|
||||
nil
|
||||
end
|
||||
content_loc_name = begin
|
||||
header[:content_location].location
|
||||
rescue StandardError
|
||||
nil
|
||||
end
|
||||
|
||||
if content_type && content_type_name
|
||||
filename = content_type_name
|
||||
@@ -56,56 +69,73 @@ module Mail
|
||||
filename = content_disp_name
|
||||
elsif content_location && content_loc_name
|
||||
filename = content_loc_name
|
||||
elsif self.mime_type == "message/rfc822"
|
||||
filename = "#{rand(100000000)}.eml"
|
||||
elsif mime_type == "message/rfc822"
|
||||
filename = "#{rand(100_000_000)}.eml"
|
||||
else
|
||||
filename = nil
|
||||
end
|
||||
|
||||
if filename
|
||||
# Normal decode
|
||||
filename = Mail::Encodings.decode_encode(filename, :decode) rescue filename
|
||||
filename = begin
|
||||
Mail::Encodings.decode_encode(filename, :decode)
|
||||
rescue StandardError
|
||||
filename
|
||||
end
|
||||
end
|
||||
filename
|
||||
end
|
||||
|
||||
def decode_body_as_text
|
||||
body_text = decode_body
|
||||
charset_tmp = Encoding.find(Ruby19.pick_encoding(charset)) rescue 'ASCII'
|
||||
charset_tmp = 'Windows-1252' if charset_tmp.to_s =~ /windows-?1258/i
|
||||
if charset_tmp == Encoding.find('UTF-7')
|
||||
body_text.force_encoding('UTF-8')
|
||||
decoded = body_text.gsub(/\+.*?\-/m) {|n|Base64.decode64(n[1..-2]+'===').force_encoding('UTF-16BE').encode('UTF-8')}
|
||||
charset_tmp = begin
|
||||
Encoding.find(Ruby19.pick_encoding(charset))
|
||||
rescue StandardError
|
||||
"ASCII"
|
||||
end
|
||||
charset_tmp = "Windows-1252" if charset_tmp.to_s =~ /windows-?1258/i
|
||||
if charset_tmp == Encoding.find("UTF-7")
|
||||
body_text.force_encoding("UTF-8")
|
||||
decoded = body_text.gsub(/\+.*?-/m) { |n| Base64.decode64(n[1..-2] + "===").force_encoding("UTF-16BE").encode("UTF-8") }
|
||||
else
|
||||
body_text.force_encoding(charset_tmp)
|
||||
decoded = body_text.encode("utf-8", :invalid => :replace, :undef => :replace)
|
||||
decoded = body_text.encode("utf-8", invalid: :replace, undef: :replace)
|
||||
end
|
||||
decoded.valid_encoding? ? decoded : decoded.encode("utf-16le", :invalid => :replace, :undef => :replace).encode("utf-8")
|
||||
decoded.valid_encoding? ? decoded : decoded.encode("utf-16le", invalid: :replace, undef: :replace).encode("utf-8")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Handle attached emails as attachments
|
||||
class AttachmentsList < Array
|
||||
|
||||
def initialize(parts_list)
|
||||
@parts_list = parts_list
|
||||
@content_disposition_type = 'attachment'
|
||||
parts_list.map { |p|
|
||||
@content_disposition_type = "attachment"
|
||||
parts_list.map do |p|
|
||||
(p.parts.empty? and p.attachment?) ? p : p.attachments
|
||||
}.flatten.compact.each { |a| self << a }
|
||||
end.flatten.compact.each { |a| self << a }
|
||||
self
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Array
|
||||
|
||||
def decoded
|
||||
return nil if self.empty?
|
||||
return self.first.decoded
|
||||
return nil if empty?
|
||||
|
||||
first.decoded
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class NilClass
|
||||
|
||||
def decoded
|
||||
nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
require 'postal'
|
||||
require 'postal/message_db/mysql'
|
||||
require "postal"
|
||||
require "postal/message_db/mysql"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
module ActionView
|
||||
module RecordIdentifier
|
||||
|
||||
def dom_id(record, prefix = nil)
|
||||
if record.new_record?
|
||||
dom_class(record, prefix || NEW)
|
||||
@@ -8,5 +9,6 @@ module ActionView
|
||||
"#{dom_class(record, prefix)}#{JOIN}#{id}"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
if Postal.config.rails&.secret_key
|
||||
Rails.application.secrets.secret_key_base = Postal.config.rails.secret_key
|
||||
else
|
||||
$stderr.puts "No secret key was specified in the Postal config file. Using one for just this session"
|
||||
warn "No secret key was specified in the Postal config file. Using one for just this session"
|
||||
Rails.application.secrets.secret_key_base = SecureRandom.hex(128)
|
||||
end
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
SecureHeaders::Configuration.default do |config|
|
||||
|
||||
config.hsts = SecureHeaders::OPT_OUT
|
||||
|
||||
config.csp[:default_src] = []
|
||||
config.csp[:script_src] = ["'self'"]
|
||||
config.csp[:child_src] = ["'self'"]
|
||||
config.csp[:connect_src] = ["'self'"]
|
||||
|
||||
end
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
require 'postal/config'
|
||||
require "postal/config"
|
||||
|
||||
if Postal.config.general&.exception_url
|
||||
require 'raven'
|
||||
require "raven"
|
||||
Raven.configure do |config|
|
||||
config.dsn = Postal.config.general.exception_url
|
||||
config.environments = ['production']
|
||||
if ENV['DEV_EXCEPTIONS']
|
||||
config.environments << 'development'
|
||||
config.environments = ["production"]
|
||||
if ENV["DEV_EXCEPTIONS"]
|
||||
config.environments << "development"
|
||||
end
|
||||
config.silence_ready = true
|
||||
config.tags = {:process => ENV['PROC_NAME']}
|
||||
config.tags = { process: ENV.fetch("PROC_NAME", nil) }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
# Be sure to restart your server when you modify this file.
|
||||
|
||||
Rails.application.config.session_store :cookie_store, key: '_postal_session'
|
||||
Rails.application.config.session_store :cookie_store, key: "_postal_session"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
require 'postal/config'
|
||||
require "postal/config"
|
||||
if Postal.config&.smtp
|
||||
ActionMailer::Base.delivery_method = :smtp
|
||||
ActionMailer::Base.smtp_settings = {:address => Postal.config.smtp.host, :user_name => Postal.config.smtp.username, :password => Postal.config.smtp.password, :port => Postal.config.smtp.port || 25}
|
||||
ActionMailer::Base.smtp_settings = { address: Postal.config.smtp.host, user_name: Postal.config.smtp.username, password: Postal.config.smtp.password, port: Postal.config.smtp.port || 25 }
|
||||
end
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
class Net::SMTP::Response
|
||||
|
||||
def message
|
||||
@string
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Net::SMTP
|
||||
|
||||
attr_accessor :source_address
|
||||
|
||||
def secure_socket?
|
||||
@@ -19,7 +22,7 @@ class Net::SMTP
|
||||
#
|
||||
def rset
|
||||
@error_occurred = false
|
||||
getok('RSET')
|
||||
getok("RSET")
|
||||
end
|
||||
|
||||
def rset_errors
|
||||
@@ -29,6 +32,7 @@ class Net::SMTP
|
||||
private
|
||||
|
||||
def tcp_socket(address, port)
|
||||
TCPSocket.open(address, port, self.source_address)
|
||||
TCPSocket.open(address, port, source_address)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
module Rack
|
||||
class Request
|
||||
|
||||
module Helpers
|
||||
|
||||
def trusted_proxy?(ip)
|
||||
ip =~ /^127\.0\.0\.1$|^localhost$|^unix$$/i
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
المرجع في مشكلة جديدة
حظر مستخدم