Skip to content

Commit b4268bf

Browse files
committed
Import
0 parents  commit b4268bf

File tree

10 files changed

+739
-0
lines changed

10 files changed

+739
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/doc/reference/
2+
/.yardoc/
3+
/pkg/
4+
/Gemfile.lock

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
notifications:
2+
email:
3+
recipients:
4+
5+
rvm:
6+
- 2.2
7+
- 2.3.3
8+
- 2.4.0

.yardopts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
--output-dir doc/reference/en
2+
--markup markdown
3+
--markup-provider kramdown
4+
-
5+
doc/text/*

Gemfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- ruby -*-
2+
#
3+
# Copyright (C) 2017 Kouhei Sutou <[email protected]>
4+
#
5+
# This library is free software; you can redistribute it and/or
6+
# modify it under the terms of the GNU Lesser General Public
7+
# License as published by the Free Software Foundation; either
8+
# version 2.1 of the License, or (at your option) any later version.
9+
#
10+
# This library is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
# Lesser General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU Lesser General Public
16+
# License along with this library; if not, write to the Free Software
17+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
19+
source "https://rubygems.org/"
20+
21+
gemspec
22+
23+
base_dir = File.dirname(__FILE__)
24+
local_chupa_text_dir = File.join(base_dir, "..", "chupa-text")
25+
if File.exist?(local_chupa_text_dir)
26+
gem "chupa-text", :path => local_chupa_text_dir
27+
end

LICENSE.txt

Lines changed: 502 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# README
2+
3+
## Name
4+
5+
chupa-text-decomposer-mail
6+
7+
## Description
8+
9+
This is a ChupaText decomposer plugin for to extract text and
10+
meta-data from RFC 2822 formatted e-mail.
11+
12+
You can use `mail` decomposer.
13+
14+
## Install
15+
16+
Install chupa-text-decomposer-mail gem:
17+
18+
```
19+
% gem install chupa-text-decomposer-mail
20+
```
21+
22+
Now, you can extract text and meta-data from e-mail:
23+
24+
```
25+
% chupa-text document.eml
26+
```
27+
28+
## Author
29+
30+
* Kouhei Sutou `<[email protected]>`
31+
32+
## License
33+
34+
LGPL 2.1 or later.
35+
36+
(Kouhei Sutou has a right to change the license including contributed
37+
patches.)

Rakefile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# -*- ruby -*-
2+
#
3+
# Copyright (C) 2017 Kouhei Sutou <[email protected]>
4+
#
5+
# This library is free software; you can redistribute it and/or
6+
# modify it under the terms of the GNU Lesser General Public
7+
# License as published by the Free Software Foundation; either
8+
# version 2.1 of the License, or (at your option) any later version.
9+
#
10+
# This library is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
# Lesser General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU Lesser General Public
16+
# License along with this library; if not, write to the Free Software
17+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
19+
task :default => :test
20+
21+
require "pathname"
22+
23+
require "rubygems"
24+
require "bundler/gem_helper"
25+
require "packnga"
26+
27+
base_dir = Pathname(__FILE__).dirname
28+
29+
helper = Bundler::GemHelper.new(base_dir.to_s)
30+
def helper.version_tag
31+
version
32+
end
33+
34+
helper.install
35+
spec = helper.gemspec
36+
37+
Packnga::DocumentTask.new(spec) do
38+
end
39+
40+
Packnga::ReleaseTask.new(spec) do
41+
end
42+
43+
desc "Run tests"
44+
task :test do
45+
ruby("test/run-test.rb")
46+
end

chupa-text-decomposer-mail.gemspec

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# -*- ruby -*-
2+
#
3+
# Copyright (C) 2017 Kouhei Sutou <[email protected]>
4+
#
5+
# This library is free software; you can redistribute it and/or
6+
# modify it under the terms of the GNU Lesser General Public
7+
# License as published by the Free Software Foundation; either
8+
# version 2.1 of the License, or (at your option) any later version.
9+
#
10+
# This library is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
# Lesser General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU Lesser General Public
16+
# License along with this library; if not, write to the Free Software
17+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
19+
clean_white_space = lambda do |entry|
20+
entry.gsub(/(\A\n+|\n+\z)/, '') + "\n"
21+
end
22+
23+
Gem::Specification.new do |spec|
24+
spec.name = "chupa-text-decomposer-mail"
25+
spec.version = "1.0.0"
26+
spec.homepage = "https://github.com/ranguba/chupa-text-decomposer-mail"
27+
spec.authors = ["Kouhei Sutou"]
28+
spec.email = ["[email protected]"]
29+
readme = File.read("README.md", :encoding => "UTF-8")
30+
entries = readme.split(/^\#\#\s(.*)$/)
31+
description = clean_white_space.call(entries[entries.index("Description") + 1])
32+
spec.summary = description.split(/\n\n+/, 2).first
33+
spec.description = description
34+
spec.license = "LGPL-2.1+"
35+
spec.files = ["#{spec.name}.gemspec"]
36+
spec.files += ["README.md", "LICENSE.txt", "Rakefile", "Gemfile"]
37+
spec.files += [".yardopts"]
38+
spec.files += Dir.glob("lib/**/*.rb")
39+
spec.files += Dir.glob("doc/text/*")
40+
spec.files += Dir.glob("test/**/*")
41+
42+
spec.add_runtime_dependency("chupa-text")
43+
spec.add_runtime_dependency("mail")
44+
45+
spec.add_development_dependency("bundler")
46+
spec.add_development_dependency("rake")
47+
spec.add_development_dependency("test-unit")
48+
spec.add_development_dependency("packnga")
49+
spec.add_development_dependency("kramdown")
50+
end

doc/text/news.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# News
2+
3+
## 1.0.0: 2017-XX-XX
4+
5+
The first release!!!

lib/chupa-text/decomposers/mail.rb

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright (C) 2017 Kouhei Sutou <[email protected]>
2+
#
3+
# This library is free software; you can redistribute it and/or
4+
# modify it under the terms of the GNU Lesser General Public
5+
# License as published by the Free Software Foundation; either
6+
# version 2.1 of the License, or (at your option) any later version.
7+
#
8+
# This library is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
# Lesser General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU Lesser General Public
14+
# License along with this library; if not, write to the Free Software
15+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16+
17+
require "time"
18+
19+
require "mail"
20+
21+
module ChupaText
22+
module Decomposers
23+
class Mail < Decomposer
24+
registry.register("mail", self)
25+
26+
TARGET_EXTENSIONS = ["eml", "mew"]
27+
TARGET_MIME_TYPES = ["message/rfc822"]
28+
def target?(data)
29+
return true if TARGET_MIME_TYPES.include?(data.mime_type)
30+
return false unless TARGET_EXTENSIONS.include?(data.extension)
31+
32+
data.uri.fragment.nil?
33+
end
34+
35+
def decompose(data)
36+
mail = ::Mail.new(data.body)
37+
mail.body.parts.each_with_index do |part, i|
38+
body = part.body.decoded
39+
body.force_encoding(part.charset)
40+
41+
part_data = TextData.new(body)
42+
part_data.uri = "#{data.uri}\##{i}"
43+
part_data.mime_type = part.mime_type
44+
data.attributes.each do |name, value|
45+
part_data[name] = value
46+
end
47+
part_data[:encoding] = body.encoding.to_s
48+
part_data[:subject] = mail.subject
49+
part_data[:author] = mail[:from].formatted | mail[:from].addresses
50+
yield(part_data)
51+
end
52+
end
53+
end
54+
end
55+
end

0 commit comments

Comments
 (0)