galakei-email 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +1 -0
- data/galakei-email.gemspec +27 -0
- data/lib/galakei/email/au_mail_interceptor.rb +18 -0
- data/lib/galakei/email/railtie.rb +13 -0
- data/lib/galakei/email/version.rb +5 -0
- data/lib/galakei/email.rb +62 -0
- data/spec/email_spec.rb +87 -0
- data/spec/spec_helper.rb +4 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f5f9d860003f4f5fb3e9ee53baf8a15f014496b5
|
4
|
+
data.tar.gz: 36c9e61cf2ce613aa7a5a5f02ed42b1693285190
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 88a5cc818050dd57b0038928d41429427a2432581700c4715ba67809a16bc6410d0dfc8910bfc2148cc7912c2fa42484d6a867a3de2cab7f8a7b74844b12a615
|
7
|
+
data.tar.gz: 909e822167ac2ab51e81fd4e20986a188ad992123f4152eb465c45b47592f94545be4243d4ee7773ffb938b4c54f189dd27d061a861e76dbde8fa5bc03b7c427
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Paul McMahon
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Galakei::Email
|
2
|
+
|
3
|
+
Japanese carriers provide each mobile subscriber with an email address. The email works basically the same as normal email, but with some caveats. This gem takes care of transforming normal mail into galakei mail.
|
4
|
+
|
5
|
+
This functionality has been extracted from the [galakei](https://github.com/mobalean/galakei) gem.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'galakei-email'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install galakei-email
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'galakei/email/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "galakei-email"
|
8
|
+
spec.version = Galakei::Email::VERSION
|
9
|
+
spec.authors = ["Paul McMahon"]
|
10
|
+
spec.email = ["paul@doorkeeper.jp"]
|
11
|
+
spec.description = %q{Send email to Japanese phones}
|
12
|
+
spec.summary = %q{Japanese carriers provide each mobile subscriber with an email address. The email works basically the same as normal email, but with some caveats. This gem takes care of transforming normal mail into galakei mail.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "nokogiri"
|
22
|
+
spec.add_dependency "activesupport"
|
23
|
+
spec.add_dependency "sanitize"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# au-kddi handsets render html mail properly only when
|
2
|
+
# all mime parts are in a flat multipart/alternate structure
|
3
|
+
class Galakei::Email::AuMailInterceptor # :nodoc:
|
4
|
+
def self.delivering_email(message)
|
5
|
+
if message.to.first =~ /^.+@ezweb\.ne\.jp$/
|
6
|
+
if message.content_type =~ /^multipart\/related/
|
7
|
+
params = message.content_type_parameters || {}
|
8
|
+
message.content_type = ["multipart", "alternative", params]
|
9
|
+
message.parts.each do |part|
|
10
|
+
if part.content_type =~ /^multipart\/alternative/
|
11
|
+
part.parts.each{ |p| message.add_part(p) }
|
12
|
+
message.parts.delete(part)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "galakei/email/au_mail_interceptor"
|
2
|
+
|
3
|
+
module Galakei
|
4
|
+
module Email
|
5
|
+
class Railtie < ::Rails::Railtie
|
6
|
+
initializer "galakei.register.method.for.mail" do
|
7
|
+
ActiveSupport.on_load :action_mailer do
|
8
|
+
ActionMailer::Base.register_interceptor Galakei::Email::AuMailInterceptor
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "galakei/email/version"
|
2
|
+
require "galakei/email/railtie" if defined?(Rails)
|
3
|
+
require "nokogiri"
|
4
|
+
require "active_support/core_ext/object/blank"
|
5
|
+
require "sanitize"
|
6
|
+
|
7
|
+
module Galakei
|
8
|
+
module Email
|
9
|
+
GALAKEI_EMAIL_ADDRESS_PATTERNS = [
|
10
|
+
/^.+@(.+\.)?pdx\.ne\.jp$/,
|
11
|
+
/^.+@ezweb\.ne\.jp$/,
|
12
|
+
/^.+@(?:softbank\.ne\.jp|disney\.ne\.jp)$/,
|
13
|
+
/^.+@[dhtcrknsq]\.vodafone\.ne\.jp$/,
|
14
|
+
/^.+@jp-[dhtcrknsq]\.ne\.jp$/,
|
15
|
+
/^.+@emnet\.ne\.jp$/,
|
16
|
+
/^.+@docomo\.ne\.jp$/ ]
|
17
|
+
|
18
|
+
SANITIZE_OPTIONS = {
|
19
|
+
:elements => %w{font blink marquee br a div hr img},
|
20
|
+
:attributes => {'a' => ['href'],
|
21
|
+
'font' => ['size','color'],
|
22
|
+
'marquee' => ['behaviour'],
|
23
|
+
'hr' => ['color'],
|
24
|
+
'div' => ['align'],
|
25
|
+
'img' => ['src'],
|
26
|
+
},
|
27
|
+
:protocols => {'a' => {'href' => ['http', 'https', 'mailto']}},
|
28
|
+
:whitespace_elements => []
|
29
|
+
}
|
30
|
+
|
31
|
+
TAGS_TO_PROCESS = %w{h1 h2 h3 h4 h5 h6 p}.join(',')
|
32
|
+
|
33
|
+
def self.galakei_email_address?(email)
|
34
|
+
GALAKEI_EMAIL_ADDRESS_PATTERNS.any?{|p| p =~ email }
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.to_galakei_email(html_email)
|
38
|
+
doc = Nokogiri::HTML(html_email)
|
39
|
+
doc.css(TAGS_TO_PROCESS).each do |node|
|
40
|
+
node.name = "div"
|
41
|
+
node.after("<br />")
|
42
|
+
end
|
43
|
+
#empty the <head>
|
44
|
+
doc.css("head").each do |node|
|
45
|
+
node.unlink
|
46
|
+
end
|
47
|
+
doc.css("img").each do |node|
|
48
|
+
if node['src'] !~ /^cid:/
|
49
|
+
node.after(doc.create_text_node(node['alt'])) if node['alt'].present?
|
50
|
+
node.unlink
|
51
|
+
end
|
52
|
+
end
|
53
|
+
encoding = doc.meta_encoding || "UTF-8"
|
54
|
+
res = "<html><head>"
|
55
|
+
res << "<meta http-equiv=\"Content-type\" content=\"text/html;charset=#{encoding}\" />"
|
56
|
+
res << "</head><body>"
|
57
|
+
res << Sanitize.clean(doc.to_s, SANITIZE_OPTIONS)
|
58
|
+
res << "</body></html>"
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
data/spec/email_spec.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
MSG=<<EOT
|
5
|
+
<html>
|
6
|
+
<head>
|
7
|
+
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
|
8
|
+
<title> This is mytitle </title>
|
9
|
+
</head>
|
10
|
+
<body bgcolor="#FFFF00">
|
11
|
+
<h1>A first level heading
|
12
|
+
</h1
|
13
|
+
<h3>A third level heading
|
14
|
+
</h3>
|
15
|
+
<blink> A BLINKING TITLE
|
16
|
+
</blink>
|
17
|
+
A table
|
18
|
+
<table>
|
19
|
+
<tr><td>Cell top left</td><td>Cell top right</td></tr>
|
20
|
+
<tr><td>Cell bot left</td><td>Cell bot right</td></tr>
|
21
|
+
</table>
|
22
|
+
<marquee behaviour="scroll"> HELLO mailworld I'm a marquee
|
23
|
+
</marquee>
|
24
|
+
<div align="left">
|
25
|
+
左側
|
26
|
+
</div>
|
27
|
+
<hr color="#0000FF">
|
28
|
+
<div align="center">
|
29
|
+
ど真ん中
|
30
|
+
</div>
|
31
|
+
<div style="text-align:center;">
|
32
|
+
</div>
|
33
|
+
<hr color="#FF0000">
|
34
|
+
<div align="right">
|
35
|
+
右側
|
36
|
+
</div>
|
37
|
+
こんにちは世界!ばあばばばあ
|
38
|
+
</body>
|
39
|
+
<br/>
|
40
|
+
<font size=4 color="#009900">
|
41
|
+
GREEEEEEN
|
42
|
+
</font>
|
43
|
+
<img src="http://someurl.com/someimage.png"/>
|
44
|
+
<a href="http://dragonmobile.nuancemobiledeveloper.com/"><img src="cid:image-attachment-id" alt=""/></a>this was an image
|
45
|
+
<br/>
|
46
|
+
This is <img src="http://someurl.com/someimage.png" alt="イメジー"/>...
|
47
|
+
And now, <a href="ftp://some.ftpsite.com/">Downloadz youz warez herez!</a>
|
48
|
+
</html>
|
49
|
+
EOT
|
50
|
+
|
51
|
+
describe Galakei::Email do
|
52
|
+
let(:sanitized_mail){ Galakei::Email.to_galakei_email(MSG) }
|
53
|
+
|
54
|
+
it "should have a html, head, meta and body" do
|
55
|
+
sanitized_mail.should =~ /html.*head.*meta.*body/m
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should have supported tags and styles" do
|
59
|
+
sanitized_mail.should =~ /<div align=/m
|
60
|
+
sanitized_mail.should =~ /<hr color=/m
|
61
|
+
sanitized_mail.should =~ /<font size=.*color=/m
|
62
|
+
sanitized_mail.should =~ /<br>/m
|
63
|
+
sanitized_mail.should =~ /<blink>/m
|
64
|
+
sanitized_mail.should =~ /<marquee behaviour=/m
|
65
|
+
sanitized_mail.should =~ /<a href=/m
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should not have h and table tags" do
|
69
|
+
sanitized_mail.should_not =~ /<h[0-9]>/
|
70
|
+
sanitized_mail.should_not =~ /<table>/
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should handle images" do
|
74
|
+
sanitized_mail.should =~ /<img src=.*cid/m
|
75
|
+
sanitized_mail.should_not =~ /<img src=.*http/m
|
76
|
+
sanitized_mail.should match("This is イメジー...")
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should not have unsupported protocols" do
|
80
|
+
sanitized_mail.should_not =~ /ftpsite/
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should not have title" do
|
84
|
+
sanitized_mail.should_not =~ /mytitle/
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: galakei-email
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paul McMahon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sanitize
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Send email to Japanese phones
|
84
|
+
email:
|
85
|
+
- paul@doorkeeper.jp
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- galakei-email.gemspec
|
96
|
+
- lib/galakei/email.rb
|
97
|
+
- lib/galakei/email/au_mail_interceptor.rb
|
98
|
+
- lib/galakei/email/railtie.rb
|
99
|
+
- lib/galakei/email/version.rb
|
100
|
+
- spec/email_spec.rb
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
homepage: ''
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.1.11
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Japanese carriers provide each mobile subscriber with an email address. The
|
126
|
+
email works basically the same as normal email, but with some caveats. This gem
|
127
|
+
takes care of transforming normal mail into galakei mail.
|
128
|
+
test_files:
|
129
|
+
- spec/email_spec.rb
|
130
|
+
- spec/spec_helper.rb
|