1
0
مراية لـ https://github.com/postalserver/postal.git تم المزامنة 2026-01-18 05:49:47 +00:00

feat: privacy mode

Adds support for hiding IP addresses & hostnames associated with clients sending
authenticated mail in to Postal over SMTP and HTTP
هذا الالتزام موجود في:
Adam Cooke
2024-02-06 19:35:43 +00:00
الأصل f05c2e4503
التزام 15f9671b66
9 ملفات معدلة مع 141 إضافات و59 حذوفات

عرض الملف

@@ -0,0 +1,43 @@
module Postal
class ReceivedHeader
OUR_HOSTNAMES = {
smtp: Postal.config.dns.smtp_server_hostname,
http: Postal.config.web.host
}
class << self
def generate(server, helo, ip_address, method)
our_hostname = OUR_HOSTNAMES[method]
if our_hostname.nil?
raise Error, "`method` is invalid (must be one of #{OUR_HOSTNAMES.join(', ')})"
end
header = "by #{our_hostname} with #{method.to_s.upcase}; #{Time.now.utc.rfc2822}"
if server.nil? || server.privacy_mode == false
hostname = resolve_hostname(ip_address)
header = "from #{helo} (#{hostname} [#{ip_address}]) #{header}"
end
header
end
private
def resolve_hostname(ip_address)
Resolv::DNS.open do |dns|
dns.timeouts = [10, 5]
begin
dns.getname(ip_address)
rescue StandardError
ip_address
end
end
end
end
end
end

عرض الملف

@@ -103,17 +103,6 @@ module Postal
private
def resolve_hostname
Resolv::DNS.open do |dns|
dns.timeouts = [10, 5]
@hostname = begin
dns.getname(@ip_address)
rescue StandardError
@ip_address
end
end
end
def proxy(data)
if m = data.match(/\APROXY (.+) (.+) (.+) (.+) (.+)\z/)
@ip_address = m[2]
@@ -143,7 +132,6 @@ module Postal
end
def ehlo(data)
resolve_hostname
@helo_name = data.strip.split(" ", 2)[1]
transaction_reset
@state = :welcomed
@@ -151,7 +139,6 @@ module Postal
end
def helo(data)
resolve_hostname
@helo_name = data.strip.split(" ", 2)[1]
transaction_reset
@state = :welcomed
@@ -377,10 +364,10 @@ module Postal
@headers = {}
@receiving_headers = true
received_header_content = "from #{@helo_name} (#{@hostname} [#{@ip_address}]) by #{Postal.config.dns.smtp_server_hostname} with SMTP; #{Time.now.utc.rfc2822}".force_encoding("BINARY")
unless Postal.config.smtp_server.strip_received_headers?
@data << "Received: #{received_header_content}\r\n"
end
received_header = Postal::ReceivedHeader.generate(@credential&.server, @helo_name, @ip_address, :smtp)
.force_encoding("BINARY")
@data << "Received: #{received_header_content}\r\n"
@headers["received"] = [received_header_content]
handler = proc do |data|