eventmachine-email_server 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f8d810ad36c8d3b8515f5f209afaadbb9038391
|
4
|
+
data.tar.gz: d6f036b47bd9fedf1e566ad576ed02e6f8a02b71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc9f85702c714eca052dd7b5ee52c66f84d35866df288494917e4039c29c5b533e1edd118a65f2815b4208962ef3331796808fb3da16e8ec50d45c1f311b7abf
|
7
|
+
data.tar.gz: dcc7d410bdd476b78db32533a507f8812d10b97c57bb2c7b177f752c95770a972ccbd111af44b416e2e06521b3be342719e0b425e6af58df9a7a3ee9c9677698
|
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_runtime_dependency "sqlite3", ">= 1.3.6"
|
23
23
|
spec.add_runtime_dependency "ratelimit-bucketbased", ">= 0.0.1"
|
24
24
|
spec.add_runtime_dependency "eventmachine-dnsbl", ">= 0.0.2"
|
25
|
+
spec.add_runtime_dependency "spf", ">= 0.0.44"
|
25
26
|
spec.add_development_dependency "minitest", "~> 5.5"
|
26
27
|
spec.add_development_dependency "bundler", "~> 1.6"
|
27
28
|
spec.add_development_dependency "rake", "~> 10.0"
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'eventmachine'
|
2
2
|
require 'eventmachine/dnsbl'
|
3
|
+
require 'spf'
|
3
4
|
|
4
5
|
module EventMachine
|
5
6
|
module EmailServer
|
@@ -11,6 +12,15 @@ module EventMachine
|
|
11
12
|
@@spf_check = false
|
12
13
|
@@reject_filters = Array.new
|
13
14
|
|
15
|
+
def self.reset
|
16
|
+
@@graylist = nil
|
17
|
+
@@dnsbl_check = nil
|
18
|
+
@@ratelimiter = nil
|
19
|
+
@@reverse_ptr_check = false
|
20
|
+
@@spf_check = false
|
21
|
+
@@reject_filters = Array.new
|
22
|
+
end
|
23
|
+
|
14
24
|
def self.reverse_ptr_check(ptr=nil)
|
15
25
|
if not ptr.nil?
|
16
26
|
@@reverse_ptr_check = ptr
|
@@ -135,36 +145,53 @@ module EventMachine
|
|
135
145
|
end
|
136
146
|
end
|
137
147
|
|
138
|
-
def check_spf(
|
148
|
+
def check_spf(helo, client_ip, identity)
|
139
149
|
if @@spf_check
|
140
150
|
@spf_ok = false
|
141
151
|
@pending_checks << :spf
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
152
|
+
|
153
|
+
spf_dispatcher = EventMachine::ThreadedResource.new do
|
154
|
+
spf_server = SPF::Server.new
|
155
|
+
end
|
156
|
+
|
157
|
+
pool = EM::Pool.new
|
158
|
+
|
159
|
+
pool.add spf_dispatcher
|
160
|
+
|
161
|
+
pool.perform do |dispatcher|
|
162
|
+
completion = dispatcher.dispatch do |spf_server|
|
163
|
+
|
164
|
+
request = SPF::Request.new(
|
165
|
+
versions: [1, 2], # optional
|
166
|
+
scope: 'mfrom', # or 'helo', 'pra'
|
167
|
+
identity: identity,
|
168
|
+
ip_address: client_ip,
|
169
|
+
helo_identity: helo # optional
|
170
|
+
)
|
171
|
+
|
172
|
+
result = spf_server.process(request)
|
149
173
|
end
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
174
|
+
|
175
|
+
completion.callback do |result|
|
176
|
+
if result.code == :pass
|
177
|
+
@spf_ok = true
|
178
|
+
elsif result.code == :fail
|
179
|
+
@spf_ok = false
|
180
|
+
elsif result.code == :softfail
|
181
|
+
@spf_ok = true
|
182
|
+
elsif result.code == :neutral
|
183
|
+
@spf_ok = true
|
184
|
+
else
|
185
|
+
@spf_ok = false
|
186
|
+
end
|
187
|
+
@pending_checks -= [:spf]
|
188
|
+
if @pending_checks.length == 0
|
189
|
+
send_answer
|
161
190
|
end
|
162
191
|
end
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
end
|
167
|
-
}
|
192
|
+
|
193
|
+
completion
|
194
|
+
end
|
168
195
|
end
|
169
196
|
end
|
170
197
|
|
@@ -202,7 +229,8 @@ module EventMachine
|
|
202
229
|
elsif (line =~ /^MAIL FROM\:/)
|
203
230
|
@mail_from = (/^MAIL FROM\:<(.+)>.*$/).match(line)[1]
|
204
231
|
if @@spf_check
|
205
|
-
|
232
|
+
port, ip = Socket.unpack_sockaddr_in(get_peername)
|
233
|
+
check_spf(helo, ip, @mail_from)
|
206
234
|
end
|
207
235
|
return true, "250 OK"
|
208
236
|
elsif (line =~ /^RCPT TO\:/)
|
data/test/test_email_server.rb
CHANGED
@@ -133,6 +133,7 @@ Looks like we had fun!
|
|
133
133
|
|
134
134
|
def test_graylisting
|
135
135
|
return unless @test_vector.call(__method__)
|
136
|
+
SMTPServer.reset
|
136
137
|
SMTPServer.graylist(Hash.new)
|
137
138
|
userstore = MemoryUserStore.new
|
138
139
|
emailstore = MemoryEmailStore.new
|
@@ -161,6 +162,7 @@ Looks like we had fun!
|
|
161
162
|
}
|
162
163
|
storage = RateLimit::Memory.new
|
163
164
|
rl = RateLimit::BucketBased.new(storage, config, 'default')
|
165
|
+
SMTPServer.reset
|
164
166
|
SMTPServer.ratelimiter(rl)
|
165
167
|
userstore = MemoryUserStore.new
|
166
168
|
emailstore = MemoryEmailStore.new
|
@@ -220,6 +222,7 @@ Looks like we had fun!
|
|
220
222
|
"127.0.0.2" => "Blacklisted as an example"
|
221
223
|
}
|
222
224
|
})
|
225
|
+
SMTPServer.reset
|
223
226
|
SMTPServer.dnsbl_check(true)
|
224
227
|
|
225
228
|
userstore = MemoryUserStore.new
|
@@ -255,32 +258,13 @@ Looks like we had fun!
|
|
255
258
|
}
|
256
259
|
end
|
257
260
|
|
258
|
-
def test_spf_resolution
|
259
|
-
return unless @test_vector.call(__method__)
|
260
|
-
EM.run {
|
261
|
-
d = EventMachine::DNS::Resolver.resolve("example.com", Resolv::DNS::Resource::IN::TXT)
|
262
|
-
d.errback do |r|
|
263
|
-
fail "dns resolution failed"
|
264
|
-
EM.stop
|
265
|
-
end
|
266
|
-
d.callback do |r|
|
267
|
-
refute_nil(r)
|
268
|
-
assert_equal(2, r.length)
|
269
|
-
refute_nil(r.index("v=spf1 -all"))
|
270
|
-
EM.stop
|
271
|
-
end
|
272
|
-
timer = EventMachine::Timer.new(10) do
|
273
|
-
EM.stop
|
274
|
-
end
|
275
|
-
}
|
276
|
-
end
|
277
|
-
|
278
261
|
def test_spf
|
279
262
|
return unless @test_vector.call(__method__)
|
280
263
|
userstore = MemoryUserStore.new
|
281
264
|
emailstore = MemoryEmailStore.new
|
282
265
|
setup_user(userstore)
|
283
266
|
|
267
|
+
SMTPServer.reset
|
284
268
|
SMTPServer.spf_check(true)
|
285
269
|
EM.run {
|
286
270
|
smtp = EventMachine::start_server "0.0.0.0", 2025, SMTPServer, "example.org", userstore, emailstore
|
@@ -314,6 +298,7 @@ Looks like we had fun!
|
|
314
298
|
rl = RateLimit::BucketBased.new(storage, config, 'default')
|
315
299
|
|
316
300
|
|
301
|
+
SMTPServer.reset
|
317
302
|
SMTPServer.reverse_ptr_check(true)
|
318
303
|
SMTPServer.graylist(Hash.new)
|
319
304
|
SMTPServer.ratelimiter(rl)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eventmachine-email_server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- chrislee35
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eventmachine
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 0.0.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: spf
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.0.44
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.0.44
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: minitest
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|