tinnef 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,21 +1,4 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.8.6
3
+ - 1.8.7
4
+ - 1.9.2
5
+ before_script:
6
+ - "sudo apt-get install tnef -y"
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in tinnef.gemspec
4
+ gemspec
@@ -1,4 +1,5 @@
1
- Copyright (c) 2009 Georg Ledermann
1
+ Copyright (c) 2010-2011 Georg Ledermann
2
+ based on the work of Peter Collingbourne
2
3
 
3
4
  Permission is hereby granted, free of charge, to any person obtaining
4
5
  a copy of this software and associated documentation files (the
@@ -0,0 +1,96 @@
1
+ # tinnef
2
+
3
+ [![Build Status](http://travis-ci.org/ledermann/tinnef.png)](http://travis-ci.org/ledermann/tinnef)
4
+
5
+ This gem handles e-mail attachments packaged in the Microsoft "application/ms-tnef" MIME type. It's a Ruby wrapper for the [tnef converter](http://tnef.sourceforge.net).
6
+
7
+ From [Wikipedia](http://en.wikipedia.org/wiki/Transport_Neutral_Encapsulation_Format): "Transport Neutral Encapsulation Format or TNEF is, despite the name, a proprietary E-mail attachment format used by Microsoft Outlook and Microsoft Exchange Server. An attached file with TNEF encoding is most often named winmail.dat or win.dat, and has a MIME type of Application/MS-TNEF."
8
+
9
+
10
+ ## Requirements
11
+
12
+ ### Ruby
13
+
14
+ Tested with Ruby 1.8.6, 1.8.7 and 1.9.2.
15
+
16
+ ### tnef
17
+
18
+ The binary of tnef is required in a current version, 1.4.6 is ok. Check if this tool already exists on your machine:
19
+
20
+ tnef --version
21
+
22
+ It doesn't exist? You can install it:
23
+
24
+ #### Mac OS X
25
+
26
+ Using Homebrew, just do:
27
+
28
+ brew install tnef
29
+
30
+ Using MacPorts, just do:
31
+
32
+ sudo ports install tnef
33
+
34
+ #### Linux
35
+
36
+ There are chances that this will work:
37
+
38
+ apt-get install tnef
39
+
40
+ Beware: On older Linux distribution, you will get a too old version of tnef, which does not work (e.g. 1.4.3 in Ubuntu Hardy), so you have to compile it by yourself. It's easy:
41
+
42
+ wget http://sourceforge.net/projects/tnef/files/tnef/v1.4.7/tnef-1.4.7.tar.gz/download
43
+ tar -xzvf tnef-1.4.7.tar.gz
44
+ cd tnef-1.4.7
45
+ ./configure
46
+ make
47
+ make check
48
+ make install
49
+
50
+ #### Windows
51
+
52
+ What? I don't think this gem will work on Windows.
53
+
54
+
55
+ ## Installation
56
+
57
+ gem install tinnef
58
+
59
+ ## Usage
60
+
61
+ The gem defines the class TNEF with a class method to convert a given winmail.dat file. Use it with a block like in the following example:
62
+
63
+ require 'rubygems'
64
+ require 'tinnef'
65
+
66
+ content = File.new('winmail.dat').read
67
+ TNEF.convert(content, :command => '/opt/local/bin/tnef') do |temp_file|
68
+ unpacked_content = temp_file.read
69
+ unpacked_filename = File.basename(temp_file.path)
70
+
71
+ File.open("/some/path/#{unpacked_filename}", 'w') do |new_file|
72
+ new_file.write(unpacked_content)
73
+ end
74
+ end
75
+
76
+
77
+ ## About the naming of this gem
78
+
79
+ "Tinnef" is a german slang word for "rubbish" or "trash". TNEF => TiNnEF => Tinnef - you know?
80
+
81
+ ## Note on Patches/Pull Requests
82
+
83
+ * Fork the project.
84
+ * Make your feature addition or bug fix.
85
+ * Add tests for it. This is important so I don't break it in a
86
+ future version unintentionally.
87
+ * Commit, do not mess with rakefile, version, or history.
88
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
89
+ * Send me a pull request. Bonus points for topic branches.
90
+
91
+ ## Copyright
92
+
93
+ This code is based on the work by Peter Collingbourne, published as part of the [alaveteli](https://github.com/sebbacon/alaveteli/blob/master/lib/tnef.rb) project.
94
+ Thank you for sharing!
95
+
96
+ Copyright (c) 2010-2011 Georg Ledermann. See MIT-LICENSE for details.
data/Rakefile CHANGED
@@ -1,52 +1,15 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "tinnef"
8
- gem.summary = %Q{Ruby wrapper for tnef, a tool for unpacking 'winmail.dat' files}
9
- gem.description = %Q{Handling e-mail attachments coming with MIME type 'application/ms-tnef' }
10
- gem.email = "ledermann@dipl-wirt-inf.de"
11
- gem.homepage = "http://github.com/ledermann/tinnef"
12
- gem.authors = ["Georg Ledermann"]
13
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
- end
15
- Jeweler::GemcutterTasks.new
16
- rescue LoadError
17
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
18
- end
1
+ require 'bundler/gem_tasks'
19
2
 
3
+ require 'rake'
20
4
  require 'rake/testtask'
21
- Rake::TestTask.new(:test) do |test|
22
- test.libs << 'lib' << 'test'
23
- test.pattern = 'test/**/test_*.rb'
24
- test.verbose = true
25
- end
26
-
27
- begin
28
- require 'rcov/rcovtask'
29
- Rcov::RcovTask.new do |test|
30
- test.libs << 'test'
31
- test.pattern = 'test/**/test_*.rb'
32
- test.verbose = true
33
- end
34
- rescue LoadError
35
- task :rcov do
36
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
- end
38
- end
39
-
40
- task :test => :check_dependencies
41
5
 
6
+ desc 'Default: run unit tests.'
42
7
  task :default => :test
43
8
 
44
- require 'rake/rdoctask'
45
- Rake::RDocTask.new do |rdoc|
46
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
-
48
- rdoc.rdoc_dir = 'rdoc'
49
- rdoc.title = "tinnef #{version}"
50
- rdoc.rdoc_files.include('README*')
51
- rdoc.rdoc_files.include('lib/**/*.rb')
52
- end
9
+ desc 'Test the tinnef gem.'
10
+ Rake::TestTask.new(:test) do |t|
11
+ t.libs << 'lib'
12
+ t.libs << 'test'
13
+ t.pattern = 'test/**/*_test.rb'
14
+ t.verbose = true
15
+ end
@@ -1,26 +1,54 @@
1
1
  require 'tinnef/dir_patch'
2
2
 
3
3
  class TNEF
4
+ # = convert
5
+ #
6
+ # Extract the content of a winmail.dat file and
7
+ # executes the given block for every single file in it
8
+ #
9
+ # Parameters:
10
+ # content => Content of the winmail.dat file
11
+ #
12
+ # Options hash with this keys:
13
+ # :command
14
+ # Full path of the tnf binary to execute (defaults to 'tnf', so it has to be in the path)
15
+ #
16
+ # Example:
17
+ # content = File.new('winmail.dat').read
18
+ # TNEF.convert(content, :command => '/opt/local/bin/tnef') do |temp_file|
19
+ # unpacked_content = temp_file.read
20
+ # unpacked_filename = File.basename(temp_file.path)
21
+ #
22
+ # File.open("/some/path/#{unpacked_filename}", 'w') do |new_file|
23
+ # new_file.write(unpacked_content)
24
+ # end
25
+ # end
4
26
  def self.convert(content, options={}, &block)
5
- command = options[:command] || 'tnef'
6
-
7
27
  Dir.mktmpdir do |dir|
8
- IO.popen("#{command} -K -C #{dir}", "w") do |f|
9
- f.write(content)
10
- f.close
11
- if $?.signaled?
12
- raise IOError, "tnef exited with signal #{$?.termsig}"
13
- end
14
- if $?.exited? && $?.exitstatus != 0
15
- raise IOError, "tnef exited with status #{$?.exitstatus}"
28
+ file_names = extract(content, options.merge(:dir => dir))
29
+ file_names.each do |file_name|
30
+ File.open("#{dir}/#{file_name}", "r") do |file|
31
+ yield(file)
16
32
  end
17
33
  end
18
- Dir.new(dir).sort.each do |file_name| # sort for deterministic behaviour
19
- if file_name != "." && file_name != ".."
20
- file = File.open("#{dir}/#{file_name}", "r")
21
- block.call(file)
22
- end
34
+ end
35
+ end
36
+
37
+ def self.extract(content, options={})
38
+ command = options[:command] || 'tnef'
39
+ dir = options[:dir]
40
+
41
+ IO.popen("#{command} -K -C #{dir}", "w") do |f|
42
+ f.write(content)
43
+ f.close
44
+ if $?.signaled?
45
+ raise IOError, "tnef exited with signal #{$?.termsig}"
46
+ end
47
+ if $?.exited? && $?.exitstatus != 0
48
+ raise IOError, "tnef exited with status #{$?.exitstatus}"
23
49
  end
24
50
  end
51
+
52
+ Dir.new(dir).sort.delete_if { |file_name| File.directory?(file_name) }
25
53
  end
26
54
  end
@@ -0,0 +1,3 @@
1
+ module Tinnef
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'mocha'
4
+
5
+ require File.dirname(__FILE__) + '/../lib/tinnef'
@@ -0,0 +1,43 @@
1
+ require 'test_helper'
2
+
3
+ class TestDir < Test::Unit::TestCase
4
+ def test_mktmpdir_path
5
+ dir = Dir.mktmpdir
6
+
7
+ assert File.directory?(dir)
8
+ assert_equal true, File.directory?(dir)
9
+ end
10
+
11
+ def test_mktmpdir_block
12
+ directory = ''
13
+ Dir.mktmpdir do |dir|
14
+ directory = dir
15
+ end
16
+
17
+ assert !File.directory?(directory)
18
+ assert_equal false, File.directory?(directory)
19
+ end
20
+ end
21
+
22
+ class TestTinnef < Test::Unit::TestCase
23
+ def setup
24
+ @content = File.new(File.dirname(__FILE__) + '/fixtures/quick-winmail.dat').read
25
+ end
26
+
27
+ def test_file_names
28
+ files = []
29
+ TNEF.convert(@content) do |temp_file|
30
+ files << File.basename(temp_file.path)
31
+ end
32
+
33
+ assert_equal %w(quick.doc quick.html quick.pdf quick.txt quick.xml), files
34
+ end
35
+
36
+ def test_content
37
+ TNEF.convert(@content) do |temp_file|
38
+ if File.basename(temp_file.path) == 'quick.txt'
39
+ assert_match /The quick brown fox jumps over the lazy dog/, temp_file.read
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,52 +1,23 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "tinnef/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{tinnef}
8
- s.version = "0.1.0"
6
+ s.name = 'tinnef'
7
+ s.version = Tinnef::VERSION
8
+ s.authors = ["Georg Ledermann"]
9
+ s.email = ["mail@georg-ledermann.de"]
10
+ s.homepage = ""
11
+ s.summary = %q{Ruby wrapper for tnef, a tool for unpacking 'winmail.dat' files}
12
+ s.description = %q{Handling e-mail attachments with MIME type 'application/ms-tnef'}
9
13
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Georg Ledermann"]
12
- s.date = %q{2010-05-18}
13
- s.description = %q{Handling e-mail attachments coming with MIME type 'application/ms-tnef' }
14
- s.email = %q{ledermann@dipl-wirt-inf.de}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "lib/tinnef.rb",
27
- "lib/tinnef/dir_patch.rb",
28
- "test/helper.rb",
29
- "test/test_tinnef.rb",
30
- "tinnef.gemspec"
31
- ]
32
- s.homepage = %q{http://github.com/ledermann/tinnef}
33
- s.rdoc_options = ["--charset=UTF-8"]
34
- s.require_paths = ["lib"]
35
- s.rubygems_version = %q{1.3.7}
36
- s.summary = %q{Ruby wrapper for tnef, a tool for unpacking 'winmail.dat' files}
37
- s.test_files = [
38
- "test/helper.rb",
39
- "test/test_tinnef.rb"
40
- ]
41
-
42
- if s.respond_to? :specification_version then
43
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
- s.specification_version = 3
14
+ s.rubyforge_project = "."
45
15
 
46
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
- else
48
- end
49
- else
50
- end
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency 'rake'
22
+ s.add_development_dependency 'mocha'
51
23
  end
52
-
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tinnef
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease: false
4
+ hash: 25
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Georg Ledermann
@@ -15,38 +15,66 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-05-18 00:00:00 +02:00
19
- default_executable:
20
- dependencies: []
21
-
22
- description: "Handling e-mail attachments coming with MIME type 'application/ms-tnef' "
23
- email: ledermann@dipl-wirt-inf.de
18
+ date: 2011-08-25 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rake
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: mocha
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :development
47
+ version_requirements: *id002
48
+ description: Handling e-mail attachments with MIME type 'application/ms-tnef'
49
+ email:
50
+ - mail@georg-ledermann.de
24
51
  executables: []
25
52
 
26
53
  extensions: []
27
54
 
28
- extra_rdoc_files:
29
- - LICENSE
30
- - README.rdoc
55
+ extra_rdoc_files: []
56
+
31
57
  files:
32
58
  - .document
33
59
  - .gitignore
34
- - LICENSE
35
- - README.rdoc
60
+ - .travis.yml
61
+ - Gemfile
62
+ - MIT-LICENSE
63
+ - README.md
36
64
  - Rakefile
37
- - VERSION
38
65
  - lib/tinnef.rb
39
66
  - lib/tinnef/dir_patch.rb
40
- - test/helper.rb
41
- - test/test_tinnef.rb
67
+ - lib/tinnef/version.rb
68
+ - test/fixtures/quick-winmail.dat
69
+ - test/test_helper.rb
70
+ - test/tinnef_test.rb
42
71
  - tinnef.gemspec
43
- has_rdoc: true
44
- homepage: http://github.com/ledermann/tinnef
72
+ homepage: ""
45
73
  licenses: []
46
74
 
47
75
  post_install_message:
48
- rdoc_options:
49
- - --charset=UTF-8
76
+ rdoc_options: []
77
+
50
78
  require_paths:
51
79
  - lib
52
80
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -69,11 +97,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
97
  version: "0"
70
98
  requirements: []
71
99
 
72
- rubyforge_project:
73
- rubygems_version: 1.3.7
100
+ rubyforge_project: .
101
+ rubygems_version: 1.8.6
74
102
  signing_key:
75
103
  specification_version: 3
76
104
  summary: Ruby wrapper for tnef, a tool for unpacking 'winmail.dat' files
77
105
  test_files:
78
- - test/helper.rb
79
- - test/test_tinnef.rb
106
+ - test/fixtures/quick-winmail.dat
107
+ - test/test_helper.rb
108
+ - test/tinnef_test.rb
@@ -1,108 +0,0 @@
1
- = tinnef
2
-
3
- This gem handles e-mail attachments packaged in the Microsoft "application/ms-tnef" MIME type. It's a Ruby wrapper for the 'tnef' converter from http://tnef.sourceforge.net/
4
-
5
- From Wikipedia: "Transport Neutral Encapsulation Format or TNEF is, despite the name, a proprietary E-mail attachment format used by Microsoft Outlook and Microsoft Exchange Server. An attached file with TNEF encoding is most often named winmail.dat or win.dat, and has a MIME type of Application/MS-TNEF."
6
- http://en.wikipedia.org/wiki/Transport_Neutral_Encapsulation_Format
7
-
8
-
9
- == Requirements
10
-
11
- === Ruby
12
-
13
- Ruby 1.8.6 or 1.8.7 is required. It's not tested with 1.9.
14
-
15
- === tnef
16
-
17
- The binary of tnef in a recent version is required, 1.4.6 is ok. Check if this tool already exists on your machine:
18
-
19
- tnef --version
20
-
21
- It doesn't exist? You can install it:
22
-
23
- ==== Mac OS X
24
-
25
- Using MacPorts, just do:
26
-
27
- sudo ports install tnef
28
-
29
- ==== Linux
30
-
31
- There are chances that this will work:
32
-
33
- apt-get install tnef
34
-
35
- Beware: On older Linux distribution, you will get a too old version of tnef, which does not work (e.g. 1.4.3 in Ubuntu hardy), so have to compile it by yourself. It's easy:
36
-
37
- wget http://sourceforge.net/projects/tnef/files/tnef/v1.4.7/tnef-1.4.7.tar.gz/download
38
- tar -xzvf tnef-1.4.7.tar.gz
39
- cd tnef-1.4.7
40
- ./configure
41
- make
42
- make check
43
- make install
44
-
45
- ==== Windows
46
-
47
- What? I don't think this gem will work on Windows.
48
-
49
-
50
- == Installation
51
-
52
- In Rails, add this to your environment.rb:
53
-
54
- config.gem 'tinnef'
55
-
56
- Then run
57
-
58
- rake gems:install
59
-
60
- or
61
-
62
- gem install tinnef
63
-
64
- == Usage
65
-
66
- The gem defines the class TNEF with just one class method to converta given winmail.dat file. Use it like in the following example:
67
-
68
- require 'rubygems'
69
- require 'tinnef'
70
-
71
- content = File.new('winmail.dat').read
72
- TNEF.convert(content, :command => '/opt/local/bin/tnef') do |temp_file|
73
- unpacked_content = temp_file.read
74
- unpacked_filename = File.basename(temp_file.path)
75
-
76
- File.open("/some/path/#{unpacked_filename}", 'w') do |new_file|
77
- new_file.write(unpacked_content)
78
- end
79
- end
80
-
81
-
82
- == About the naming of this gem
83
-
84
- "Tinnef" is a german slang word for "rubbish" or "trash". TNEF => TiNnEF => Tinnef - you know?
85
-
86
-
87
- == TODO
88
-
89
- * Add some tests
90
-
91
-
92
- == Note on Patches/Pull Requests
93
-
94
- * Fork the project.
95
- * Make your feature addition or bug fix.
96
- * Add tests for it. This is important so I don't break it in a
97
- future version unintentionally.
98
- * Commit, do not mess with rakefile, version, or history.
99
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
100
- * Send me a pull request. Bonus points for topic branches.
101
-
102
- == Copyright
103
-
104
- This code is based on the work by Peter Collingbourne, published as part of the project "whatdotheyknow":
105
- http://github.com/mysociety/whatdotheyknow/blob/master/lib/tnef.rb
106
- Thank you for sharing!
107
-
108
- Copyright (c) 2010 Georg Ledermann. See LICENSE for details.
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.0
@@ -1,9 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
-
4
- $LOAD_PATH.unshift(File.dirname(__FILE__))
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
- require 'tinnef'
7
-
8
- class Test::Unit::TestCase
9
- end
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestTinnef < Test::Unit::TestCase
4
- def test_something_for_real
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end