tinnef 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +108 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/lib/tinnef.rb +26 -0
- data/lib/tinnef/dir_patch.rb +49 -0
- data/test/helper.rb +9 -0
- data/test/test_tinnef.rb +7 -0
- data/tinnef.gemspec +52 -0
- metadata +79 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Georg Ledermann
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,108 @@
|
|
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/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
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
|
19
|
+
|
20
|
+
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
|
+
|
42
|
+
task :default => :test
|
43
|
+
|
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
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/lib/tinnef.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'tinnef/dir_patch'
|
2
|
+
|
3
|
+
class TNEF
|
4
|
+
def self.convert(content, options={}, &block)
|
5
|
+
command = options[:command] || 'tnef'
|
6
|
+
|
7
|
+
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}"
|
16
|
+
end
|
17
|
+
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
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'dir'
|
2
|
+
require 'tmpdir'
|
3
|
+
|
4
|
+
#
|
5
|
+
# Dir.mktmpdir is missing in Ruby 1.8.6 patchlevel 111, so monkeypatch it from
|
6
|
+
# http://www.ruby-doc.org/core-1.9/classes/Dir.src/M002362.html
|
7
|
+
#
|
8
|
+
unless Dir.respond_to?(:mktmpdir)
|
9
|
+
class Dir
|
10
|
+
def self.mktmpdir(prefix_suffix=nil, tmpdir=nil)
|
11
|
+
case prefix_suffix
|
12
|
+
when nil
|
13
|
+
prefix = "d"
|
14
|
+
suffix = ""
|
15
|
+
when String
|
16
|
+
prefix = prefix_suffix
|
17
|
+
suffix = ""
|
18
|
+
when Array
|
19
|
+
prefix = prefix_suffix[0]
|
20
|
+
suffix = prefix_suffix[1]
|
21
|
+
else
|
22
|
+
raise ArgumentError, "unexpected prefix_suffix: #{prefix_suffix.inspect}"
|
23
|
+
end
|
24
|
+
tmpdir ||= Dir.tmpdir
|
25
|
+
t = Time.now.strftime("%Y%m%d")
|
26
|
+
n = nil
|
27
|
+
begin
|
28
|
+
path = "#{tmpdir}/#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
|
29
|
+
path << "-#{n}" if n
|
30
|
+
path << suffix
|
31
|
+
Dir.mkdir(path, 0700)
|
32
|
+
rescue Errno::EEXIST
|
33
|
+
n ||= 0
|
34
|
+
n += 1
|
35
|
+
retry
|
36
|
+
end
|
37
|
+
|
38
|
+
if block_given?
|
39
|
+
begin
|
40
|
+
yield path
|
41
|
+
ensure
|
42
|
+
FileUtils.remove_entry_secure path
|
43
|
+
end
|
44
|
+
else
|
45
|
+
path
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/test/helper.rb
ADDED
data/test/test_tinnef.rb
ADDED
data/tinnef.gemspec
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{tinnef}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
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
|
45
|
+
|
46
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
|
+
else
|
48
|
+
end
|
49
|
+
else
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tinnef
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Georg Ledermann
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
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
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- LICENSE
|
30
|
+
- README.rdoc
|
31
|
+
files:
|
32
|
+
- .document
|
33
|
+
- .gitignore
|
34
|
+
- LICENSE
|
35
|
+
- README.rdoc
|
36
|
+
- Rakefile
|
37
|
+
- VERSION
|
38
|
+
- lib/tinnef.rb
|
39
|
+
- lib/tinnef/dir_patch.rb
|
40
|
+
- test/helper.rb
|
41
|
+
- test/test_tinnef.rb
|
42
|
+
- tinnef.gemspec
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: http://github.com/ledermann/tinnef
|
45
|
+
licenses: []
|
46
|
+
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options:
|
49
|
+
- --charset=UTF-8
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
hash: 3
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
70
|
+
requirements: []
|
71
|
+
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 1.3.7
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: Ruby wrapper for tnef, a tool for unpacking 'winmail.dat' files
|
77
|
+
test_files:
|
78
|
+
- test/helper.rb
|
79
|
+
- test/test_tinnef.rb
|