From e0ba05acb11108d98a460ae3fac653ceefb5f672 Mon Sep 17 00:00:00 2001 From: Adam Cooke Date: Tue, 27 Jul 2021 14:31:40 +0000 Subject: [PATCH] fix(smtp_server): fixes issue with malformed rcpt to closes #1299 closes #1019 --- lib/postal/smtp_server/client.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/postal/smtp_server/client.rb b/lib/postal/smtp_server/client.rb index 36363e6..831b105 100644 --- a/lib/postal/smtp_server/client.rb +++ b/lib/postal/smtp_server/client.rb @@ -267,7 +267,17 @@ module Postal end rcpt_to = data.gsub(/RCPT TO\s*:\s*/i, '').gsub(/.*.*/, '').strip + + if rcpt_to.blank? + return '501 RCPT TO should not be empty' + end + uname, domain = rcpt_to.split('@', 2) + + if domain.blank? + return '501 Invalid RCPT TO' + end + uname, tag = uname.split('+', 2) if domain == Postal.config.dns.return_path || domain =~ /\A#{Regexp.escape(Postal.config.dns.custom_return_path_prefix)}\./