From f60ccc660434d445b78e8281833c99048a00de20 Mon Sep 17 00:00:00 2001 From: jethrogb Date: Wed, 12 Mar 2014 14:41:02 -0700 Subject: [PATCH] Fix Mail::Exim, forgotten in 4875bc2b The parameters of Mail::Sendmail.call changed in 4875bc2b but Mail::Exim was not changed accordingly. Backport to 2-5-stable References #689 --- CHANGELOG.rdoc | 1 + lib/mail/network/delivery_methods/exim.rb | 16 ++--- lib/mail/network/delivery_methods/sendmail.rb | 8 ++- .../network/delivery_methods/exim_spec.rb | 61 +++++++------------ 4 files changed, 35 insertions(+), 51 deletions(-) diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index d6fcbd455..9f08bbf24 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -5,6 +5,7 @@ Security: Bugs: * #633 – Cope with message parts that have an empty Content-Type (ThomasKoppensteiner, zeepeeare) +* #689 - Fix Exim delivery method broken by #477 in 2.5.4. (jethrogb) == Version 2.5.4 - Tue May 14 14:45:00 +1100 2013 Mikel Lindsaar diff --git a/lib/mail/network/delivery_methods/exim.rb b/lib/mail/network/delivery_methods/exim.rb index f3b5800f9..36cc848fd 100644 --- a/lib/mail/network/delivery_methods/exim.rb +++ b/lib/mail/network/delivery_methods/exim.rb @@ -36,17 +36,13 @@ module Mail # # mail.deliver! class Exim < Sendmail - def initialize(values) - self.settings = { :location => '/usr/sbin/exim', - :arguments => '-i -t' }.merge(values) - end + DEFAULTS = { + :location => '/usr/sbin/exim', + :arguments => '-i -t' + } - def self.call(path, arguments, destinations, mail) - popen "#{path} #{arguments}" do |io| - io.puts mail.encoded.to_lf - io.flush - end + def self.call(path, arguments, destinations, encoded_message) + super path, arguments, nil, encoded_message end - end end diff --git a/lib/mail/network/delivery_methods/sendmail.rb b/lib/mail/network/delivery_methods/sendmail.rb index 3a4e4f03c..3aa571ca1 100644 --- a/lib/mail/network/delivery_methods/sendmail.rb +++ b/lib/mail/network/delivery_methods/sendmail.rb @@ -37,11 +37,15 @@ module Mail # # mail.deliver! class Sendmail + DEFAULTS = { + :location => '/usr/sbin/sendmail', + :arguments => '-i' + } + attr_accessor :settings def initialize(values) - self.settings = { :location => '/usr/sbin/sendmail', - :arguments => '-i' }.merge(values) + self.settings = self.class::DEFAULTS.merge(values) end def deliver!(mail) diff --git a/spec/mail/network/delivery_methods/exim_spec.rb b/spec/mail/network/delivery_methods/exim_spec.rb index 9017563cb..351c4ba98 100644 --- a/spec/mail/network/delivery_methods/exim_spec.rb +++ b/spec/mail/network/delivery_methods/exim_spec.rb @@ -26,11 +26,9 @@ to 'marcel@test.lindsaar.net, bob@test.lindsaar.net' subject 'invalid RFC2822' end - - Mail::Exim.should_receive(:call).with('/usr/sbin/exim', - '-i -t -f "roger@test.lindsaar.net" --', - '"marcel@test.lindsaar.net" "bob@test.lindsaar.net"', - mail.encoded) + + Mail::Sendmail.should_receive(:call).with('/usr/sbin/exim', '-i -t -f "roger@test.lindsaar.net" --', nil, mail.encoded) + mail.deliver! end @@ -50,14 +48,10 @@ message_id "<1234@test.lindsaar.net>" body "body" end - - Mail::Exim.should_receive(:call).with('/usr/sbin/exim', - '-i -t -f "return@test.lindsaar.net" --', - '"to@test.lindsaar.net"', - mail.encoded) - - mail.deliver + Mail::Sendmail.should_receive(:call).with('/usr/sbin/exim', '-i -t -f "return@test.lindsaar.net" --', nil, mail.encoded) + + mail.deliver end it "should use the sender address is no return path is specified" do @@ -74,14 +68,9 @@ body "body" end - Mail::Exim.should_receive(:call).with('/usr/sbin/exim', - '-i -t -f "sender@test.lindsaar.net" --', - '"to@test.lindsaar.net"', - mail.encoded) - mail.deliver end - + it "should use the from address is no return path or sender are specified" do Mail.defaults do delivery_method :exim @@ -95,10 +84,8 @@ body "body" end - Mail::Exim.should_receive(:call).with('/usr/sbin/exim', - '-i -t -f "from@test.lindsaar.net" --', - '"to@test.lindsaar.net"', - mail.encoded) + Mail::Sendmail.should_receive(:call).with('/usr/sbin/exim', '-i -t -f "from@test.lindsaar.net" --', nil, mail.encoded) + mail.deliver end @@ -115,10 +102,8 @@ body 'body' end - Mail::Exim.should_receive(:call).with('/usr/sbin/exim', - '-i -t -f "\"from+suffix test\"@test.lindsaar.net" --', - '"to@test.lindsaar.net"', - mail.encoded) + Mail::Sendmail.should_receive(:call).with('/usr/sbin/exim', '-i -t -f "\"from+suffix test\"@test.lindsaar.net" --', nil, mail.encoded) + mail.deliver end @@ -132,10 +117,8 @@ from 'from@test.lindsaar.net' end - Mail::Exim.should_receive(:call).with('/usr/sbin/exim', - '-i -t -f "from@test.lindsaar.net" --', - '"-hyphen@test.lindsaar.net"', - mail.encoded) + Mail::Sendmail.should_receive(:call).with('/usr/sbin/exim', '-i -t -f "from@test.lindsaar.net" --', nil, mail.encoded) + mail.deliver end end @@ -151,10 +134,8 @@ subject 'invalid RFC2822' end - Mail::Exim.should_receive(:call).with('/usr/sbin/exim', - ' -f "from@test.lindsaar.net" --', - '"marcel@test.lindsaar.net" "bob@test.lindsaar.net"', - mail.encoded) + Mail::Sendmail.should_receive(:call).with('/usr/sbin/exim', ' -f "from@test.lindsaar.net" --', nil, mail.encoded) + mail.deliver! end @@ -168,11 +149,13 @@ to 'marcel@test.lindsaar.net' subject 'invalid RFC2822' end - - Mail::Exim.should_receive(:call).with('/usr/sbin/exim', - " -f \"\\\"foo\\\\\\\"\\;touch /tmp/PWNED\\;\\\\\\\"\\\"@blah.com\" --", - '"marcel@test.lindsaar.net"', - mail.encoded) + + Mail::Sendmail.should_receive(:call).with( + '/usr/sbin/exim', + " -f \"\\\"foo\\\\\\\"\\;touch /tmp/PWNED\\;\\\\\\\"\\\"@blah.com\" --", + nil, + mail.encoded) + mail.deliver! end