diff --git a/Rakefile b/Rakefile index f09cb7d..f2e659f 100644 --- a/Rakefile +++ b/Rakefile @@ -4,7 +4,8 @@ require 'rake/testtask' require 'rbconfig' require 'fileutils' -spec = eval File.read('ruby-msg.gemspec') +gemspec_file = File.expand_path(File.dirname(__FILE__) + '/ruby-msg.gemspec') +spec = eval File.read(gemspec_file) task :default => [:test] diff --git a/contrib/wmf.rb b/contrib/wmf.rb index f662dc4..899c0da 100644 --- a/contrib/wmf.rb +++ b/contrib/wmf.rb @@ -1,4 +1,4 @@ -# -*- encoding : utf-8 -*- +# -*- encoding : ASCII-8BIT -*- # this file will be used later to enhance the msg conversion. @@ -52,7 +52,7 @@ def wmf_getdimensions wmf_data \b\f2\fs20{\object\objemb{\*\objclass PBrush}\objw1320\objh1274{\*\objdata 01050000 <- looks like standard header 02000000 <- not sure -07000000 <- this means length of following is 7. +07000000 <- this means length of following is 7. 50427275736800 <- Pbrush\000 in hex 00000000 <- ? 00000000 <- ? diff --git a/lib/mapi.rb b/lib/mapi.rb index 3dfd441..af9b364 100644 --- a/lib/mapi.rb +++ b/lib/mapi.rb @@ -1,4 +1,4 @@ -# -*- encoding : utf-8 -*- +# -*- encoding : ASCII-8BIT -*- require 'mapi/version' require 'mapi/base' require 'mapi/types' diff --git a/lib/mapi/base.rb b/lib/mapi/base.rb index 91cf190..73e1920 100644 --- a/lib/mapi/base.rb +++ b/lib/mapi/base.rb @@ -1,4 +1,4 @@ -# -*- encoding : utf-8 -*- +# -*- encoding : ASCII-8BIT -*- module Mapi # # Mapi::Item is the base class used for all mapi objects, and is purely a diff --git a/lib/mapi/convert.rb b/lib/mapi/convert.rb index cc7e18a..2e86e67 100644 --- a/lib/mapi/convert.rb +++ b/lib/mapi/convert.rb @@ -1,4 +1,4 @@ -# -*- encoding : utf-8 -*- +# -*- encoding : ASCII-8BIT -*- # we have two different "backends" for note conversion. we're sticking with # the current (home grown) mime one until the tmail version is suitably # polished. diff --git a/lib/mapi/convert/contact.rb b/lib/mapi/convert/contact.rb index 6b02e21..1a2297b 100644 --- a/lib/mapi/convert/contact.rb +++ b/lib/mapi/convert/contact.rb @@ -1,4 +1,4 @@ -# -*- encoding : utf-8 -*- +# -*- encoding : ASCII-8BIT -*- require 'rubygems' require 'vpim/vcard' diff --git a/lib/mapi/convert/note-mime.rb b/lib/mapi/convert/note-mime.rb index cd326d5..2156e8f 100644 --- a/lib/mapi/convert/note-mime.rb +++ b/lib/mapi/convert/note-mime.rb @@ -1,4 +1,4 @@ -# -*- encoding : utf-8 -*- +# -*- encoding : ASCII-8BIT -*- require 'base64' require 'mapi/mime' require 'time' diff --git a/lib/mapi/convert/note-tmail.rb b/lib/mapi/convert/note-tmail.rb index 1688f97..b2930a4 100644 --- a/lib/mapi/convert/note-tmail.rb +++ b/lib/mapi/convert/note-tmail.rb @@ -1,4 +1,4 @@ -# -*- encoding : utf-8 -*- +# -*- encoding : ASCII-8BIT -*- require 'rubygems' require 'tmail' diff --git a/lib/mapi/mime.rb b/lib/mapi/mime.rb index b278ff0..c8b007a 100644 --- a/lib/mapi/mime.rb +++ b/lib/mapi/mime.rb @@ -1,4 +1,4 @@ -# -*- encoding : utf-8 -*- +# -*- encoding : ASCII-8BIT -*- # # = Introduction # @@ -106,8 +106,17 @@ def to_s opts={} opts = {:boundary_counter => 0}.merge opts if multipart? boundary = Mime.make_boundary opts[:boundary_counter] += 1, self - @body = [preamble, parts.map { |part| "\r\n" + part.to_s(opts) + "\r\n" }, "--\r\n" + epilogue]. - flatten.join("\r\n--" + boundary) + begin + @body = [preamble, parts.map { |part| "\r\n" + part.to_s(opts) + "\r\n" }, "--\r\n" + epilogue]. + flatten.join("\r\n--" + boundary) + rescue Encoding::CompatibilityError => e + if ''.respond_to?(:force_encoding) + @body = [preamble, parts.map { |part| "\r\n" + part.to_s(opts).force_encoding('ASCII-8BIT') + "\r\n" }, "--\r\n" + epilogue]. + flatten.join("\r\n--" + boundary) + else + raise e + end + end content_type, attrs = Mime.split_header @headers['Content-Type'][0] attrs['boundary'] = boundary @headers['Content-Type'] = [([content_type] + attrs.map { |key, val| %{#{key}="#{val}"} }).join('; ')] diff --git a/lib/mapi/msg.rb b/lib/mapi/msg.rb index 8d8b286..c805ea4 100644 --- a/lib/mapi/msg.rb +++ b/lib/mapi/msg.rb @@ -1,4 +1,4 @@ -# -*- encoding : utf-8 -*- +# -*- encoding : ASCII-8BIT -*- require 'ole/storage' require 'mapi' require 'mapi/rtf' diff --git a/lib/mapi/orderedhash.rb b/lib/mapi/orderedhash.rb index 34b9777..dc33741 100644 --- a/lib/mapi/orderedhash.rb +++ b/lib/mapi/orderedhash.rb @@ -1,4 +1,4 @@ -# -*- encoding : utf-8 -*- +# -*- encoding : ASCII-8BIT -*- # = OrderedHash # # == Version diff --git a/lib/mapi/property_set.rb b/lib/mapi/property_set.rb index 5e8abe9..d911b98 100644 --- a/lib/mapi/property_set.rb +++ b/lib/mapi/property_set.rb @@ -1,4 +1,4 @@ -# -*- encoding : utf-8 -*- +# -*- encoding : ASCII-8BIT -*- require 'yaml' require 'mapi/types' require 'mapi/rtf' @@ -282,11 +282,6 @@ def body_html end end end - if @body_html && @body_html.respond_to?(:encoding) - @body_html.force_encoding("utf-8") - @body_html = @body_html.valid_encoding? ? @body_html : @body_html.encode("utf-16le", :invalid => :replace, :replace => "").encode("utf-8") - end - @body_html end end end diff --git a/lib/mapi/pst.rb b/lib/mapi/pst.rb index 57cd2e1..ce6bfda 100644 --- a/lib/mapi/pst.rb +++ b/lib/mapi/pst.rb @@ -1,4 +1,4 @@ -# -*- encoding : utf-8 -*- +# -*- encoding : ASCII-8BIT -*- # # = Introduction # diff --git a/lib/mapi/rtf.rb b/lib/mapi/rtf.rb index 8651a71..8a34467 100644 --- a/lib/mapi/rtf.rb +++ b/lib/mapi/rtf.rb @@ -1,4 +1,4 @@ -# -*- encoding : utf-8 -*- +# -*- encoding : ASCII-8BIT -*- require 'stringio' require 'strscan' diff --git a/lib/mapi/types.rb b/lib/mapi/types.rb index c802682..cbf6092 100644 --- a/lib/mapi/types.rb +++ b/lib/mapi/types.rb @@ -1,4 +1,4 @@ -# -*- encoding : utf-8 -*- +# -*- encoding : ASCII-8BIT -*- require 'rubygems' require 'ole/types' diff --git a/lib/mapi/version.rb b/lib/mapi/version.rb index 689b454..e2c4f06 100644 --- a/lib/mapi/version.rb +++ b/lib/mapi/version.rb @@ -1,4 +1,4 @@ -# -*- encoding : utf-8 -*- +# -*- encoding : ASCII-8BIT -*- module Mapi VERSION = '1.5.2' end diff --git a/ruby-msg.gemspec b/ruby-msg.gemspec index 438e9d1..e0dc99a 100644 --- a/ruby-msg.gemspec +++ b/ruby-msg.gemspec @@ -21,14 +21,6 @@ Gem::Specification.new do |s| s.files += Dir.glob('test/test_*.rb') s.files += Dir.glob('bin/*') - s.has_rdoc = true - s.extra_rdoc_files = ['README', 'ChangeLog'] - s.rdoc_options += [ - '--main', 'README', - '--title', "#{PKG_NAME} documentation", - '--tab-width', '2' - ] - s.add_dependency 'ruby-ole', '>=1.2.8' s.add_dependency 'vpim', '>=0.360' end diff --git a/test/test_convert_contact.rb b/test/test_convert_contact.rb index b37c529..1466572 100644 --- a/test/test_convert_contact.rb +++ b/test/test_convert_contact.rb @@ -1,4 +1,4 @@ -# -*- encoding : utf-8 -*- +# -*- encoding : ASCII-8BIT -*- require 'test/unit' $:.unshift File.dirname(__FILE__) + '/../lib' diff --git a/test/test_convert_note.rb b/test/test_convert_note.rb index 09c9981..8aabccb 100644 --- a/test/test_convert_note.rb +++ b/test/test_convert_note.rb @@ -1,4 +1,4 @@ -# -*- encoding : utf-8 -*- +# -*- encoding : ASCII-8BIT -*- require 'test/unit' $:.unshift File.dirname(__FILE__) + '/../lib' diff --git a/test/test_mime.rb b/test/test_mime.rb index 124d428..e597d88 100644 --- a/test/test_mime.rb +++ b/test/test_mime.rb @@ -1,4 +1,4 @@ -# -*- encoding : utf-8 -*- +# -*- encoding : ASCII-8BIT -*- #! /usr/bin/ruby -w $: << File.dirname(__FILE__) + '/../lib' diff --git a/test/test_msg.rb b/test/test_msg.rb index e5435bc..ed52f0e 100644 --- a/test/test_msg.rb +++ b/test/test_msg.rb @@ -1,4 +1,4 @@ -# -*- encoding : utf-8 -*- +# -*- encoding : ASCII-8BIT -*- #! /usr/bin/ruby TEST_DIR = File.dirname __FILE__ @@ -9,39 +9,36 @@ require 'mapi/convert' class TestMsg < Test::Unit::TestCase - def test_blammo - Mapi::Msg.open "#{TEST_DIR}/test_Blammo.msg" do |msg| - assert_equal '"TripleNickel" ', msg.from - assert_equal 'BlammoBlammo', msg.subject - assert_equal 0, msg.recipients.length - assert_equal 0, msg.attachments.length - # this is all properties - assert_equal 66, msg.properties.raw.length - # this is unique named properties - assert_equal 48, msg.properties.to_h.length - # test accessing the named property keys - same name but different namespace - assert_equal 'Yippee555', msg.props['Name4', Ole::Types::Clsid.parse('55555555-5555-5555-c000-000000000046')] - assert_equal 'Yippee666', msg.props['Name4', Ole::Types::Clsid.parse('66666666-6666-6666-c000-000000000046')] - end - end + def test_blammo + Mapi::Msg.open "#{TEST_DIR}/test_Blammo.msg" do |msg| + assert_equal '"TripleNickel" ', msg.from + assert_equal 'BlammoBlammo', msg.subject + assert_equal 0, msg.recipients.length + assert_equal 0, msg.attachments.length + # this is all properties + assert_equal 66, msg.properties.raw.length + # this is unique named properties + assert_equal 48, msg.properties.to_h.length + # test accessing the named property keys - same name but different namespace + assert_equal 'Yippee555', msg.props['Name4', Ole::Types::Clsid.parse('55555555-5555-5555-c000-000000000046')] + assert_equal 'Yippee666', msg.props['Name4', Ole::Types::Clsid.parse('66666666-6666-6666-c000-000000000046')] + end + end - def test_rtf_to_html_returns_valid_utf8 - msg = Mapi::Msg.open "#{TEST_DIR}/multipart-with-html.msg" do |msg| - assert_equal 1, msg.recipients.length - assert_equal 3, msg.attachments.length - html_part = msg.to_mime.parts[0].parts[1].to_s - if html_part.respond_to?(:encoding) - assert_equal 'UTF-8', html_part.encoding.to_s - assert html_part.valid_encoding? - end - end - end + def test_rendered_string_is_valid_encoding + msg = Mapi::Msg.open "#{TEST_DIR}/multipart-with-html.msg" do |msg| + string_version = msg.to_mime.to_s + if string_version.respond_to?(:valid_encoding?) + assert_equal true, string_version.valid_encoding? + end + end + end - def test_embedded_msg_renders_as_string - msg = Mapi::Msg.open "#{TEST_DIR}/embedded.msg" do |msg| - assert_match "message/rfc822", msg.to_mime.to_s - end - end + def test_embedded_msg_renders_as_string + msg = Mapi::Msg.open "#{TEST_DIR}/embedded.msg" do |msg| + assert_match "message/rfc822", msg.to_mime.to_s + end + end end diff --git a/test/test_property_set.rb b/test/test_property_set.rb index bd6b85b..a34451b 100644 --- a/test/test_property_set.rb +++ b/test/test_property_set.rb @@ -1,4 +1,4 @@ -# -*- encoding : utf-8 -*- +# -*- encoding : ASCII-8BIT -*- require 'test/unit' $:.unshift File.dirname(__FILE__) + '/../lib' diff --git a/test/test_types.rb b/test/test_types.rb index fc9c94f..4353fcf 100644 --- a/test/test_types.rb +++ b/test/test_types.rb @@ -1,4 +1,4 @@ -# -*- encoding : utf-8 -*- +# -*- encoding : ASCII-8BIT -*- require 'test/unit' $:.unshift File.dirname(__FILE__) + '/../lib'