Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/senders/smtp_sender.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ def determine_mail_from_for_message(message)
# If the domain has a valid custom return path configured, return
# that.
if message.domain.return_path_status == "OK"
return "#{message.server.token}@#{message.domain.return_path_domain}"
return "#{message.server.token}+#{message.token}@#{message.domain.return_path_domain}"
end

"#{message.server.token}@#{Postal::Config.dns.return_path_domain}"
"#{message.server.token}+#{message.token}@#{Postal::Config.dns.return_path_domain}"
end

# Return the RCPT TO to use for the given message in this sending session
Expand Down
2 changes: 2 additions & 0 deletions doc/config/yaml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ postal:
use_local_ns_for_domain_verification: false
# Append a Resend-Sender header to all outgoing e-mails
use_resent_sender_header: true
# Use message tags when assigning bounces to their corresponding messages
use_message_tags_for_bounces: false
# Path to the private key used for signing
signing_key_path: $config-file-root/signing.key
# An array of SMTP relays in the format of smtp://host:port
Expand Down
5 changes: 5 additions & 0 deletions lib/postal/config_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ module Postal
default true
end

boolean :use_message_tags_for_bounces do
description "Use message tags when assigning bounces to their corresponding messages"
default false
end

string :signing_key_path do
description "Path to the private key used for signing"
default "$config-file-root/signing.key"
Expand Down
12 changes: 11 additions & 1 deletion lib/postal/message_db/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,17 @@ def create_link(url)
def original_messages
return nil unless bounce

other_message_ids = raw_message.scan(/\X-Postal-MsgID:\s*([a-z0-9]+)/i).flatten
# if this is enabled, we search first for the message tag as this is faster
# than to scan the full message (which is probably many mbytes in size)
if Postal::Config.postal.use_message_tags_for_bounces?
uname, domain = rcpt_to.split("@", 2)
uname, other_message_ids = uname.split("+", 2)
end
# if we did not found any messages, or this was not enabled, then fall back to
# the old header based search
if other_message_ids.nil? || other_message_ids.empty?
other_message_ids = raw_message.scan(/\X-Postal-MsgID:\s*([a-z0-9]+)/i).flatten
end
if other_message_ids.empty?
[]
else
Expand Down
6 changes: 3 additions & 3 deletions spec/senders/smtp_sender_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
sender.send_message(message)
expect(sender.endpoints.last).to have_received(:send_message).with(
kind_of(String),
"#{server.token}@#{domain.return_path_domain}",
"#{server.token}+#{message.token}@#{domain.return_path_domain}",
["[email protected]"]
)
end
Expand All @@ -274,7 +274,7 @@
sender.send_message(message)
expect(sender.endpoints.last).to have_received(:send_message).with(
kind_of(String),
"#{server.token}@#{Postal::Config.dns.return_path_domain}",
"#{server.token}+#{message.token}@#{Postal::Config.dns.return_path_domain}",
["[email protected]"]
)
end
Expand Down Expand Up @@ -308,7 +308,7 @@
it "adds the resent-sender header" do
sender.send_message(message)
expect(sender.endpoints.last).to have_received(:send_message).with(
"Resent-Sender: #{server.token}@#{Postal::Config.dns.return_path_domain}\r\n#{message.raw_message}",
"Resent-Sender: #{server.token}+#{message.token}@#{Postal::Config.dns.return_path_domain}\r\n#{message.raw_message}",
kind_of(String),
kind_of(Array)
)
Expand Down
Loading