Skip to content

Commit

Permalink
Import
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Feb 17, 2017
0 parents commit b4268bf
Show file tree
Hide file tree
Showing 10 changed files with 739 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/doc/reference/
/.yardoc/
/pkg/
/Gemfile.lock
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
notifications:
email:
recipients:
- [email protected]
rvm:
- 2.2
- 2.3.3
- 2.4.0
5 changes: 5 additions & 0 deletions .yardopts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--output-dir doc/reference/en
--markup markdown
--markup-provider kramdown
-
doc/text/*
27 changes: 27 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- ruby -*-
#
# Copyright (C) 2017 Kouhei Sutou <[email protected]>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

source "https://rubygems.org/"

gemspec

base_dir = File.dirname(__FILE__)
local_chupa_text_dir = File.join(base_dir, "..", "chupa-text")
if File.exist?(local_chupa_text_dir)
gem "chupa-text", :path => local_chupa_text_dir
end
502 changes: 502 additions & 0 deletions LICENSE.txt

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# README

## Name

chupa-text-decomposer-mail

## Description

This is a ChupaText decomposer plugin for to extract text and
meta-data from RFC 2822 formatted e-mail.

You can use `mail` decomposer.

## Install

Install chupa-text-decomposer-mail gem:

```
% gem install chupa-text-decomposer-mail
```

Now, you can extract text and meta-data from e-mail:

```
% chupa-text document.eml
```

## Author

* Kouhei Sutou `<[email protected]>`

## License

LGPL 2.1 or later.

(Kouhei Sutou has a right to change the license including contributed
patches.)
46 changes: 46 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# -*- ruby -*-
#
# Copyright (C) 2017 Kouhei Sutou <[email protected]>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

task :default => :test

require "pathname"

require "rubygems"
require "bundler/gem_helper"
require "packnga"

base_dir = Pathname(__FILE__).dirname

helper = Bundler::GemHelper.new(base_dir.to_s)
def helper.version_tag
version
end

helper.install
spec = helper.gemspec

Packnga::DocumentTask.new(spec) do
end

Packnga::ReleaseTask.new(spec) do
end

desc "Run tests"
task :test do
ruby("test/run-test.rb")
end
50 changes: 50 additions & 0 deletions chupa-text-decomposer-mail.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# -*- ruby -*-
#
# Copyright (C) 2017 Kouhei Sutou <[email protected]>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

clean_white_space = lambda do |entry|
entry.gsub(/(\A\n+|\n+\z)/, '') + "\n"
end

Gem::Specification.new do |spec|
spec.name = "chupa-text-decomposer-mail"
spec.version = "1.0.0"
spec.homepage = "https://github.com/ranguba/chupa-text-decomposer-mail"
spec.authors = ["Kouhei Sutou"]
spec.email = ["[email protected]"]
readme = File.read("README.md", :encoding => "UTF-8")
entries = readme.split(/^\#\#\s(.*)$/)
description = clean_white_space.call(entries[entries.index("Description") + 1])
spec.summary = description.split(/\n\n+/, 2).first
spec.description = description
spec.license = "LGPL-2.1+"
spec.files = ["#{spec.name}.gemspec"]
spec.files += ["README.md", "LICENSE.txt", "Rakefile", "Gemfile"]
spec.files += [".yardopts"]
spec.files += Dir.glob("lib/**/*.rb")
spec.files += Dir.glob("doc/text/*")
spec.files += Dir.glob("test/**/*")

spec.add_runtime_dependency("chupa-text")
spec.add_runtime_dependency("mail")

spec.add_development_dependency("bundler")
spec.add_development_dependency("rake")
spec.add_development_dependency("test-unit")
spec.add_development_dependency("packnga")
spec.add_development_dependency("kramdown")
end
5 changes: 5 additions & 0 deletions doc/text/news.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# News

## 1.0.0: 2017-XX-XX

The first release!!!
55 changes: 55 additions & 0 deletions lib/chupa-text/decomposers/mail.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright (C) 2017 Kouhei Sutou <[email protected]>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

require "time"

require "mail"

module ChupaText
module Decomposers
class Mail < Decomposer
registry.register("mail", self)

TARGET_EXTENSIONS = ["eml", "mew"]
TARGET_MIME_TYPES = ["message/rfc822"]
def target?(data)
return true if TARGET_MIME_TYPES.include?(data.mime_type)
return false unless TARGET_EXTENSIONS.include?(data.extension)

data.uri.fragment.nil?
end

def decompose(data)
mail = ::Mail.new(data.body)
mail.body.parts.each_with_index do |part, i|
body = part.body.decoded
body.force_encoding(part.charset)

part_data = TextData.new(body)
part_data.uri = "#{data.uri}\##{i}"
part_data.mime_type = part.mime_type
data.attributes.each do |name, value|
part_data[name] = value
end
part_data[:encoding] = body.encoding.to_s
part_data[:subject] = mail.subject
part_data[:author] = mail[:from].formatted | mail[:from].addresses
yield(part_data)
end
end
end
end
end

0 comments on commit b4268bf

Please sign in to comment.