Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decode quoted-printable with bad line breaks #493

Merged
merged 1 commit into from
Jan 28, 2013
Merged
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
5 changes: 3 additions & 2 deletions lib/mail/encodings/quoted_printable.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ def self.can_encode?(str)
EightBit.can_encode? str EightBit.can_encode? str
end end


# Decode the string from Quoted-Printable # Decode the string from Quoted-Printable. Cope with hard line breaks
# that were incorrectly encoded as hex instead of literal CRLF.
def self.decode(str) def self.decode(str)
str.unpack("M*").first.to_lf str.gsub(/(?:=0D=0A|=0D|=0A)\r\n/, "\r\n").unpack("M*").first.to_lf
end end


def self.encode(str) def self.encode(str)
Expand Down
16 changes: 16 additions & 0 deletions spec/mail/encodings/quoted_printable_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -31,5 +31,21 @@
result = "\000\000\000\000" result = "\000\000\000\000"
Mail::Encodings::QuotedPrintable.decode("=00=00=00=00").should eq result Mail::Encodings::QuotedPrintable.decode("=00=00=00=00").should eq result
end end

%w(=0D =0A =0D=0A).each do |linebreak|
expected = "first line wraps\n\nsecond paragraph"
it "should cope with inappropriate #{linebreak} line break encoding" do
body = "first line=\r\n wraps#{linebreak}\r\n#{linebreak}\r\nsecond paragraph=\r\n"
Mail::Encodings::QuotedPrintable.decode(body).should eq expected
end
end

[["\r", "=0D"], ["\n", "=0A"], ["\r\n", "=0D=0A"]].each do |crlf, linebreak|
expected = "first line wraps\n\nsecond paragraph"
it "should allow encoded #{linebreak} line breaks with soft line feeds" do
body = "first line=\r\n wraps#{linebreak}=\r\n#{linebreak}=\r\nsecond paragraph=\r\n"
Mail::Encodings::QuotedPrintable.decode(body).should eq expected
end
end


end end