JunKikuchi-simple-mailer 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +0 -0
- data/COPYING +18 -0
- data/README.rdoc +21 -0
- data/Rakefile +30 -0
- data/VERSION +1 -0
- data/lib/simple-mailer.rb +149 -0
- metadata +59 -0
data/CHANGELOG
ADDED
File without changes
|
data/COPYING
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2009 Jun Kikuchi
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to
|
5
|
+
deal in the Software without restriction, including without limitation the
|
6
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
16
|
+
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
= simple-mailer
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'lib/simple-mailer'
|
5
|
+
|
6
|
+
SimpleMailer::SMTP.new(:host => 'localhost', :port => 25) do
|
7
|
+
message(:encoding => 'iso-2022-jp') do
|
8
|
+
from 'hoge@example.com'
|
9
|
+
to 'foo@example.com', 'Foo'
|
10
|
+
to 'bar@example.com'
|
11
|
+
subject 'Hello'
|
12
|
+
body <<END
|
13
|
+
Hi,
|
14
|
+
|
15
|
+
How are you doing?
|
16
|
+
|
17
|
+
--
|
18
|
+
hoge
|
19
|
+
END
|
20
|
+
end
|
21
|
+
end
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec/rake/spectask'
|
3
|
+
|
4
|
+
NAME = 'simple-mailer'
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'jeweler'
|
8
|
+
Jeweler::Tasks.new do |s|
|
9
|
+
s.name = NAME
|
10
|
+
s.platform = Gem::Platform::RUBY
|
11
|
+
s.summary = NAME
|
12
|
+
s.description = NAME
|
13
|
+
s.author = "Jun Kikuchi"
|
14
|
+
s.email = "kikuchi@bonnou.com"
|
15
|
+
s.homepage = "http://github.com/JunKikuchi/simple-mailer"
|
16
|
+
s.files = %w(
|
17
|
+
COPYING CHANGELOG README.rdoc Rakefile VERSION
|
18
|
+
) + Dir.glob("{bin,doc,spec,lib}/**/*")
|
19
|
+
s.require_path = "lib"
|
20
|
+
s.has_rdoc = true
|
21
|
+
end
|
22
|
+
rescue LoadError
|
23
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
24
|
+
end
|
25
|
+
|
26
|
+
Spec::Rake::SpecTask.new do |t|
|
27
|
+
#t.spec_opts = ['-c --format specdoc']
|
28
|
+
t.spec_opts = ['-c']
|
29
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
30
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
class SimpleMailer
|
4
|
+
def self.parse(message)
|
5
|
+
end
|
6
|
+
|
7
|
+
class SMTP
|
8
|
+
def initialize(params={}, &block)
|
9
|
+
require 'net/smtp'
|
10
|
+
@params = {
|
11
|
+
:host => 'localhost',
|
12
|
+
:port => 25
|
13
|
+
}.merge(params)
|
14
|
+
|
15
|
+
@smtp = Net::SMTP.start(@params[:host], @params[:port].to_i)
|
16
|
+
instance_eval(&block)
|
17
|
+
@smtp.finish
|
18
|
+
end
|
19
|
+
|
20
|
+
def message(params={}, &block)
|
21
|
+
@params = {
|
22
|
+
:encoding => 'us-ascii'
|
23
|
+
}.merge(params)
|
24
|
+
|
25
|
+
@smtp.send_mail(
|
26
|
+
*Message.new(@params[:encoding], &block).to_smtp
|
27
|
+
)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class Message
|
32
|
+
if RUBY_VERSION < '1.9'
|
33
|
+
require 'nkf'
|
34
|
+
|
35
|
+
ENCODING = {
|
36
|
+
'iso-2022-jp' => proc do |val|
|
37
|
+
NKF.nkf '--jis', val
|
38
|
+
end
|
39
|
+
}
|
40
|
+
|
41
|
+
def self.encode(val, encoding)
|
42
|
+
ENCODING[encoding.downcase].call(val)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.encode_header(val, encoding)
|
46
|
+
'=?%s?b?%s?=' % [
|
47
|
+
encoding,
|
48
|
+
[self.encode(val, encoding)].pack('m').split.join
|
49
|
+
]
|
50
|
+
end
|
51
|
+
else
|
52
|
+
def self.encode(val, encoding)
|
53
|
+
val.encode(encoding)
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.encode_header(val, encoding)
|
57
|
+
if val.ascii_only?
|
58
|
+
val
|
59
|
+
else
|
60
|
+
'=?%s?b?%s?=' % [
|
61
|
+
encoding,
|
62
|
+
[val.encode(encoding)].pack('m').split.join
|
63
|
+
]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def initialize(encoding, &block)
|
69
|
+
@encoding = encoding
|
70
|
+
|
71
|
+
@from = []
|
72
|
+
@to = []
|
73
|
+
@cc = []
|
74
|
+
@bcc = []
|
75
|
+
@subject = ''
|
76
|
+
@body = ''
|
77
|
+
|
78
|
+
instance_eval(&block)
|
79
|
+
end
|
80
|
+
|
81
|
+
def encode_header(val)
|
82
|
+
self.class.encode_header(val, @encoding)
|
83
|
+
end
|
84
|
+
|
85
|
+
def encode(val)
|
86
|
+
self.class.encode(val, @encoding)
|
87
|
+
end
|
88
|
+
|
89
|
+
def encode_addr(addr, name=nil)
|
90
|
+
if name
|
91
|
+
'%s <%s>' % [encode_header(name), addr]
|
92
|
+
else
|
93
|
+
'<%s>' % addr
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def from(addr, name=nil)
|
98
|
+
@from = [addr, name]
|
99
|
+
end
|
100
|
+
|
101
|
+
def to(addr, name=nil)
|
102
|
+
@to << [addr, name]
|
103
|
+
end
|
104
|
+
|
105
|
+
def cc(addr, name=nil)
|
106
|
+
@cc << [addr, name]
|
107
|
+
end
|
108
|
+
|
109
|
+
def bcc(addr, name=nil)
|
110
|
+
@bcc << [addr, name]
|
111
|
+
end
|
112
|
+
|
113
|
+
def subject(subject)
|
114
|
+
@subject = subject
|
115
|
+
end
|
116
|
+
|
117
|
+
def body(body)
|
118
|
+
@body = body
|
119
|
+
end
|
120
|
+
|
121
|
+
def to_s
|
122
|
+
([
|
123
|
+
'MIME-Version: 1.0',
|
124
|
+
'Content-Type: text/plain; charset=' + @encoding,
|
125
|
+
'From: ' << encode_addr(@from[0], @from[1]),
|
126
|
+
@to.map do |val|
|
127
|
+
'To: ' << encode_addr(val[0], val[1])
|
128
|
+
end,
|
129
|
+
@cc.map do |val|
|
130
|
+
'Cc: ' << encode_addr(val[0], val[1])
|
131
|
+
end,
|
132
|
+
'Date: ' << Time.now.rfc2822,
|
133
|
+
'Subject: ' << encode_header(@subject)
|
134
|
+
].flatten!.join("\n") + "\n\n" + encode(@body))
|
135
|
+
end
|
136
|
+
|
137
|
+
def to_smtp
|
138
|
+
[
|
139
|
+
if RUBY_VERSION < '1.9'
|
140
|
+
to_s
|
141
|
+
else
|
142
|
+
to_s.force_encoding('ASCII-8BIT')
|
143
|
+
end,
|
144
|
+
@from[0],
|
145
|
+
*((@to + @cc + @bcc).map do |v| v[0] end)
|
146
|
+
]
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: JunKikuchi-simple-mailer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jun Kikuchi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-09-13 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: simple-mailer
|
17
|
+
email: kikuchi@bonnou.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
files:
|
25
|
+
- CHANGELOG
|
26
|
+
- COPYING
|
27
|
+
- README.rdoc
|
28
|
+
- Rakefile
|
29
|
+
- VERSION
|
30
|
+
- lib/simple-mailer.rb
|
31
|
+
has_rdoc: false
|
32
|
+
homepage: http://github.com/JunKikuchi/simple-mailer
|
33
|
+
licenses:
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options:
|
36
|
+
- --charset=UTF-8
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
version:
|
51
|
+
requirements: []
|
52
|
+
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 1.3.5
|
55
|
+
signing_key:
|
56
|
+
specification_version: 3
|
57
|
+
summary: simple-mailer
|
58
|
+
test_files: []
|
59
|
+
|