File: quoted_printable_spec.rb

package info (click to toggle)
ruby-mail 2.6.1%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,092 kB
  • ctags: 1,281
  • sloc: ruby: 43,919; makefile: 2
file content (51 lines) | stat: -rw-r--r-- 1,855 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require 'spec_helper'

describe Mail::Encodings::QuotedPrintable do
  
  it "should encode quoted printable from text" do
    result = "This is\r\na test=\r\n"
    Mail::Encodings::QuotedPrintable.encode("This is\na test").should eq result
  end

  it "should encode quoted printable from crlf text" do
    result = "This is\r\na test=\r\n"
    Mail::Encodings::QuotedPrintable.encode("This is\r\na test").should eq result
  end

  it "should encode quoted printable from cr text" do
    result = "This is\r\na test=\r\n"
    Mail::Encodings::QuotedPrintable.encode("This is\ra test").should eq result
  end
  
  it "should decode quoted printable" do
    result = "This is\na test"
    Mail::Encodings::QuotedPrintable.decode("This is\r\na test").should eq result
  end
  
  it "should encode quoted printable from binary" do
    result = "=00=00=00=00=\r\n"
    Mail::Encodings::QuotedPrintable.encode("\000\000\000\000").should eq result
  end
  
  it "should decode quoted printable text" do
    result = "\000\000\000\000"
    Mail::Encodings::QuotedPrintable.decode("=00=00=00=00").should eq result
  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