From 20cf6e98f1362be06db9b3d83e758ca3af5df8a2 Mon Sep 17 00:00:00 2001 From: Samuel Cochran Date: Wed, 18 Jul 2012 11:27:27 +0800 Subject: [PATCH] Discard periods prefixing SMTP data per RFC 821 4.5.2 --- examples/dotmail | 14 ++++++++++++++ lib/mail_catcher/smtp.rb | 5 ++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 examples/dotmail diff --git a/examples/dotmail b/examples/dotmail new file mode 100644 index 0000000..46d72d4 --- /dev/null +++ b/examples/dotmail @@ -0,0 +1,14 @@ +To: Blah +From: Me +Subject: Whatever +Content-Type: text/plain + +Plain text mail + +With some dot lines: + +. + +... + +Done. diff --git a/lib/mail_catcher/smtp.rb b/lib/mail_catcher/smtp.rb index eb60231..6088013 100644 --- a/lib/mail_catcher/smtp.rb +++ b/lib/mail_catcher/smtp.rb @@ -34,7 +34,10 @@ class MailCatcher::Smtp < EventMachine::Protocols::SmtpServer def receive_data_chunk(lines) current_message[:source] ||= "" - current_message[:source] += lines.join("\n") + lines.each do |line| + # RFC821 4.5.2 says leading periods should be stripped from the body data. + current_message[:source] << line.sub(/\A\./, "") << "\n" + end true end