Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #7861: base64_decoding.patch

File base64_decoding.patch, 3.3 kB (added by orangechicken, 2 years ago)
  • actionmailer/lib/action_mailer/vendor/tmail/base64.rb

    old new  
    4242    end 
    4343 
    4444    def rb_decode( str, strict = false ) 
    45       str.unpack('m') 
     45      str.unpack('m').first 
    4646    end 
    4747 
    4848    begin 
  • actionmailer/lib/action_mailer/vendor/tmail/quoting.rb

    old new  
    7878      end 
    7979  
    8080      def unquote_base64_and_convert_to(text, to, from) 
    81         convert_to(Base64.decode(text).first, to, from) 
     81        convert_to(Base64.decode(text), to, from) 
    8282      end 
    8383 
    8484      begin 
  • actionmailer/test/quoting_test.rb

    old new  
    3030    mail = TMail::Mail.parse(IO.read("#{File.dirname(__FILE__)}/fixtures/raw_email_with_partially_quoted_subject")) 
    3131    assert_equal "Re: Test: \"\346\274\242\345\255\227\" mid \"\346\274\242\345\255\227\" tail", mail.subject 
    3232  end 
     33   
     34  def test_rb_decode 
     35    encoded, decoded = expected_base64_strings 
     36    assert_equal decoded, TMail::Base64.rb_decode(encoded) 
     37  end 
     38   
     39  def test_rb_encode 
     40    encoded, decoded = expected_base64_strings 
     41    assert_equal encoded.length, TMail::Base64.rb_encode(decoded).length 
     42  end 
     43   
     44  def test_rb_decode_should_match_c_decode_if_available 
     45    encoded, decoded = expected_base64_strings 
     46     
     47    begin 
     48      require 'tmail/base64.so' 
     49      assert_equal TMail::Base64.rb_decode(encoded), TMail::Base64.c_decode(encoded) 
     50    rescue 
     51      # No .so 
     52    end 
     53  end 
     54   
     55  def test_rb_encode_should_match_c_encode_if_available 
     56    encoded, decoded = expected_base64_strings 
     57     
     58    begin 
     59      require 'tmail/base64.so' 
     60      assert_equal TMail::Base64.rb_encode(decoded), TMail::Base64.c_encode(decoded) 
     61    rescue 
     62      # No .so 
     63    end 
     64  end 
    3365 
    3466  private 
    35  
     67     
    3668    # This whole thing *could* be much simpler, but I don't think Tempfile, 
    3769    # popen and others exist on all platforms (like Windows). 
    3870    def execute_in_sandbox(code) 
     
    5486      File.delete(test_name) rescue nil 
    5587      File.delete(res_name) rescue nil 
    5688    end 
     89     
     90    def expected_base64_strings 
     91      [ File.read("#{File.dirname(__FILE__)}/fixtures/raw_base64_encoded_string"), File.read("#{File.dirname(__FILE__)}/fixtures/raw_base64_decoded_string") ] 
     92    end 
    5793end 
  • actionmailer/test/tmail_test.rb

    old new  
    1616    mail = TMail::Mail.parse(fixture) 
    1717    assert_equal 2, mail.attachments.length 
    1818    assert_equal "image/png", mail.attachments.first.content_type 
     19    assert_equal 1902, mail.attachments.first.length 
    1920    assert_equal "application/pkcs7-signature", mail.attachments.last.content_type 
    2021  end 
    2122end